Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/accelera.../template.../template...
File: template-mode.php
<?php
[0] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[1] Fix | Delete
exit;
[2] Fix | Delete
}
[3] Fix | Delete
Class AMPforWP_theme_mode{
[4] Fix | Delete
public function __construct(){
[5] Fix | Delete
}
[6] Fix | Delete
public function init(){
[7] Fix | Delete
[8] Fix | Delete
add_action( 'init', array("AMPforWP_theme_mode", 'removeUnusedAction'));
[9] Fix | Delete
add_action( 'init', array("AMPforWP_theme_mode", 'removeUnusedMenuWidgets'), 11);
[10] Fix | Delete
[11] Fix | Delete
if(!is_admin() && $GLOBALS['pagenow'] !== 'wp-login.php' && (!is_preview() && !isset($_GET['elementor-preview'])) ){
[12] Fix | Delete
add_action( 'init', array($this, 'rm_wp_core'), 20 );
[13] Fix | Delete
add_filter("ampforwp_is_amp_endpoint", array($this, 'ampforwp_theme_mode_enable'));
[14] Fix | Delete
add_action( 'init', array($this, 'dynamic_sidebar_callback_bkp') );
[15] Fix | Delete
add_filter( 'amp_post_template_dir', array($this, 'template_mode_new_dir') );
[16] Fix | Delete
add_filter( 'amp_post_template_file', array($this, 'custom_template_file_name'), 11, 3 );
[17] Fix | Delete
add_filter( "post_thumbnail_html", array($this, 'featured_image_html'), 11, 5 );
[18] Fix | Delete
add_filter("language_attributes", array($this, 'add_amp_html_attr'), 10, 2);
[19] Fix | Delete
add_filter( "the_content", array($this, 'amp_the_content') );
[20] Fix | Delete
add_action( "levelup_head", array($this, 'amp_head_content') );
[21] Fix | Delete
add_action( "levelup_css", array($this, 'amp_head_css') );
[22] Fix | Delete
add_filter( "get_search_form", array($this, 'search_form'), 99 );
[23] Fix | Delete
add_filter( "get_custom_logo", array($this, 'get_custom_logo'), 10, 2 );
[24] Fix | Delete
add_action( "levelup_footer", array($this, 'amp_footer_content') );
[25] Fix | Delete
add_action( "get_avatar", array($this,'get_avatar'), 11,6);
[26] Fix | Delete
add_filter( "the_author_description", array($this, 'author_meta_desctiption_amp'),10, 2 );
[27] Fix | Delete
add_filter("ampforwp_the_content_last_filter", array($this, "comment_form_conversion") );
[28] Fix | Delete
add_filter("amp_post_template_data", array($this, 'amp_comment_mustache_script'), 11 );
[29] Fix | Delete
//Remove admin bar
[30] Fix | Delete
if( is_user_logged_in() ){
[31] Fix | Delete
$pref = get_user_option( "show_admin_bar_front", get_current_user_id() );
[32] Fix | Delete
if($pref==="true"){
[33] Fix | Delete
add_action("wp_body_open", function(){
[34] Fix | Delete
wp_admin_bar_render();
[35] Fix | Delete
});
[36] Fix | Delete
add_action( 'admin_bar_init', array($this,'init_admin_bar'));
[37] Fix | Delete
add_action( 'wp_before_admin_bar_render', function(){
[38] Fix | Delete
remove_action( 'wp_before_admin_bar_render', 'wp_customize_support_script' );
[39] Fix | Delete
},9);
[40] Fix | Delete
add_action( 'admin_bar_menu', array($this, 'remove_adminbar_search'));
[41] Fix | Delete
}
[42] Fix | Delete
}
[43] Fix | Delete
[44] Fix | Delete
}else{
[45] Fix | Delete
require_once AMPFORWP_PLUGIN_DIR.'/templates/template-mode/admin-settings.php';
[46] Fix | Delete
add_filter( 'plugin_action_links_accelerated-mobile-pages/accelerated-moblie-pages.php', array($this, 'ampforwp_plugin_settings_link'), 999, 4 );
[47] Fix | Delete
}
[48] Fix | Delete
add_action( 'wp_ajax_amp_theme_ajaxcomments', array($this, 'amp_theme_ajaxcomments') );
[49] Fix | Delete
add_action( 'wp_ajax_nopriv_amp_theme_ajaxcomments', array($this, 'amp_theme_ajaxcomments') );
[50] Fix | Delete
}
[51] Fix | Delete
static function removeUnusedMenuWidgets(){
[52] Fix | Delete
unregister_nav_menu( 'amp-menu' );
[53] Fix | Delete
unregister_nav_menu( 'amp-footer-menu' );
[54] Fix | Delete
unregister_sidebar('ampforwp-above-loop');
[55] Fix | Delete
unregister_sidebar('ampforwp-below-loop');
[56] Fix | Delete
unregister_sidebar('ampforwp-below-header');
[57] Fix | Delete
unregister_sidebar('ampforwp-above-footer');
[58] Fix | Delete
unregister_sidebar('swift-footer-widget-area');
[59] Fix | Delete
unregister_sidebar('swift-sidebar');
[60] Fix | Delete
}
[61] Fix | Delete
public static function removeUnusedAction(){
[62] Fix | Delete
//redirect.php
[63] Fix | Delete
remove_action( 'init', 'ampforwp_menu', 10 );
[64] Fix | Delete
remove_action( 'init', 'ampforwp_footermenu', 10 );
[65] Fix | Delete
remove_action( 'init', 'swifttheme_footer_widgets_init', 10 );
[66] Fix | Delete
remove_action( 'init', 'ampforwp_add_widget_support', 10);
[67] Fix | Delete
[68] Fix | Delete
remove_action( 'template_redirect', 'ampforwp_redirection', 10 );
[69] Fix | Delete
remove_action( 'template_redirect', 'ampforwp_check_amp_page_status', 10 );
[70] Fix | Delete
remove_action( 'template_redirect', 'ampforwp_page_template_redirect', 10 );
[71] Fix | Delete
remove_action( 'template_redirect', 'ampforwp_page_template_redirect_archive', 10 );
[72] Fix | Delete
remove_filter( 'query_vars', 'ampforwp_custom_query_var' );
[73] Fix | Delete
remove_action( 'template_redirect', 'ampforwp_redirect_to_orginal_url' );
[74] Fix | Delete
remove_action('template_redirect', 'ampforwp_redirect_proper_qendpoint' );
[75] Fix | Delete
remove_action('get_search_form', 'ampforwp_search_form' );
[76] Fix | Delete
//Main files
[77] Fix | Delete
remove_action( 'init', 'ampforwp_add_custom_post_support',11);
[78] Fix | Delete
remove_action( 'init', 'ampforwp_add_custom_rewrite_rules', 25 );
[79] Fix | Delete
remove_action( 'init', 'ampforwp_custom_rewrite_rules_for_product_category' );
[80] Fix | Delete
}
[81] Fix | Delete
function ampforwp_theme_mode_enable($opt){
[82] Fix | Delete
return true;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
function ampforwp_plugin_settings_link( $actions, $plugin_file, $plugin_data, $context ) {
[86] Fix | Delete
$amp_activate = '';
[87] Fix | Delete
$amp_activate = array('<span style="color:black;">'.esc_html__("Status: Template Mode", "accelerated-mobile-pages").'</span> |');
[88] Fix | Delete
$actions = array_merge( $actions, $amp_activate );
[89] Fix | Delete
return $actions;
[90] Fix | Delete
}
[91] Fix | Delete
function amp_comment_mustache_script($data){
[92] Fix | Delete
if(isset($data['amp_component_scripts']['amp-next-page'])){
[93] Fix | Delete
unset($data['amp_component_scripts']['amp-next-page']);
[94] Fix | Delete
}
[95] Fix | Delete
if ( comments_open()){
[96] Fix | Delete
if ( empty( $data['amp_component_scripts']['amp-mustache'] ) ) {
[97] Fix | Delete
$data['amp_component_scripts']['amp-mustache'] = 'https://cdn.ampproject.org/v0/amp-mustache-latest.js';
[98] Fix | Delete
}
[99] Fix | Delete
if ( empty( $data['amp_component_scripts']['amp-form'] ) ) {
[100] Fix | Delete
$data['amp_component_scripts']['amp-form'] = 'https://cdn.ampproject.org/v0/amp-form-latest.js';
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
unset($data['amp_component_scripts']['amp-addthis']);
[104] Fix | Delete
return $data;
[105] Fix | Delete
}
[106] Fix | Delete
function amp_theme_ajaxcomments(){
[107] Fix | Delete
global $redux_builder_amp;
[108] Fix | Delete
header("access-control-allow-credentials:true");
[109] Fix | Delete
header("access-control-allow-headers:Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token");
[110] Fix | Delete
header("Access-Control-Allow-Origin:".esc_attr($_SERVER['HTTP_ORIGIN']) );
[111] Fix | Delete
$siteUrl = parse_url( get_site_url() );
[112] Fix | Delete
header("AMP-Access-Control-Allow-Source-Origin:".esc_attr($siteUrl['scheme']) . '://' . esc_attr($siteUrl['host']) );
[113] Fix | Delete
header("access-control-expose-headers:AMP-Access-Control-Allow-Source-Origin");
[114] Fix | Delete
header("Content-Type:application/json;charset=utf-8");
[115] Fix | Delete
if(wp_verify_nonce($_POST['amp_comment_form_nonce'], 'commentform_submission')){
[116] Fix | Delete
$comment_status = array('response' => 'Nonce not verified' );
[117] Fix | Delete
echo wp_json_encode($comment_status);
[118] Fix | Delete
die;
[119] Fix | Delete
}
[120] Fix | Delete
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
[121] Fix | Delete
$text_data = 'Comment Successfully submitted';
[122] Fix | Delete
if ($redux_builder_amp['amp-comments-Successful-message']){
[123] Fix | Delete
$text_data = esc_html__( $redux_builder_amp['amp-comments-Successful-message'], 'accelerated-mobile-pages');
[124] Fix | Delete
}
[125] Fix | Delete
[126] Fix | Delete
if ( is_wp_error( $comment ) ) {
[127] Fix | Delete
$error_data = intval( $comment->get_error_data() );
[128] Fix | Delete
if ( ! empty( $error_data ) ) {
[129] Fix | Delete
$comment_html = $comment->get_error_message();
[130] Fix | Delete
$comment_html = str_replace("&#8217;","'",$comment_html);
[131] Fix | Delete
$comment_status = array('response' => $comment_html );
[132] Fix | Delete
echo wp_json_encode($comment_status);
[133] Fix | Delete
die;
[134] Fix | Delete
} else {
[135] Fix | Delete
wp_die( 'Unknown error' );
[136] Fix | Delete
}
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$user = wp_get_current_user();
[140] Fix | Delete
do_action('set_comment_cookies', $comment, $user);
[141] Fix | Delete
[142] Fix | Delete
$comment_depth = 1;
[143] Fix | Delete
$comment_parent = $comment->comment_parent;
[144] Fix | Delete
while( $comment_parent ){
[145] Fix | Delete
$comment_depth++;
[146] Fix | Delete
$parent_comment = get_comment( $comment_parent );
[147] Fix | Delete
$comment_parent = $parent_comment->comment_parent;
[148] Fix | Delete
}
[149] Fix | Delete
[150] Fix | Delete
$GLOBALS['comment'] = $comment;
[151] Fix | Delete
$GLOBALS['comment_depth'] = $comment_depth;
[152] Fix | Delete
$comment_html = $text_data;
[153] Fix | Delete
$comment_status = array('response' => $comment_html );
[154] Fix | Delete
echo wp_json_encode($comment_status);
[155] Fix | Delete
die;
[156] Fix | Delete
}
[157] Fix | Delete
function comment_form_conversion($content){
[158] Fix | Delete
[159] Fix | Delete
if(strpos($content, 'id="commentform"')!==false){
[160] Fix | Delete
$submit_url = admin_url('admin-ajax.php?action=amp_theme_ajaxcomments');
[161] Fix | Delete
$submit_url = str_replace("http:", "", $submit_url);
[162] Fix | Delete
$comment_nonce = wp_create_nonce( 'commentform_submission' );
[163] Fix | Delete
$mustache = '<input type="hidden" name="amp_comment_form_nonce" value="'.esc_attr($comment_nonce).'"><div submit-success>
[164] Fix | Delete
<template type="amp-mustache">
[165] Fix | Delete
{{response}}
[166] Fix | Delete
</template>
[167] Fix | Delete
</div>
[168] Fix | Delete
<div submit-error>
[169] Fix | Delete
<template type="amp-mustache">
[170] Fix | Delete
{{response}}
[171] Fix | Delete
</template>
[172] Fix | Delete
</div>';
[173] Fix | Delete
if(preg_match('/method\s*=\s*"\s*get\s*"/', $content)){
[174] Fix | Delete
$content = preg_replace("/<form(.*?)action=[\"|'](.*?)[\"|'](.*?)id=[\"|']commentform[\"|'](.*?)>/s", '<form$1action="'.esc_url_raw($submit_url).'"$3id="commentform" $4 on="submit-success:commentform.reset()">'.$mustache, $content);
[175] Fix | Delete
}
[176] Fix | Delete
if(preg_match('/method\s*=\s*"\s*post\s*"/', $content)){
[177] Fix | Delete
$content = preg_replace("/<form action=[\"|'](.*?)[\"|'](.*?)id=[\"|']commentform[\"|'](.*?)>/s", '<form action-xhr="$1"$2id="commentform" $3 on="submit-success:commentform.reset()">'.$mustache, $content);
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
return $content;
[181] Fix | Delete
}
[182] Fix | Delete
/**
[183] Fix | Delete
* Remove Unwanted hooks from template
[184] Fix | Delete
**/
[185] Fix | Delete
public function rm_wp_core(){
[186] Fix | Delete
remove_all_actions( 'wp_head' );
[187] Fix | Delete
remove_all_actions( 'wp_print_styles' );
[188] Fix | Delete
remove_all_actions( 'wp_print_head_scripts' );
[189] Fix | Delete
remove_all_actions( 'wp_footer' );
[190] Fix | Delete
remove_all_actions( 'wp_enqueue_scripts' );
[191] Fix | Delete
remove_all_actions( 'after_wp_tiny_mce' );
[192] Fix | Delete
remove_all_actions( 'comment_form' );
[193] Fix | Delete
remove_action( 'amp_post_template_head','ampforwp_add_meta_viewport', 9);
[194] Fix | Delete
remove_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 );
[195] Fix | Delete
remove_filter( 'ampforwp_post_template_data', 'ampforwp_backtotop' );
[196] Fix | Delete
remove_filter( 'amp_post_template_data', 'ampforwp_backtotop' );
[197] Fix | Delete
remove_filter('amp_post_template_dir','ampforwp_new_dir');
[198] Fix | Delete
remove_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 );
[199] Fix | Delete
}
[200] Fix | Delete
/**
[201] Fix | Delete
* Replacing callback of widgets for conversion
[202] Fix | Delete
**/
[203] Fix | Delete
public function dynamic_sidebar_callback_bkp(){
[204] Fix | Delete
global $wp_registered_widgets, $ampforwp_wp_registered_widgets;
[205] Fix | Delete
if(count($wp_registered_widgets)){
[206] Fix | Delete
foreach ($wp_registered_widgets as $key => $value) {
[207] Fix | Delete
$wp_registered_widgets[$key]['amp_callback'] = $value['callback'];
[208] Fix | Delete
$wp_registered_widgets[$key]['amp_params'] = $value['params'];
[209] Fix | Delete
$wp_registered_widgets[$key]['params'] = array(array('public function_name'=> $value['id'] ));
[210] Fix | Delete
$wp_registered_widgets[$key]['callback'] = array($this, 'ampforwp_template_mode_reg_callback_widgets');
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
}
[214] Fix | Delete
/**
[215] Fix | Delete
* Change Templates directory for AMP theme
[216] Fix | Delete
**/
[217] Fix | Delete
public function template_mode_new_dir( $dir ) {
[218] Fix | Delete
global $redux_builder_amp;
[219] Fix | Delete
$dir = get_template_directory()."/";
[220] Fix | Delete
return $dir;
[221] Fix | Delete
}
[222] Fix | Delete
/**
[223] Fix | Delete
* Calling name of template from theme directory
[224] Fix | Delete
**/
[225] Fix | Delete
// Custom Template Files
[226] Fix | Delete
public function custom_template_file_name( $file, $type, $post ) {
[227] Fix | Delete
global $redux_builder_amp;
[228] Fix | Delete
// 404 Template
[229] Fix | Delete
if( 'single' === $type && is_404() ) {
[230] Fix | Delete
$file = get_template_directory() . '/404.php';
[231] Fix | Delete
}
[232] Fix | Delete
// single Template
[233] Fix | Delete
if ( is_page() ) {
[234] Fix | Delete
if( 'single' === $type && ! ('product' === $post->post_type) ) {
[235] Fix | Delete
$file = get_template_directory() . '/page.php';
[236] Fix | Delete
}
[237] Fix | Delete
}
[238] Fix | Delete
// Loop Template
[239] Fix | Delete
if ( 'loop' === $type ) {
[240] Fix | Delete
$file = get_template_directory() . '/loop.php';
[241] Fix | Delete
}
[242] Fix | Delete
// Archive
[243] Fix | Delete
if ( is_archive() ) {
[244] Fix | Delete
if ( 'single' === $type ) {
[245] Fix | Delete
$file = get_template_directory() . '/archive.php';
[246] Fix | Delete
}
[247] Fix | Delete
}
[248] Fix | Delete
$ampforwp_custom_post_page = ampforwp_custom_post_page();
[249] Fix | Delete
// Homepage
[250] Fix | Delete
if ( is_home() ) {
[251] Fix | Delete
if ( 'single' === $type ) {
[252] Fix | Delete
$file = get_template_directory() . '/index.php';
[253] Fix | Delete
[254] Fix | Delete
if ( $redux_builder_amp['amp-frontpage-select-option'] == 1 ) {
[255] Fix | Delete
$file = get_template_directory() . '/page.php';
[256] Fix | Delete
}
[257] Fix | Delete
if ( ampforwp_is_blog() ) {
[258] Fix | Delete
$file = get_template_directory() . '/index.php';
[259] Fix | Delete
}
[260] Fix | Delete
}
[261] Fix | Delete
}
[262] Fix | Delete
// is_search
[263] Fix | Delete
if ( is_search() ) {
[264] Fix | Delete
if ( 'single' === $type ) {
[265] Fix | Delete
$file = get_template_directory() . '/search.php';
[266] Fix | Delete
}
[267] Fix | Delete
}
[268] Fix | Delete
//For template pages
[269] Fix | Delete
switch ( true ) {
[270] Fix | Delete
case (is_tax()):
[271] Fix | Delete
$term = get_queried_object();
[272] Fix | Delete
$templates = array();
[273] Fix | Delete
if ( ! empty( $term->slug ) ) {
[274] Fix | Delete
$taxonomy = $term->taxonomy;
[275] Fix | Delete
$slug_decoded = urldecode( $term->slug );
[276] Fix | Delete
if ( $slug_decoded !== $term->slug ) {
[277] Fix | Delete
$templates[] = get_template_directory() . "/taxonomy-$taxonomy-{$slug_decoded}.php";
[278] Fix | Delete
}
[279] Fix | Delete
$templates[] = get_template_directory() . "/taxonomy-$taxonomy-{$term->slug}.php";
[280] Fix | Delete
$templates[] = get_template_directory() . "/taxonomy-$taxonomy.php";
[281] Fix | Delete
}
[282] Fix | Delete
$templates[] = get_template_directory() . "/taxonomy.php";
[283] Fix | Delete
foreach ( $templates as $key => $value ) {
[284] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[285] Fix | Delete
$file = $value;
[286] Fix | Delete
break;
[287] Fix | Delete
}
[288] Fix | Delete
}
[289] Fix | Delete
break;
[290] Fix | Delete
case (is_category()):
[291] Fix | Delete
$category = get_queried_object();
[292] Fix | Delete
$templates = array();
[293] Fix | Delete
if ( ! empty( $category->slug ) ) {
[294] Fix | Delete
$slug_decoded = urldecode( $category->slug );
[295] Fix | Delete
if ( $slug_decoded !== $category->slug ) {
[296] Fix | Delete
$templates[] = get_template_directory() . "/category-{$slug_decoded}.php";
[297] Fix | Delete
}
[298] Fix | Delete
$templates[] = get_template_directory() . "/category-{$category->slug}.php";
[299] Fix | Delete
$templates[] = get_template_directory() . "/category-{$category->term_id}.php";
[300] Fix | Delete
}
[301] Fix | Delete
$templates[] = get_template_directory() . '/category.php';
[302] Fix | Delete
foreach ( $templates as $key => $value ) {
[303] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[304] Fix | Delete
$file = $value;
[305] Fix | Delete
break;
[306] Fix | Delete
}
[307] Fix | Delete
}
[308] Fix | Delete
break;
[309] Fix | Delete
case (is_tag()):
[310] Fix | Delete
$tag = get_queried_object();
[311] Fix | Delete
$templates = array();
[312] Fix | Delete
if ( ! empty( $tag->slug ) ) {
[313] Fix | Delete
$slug_decoded = urldecode( $tag->slug );
[314] Fix | Delete
if ( $slug_decoded !== $tag->slug ) {
[315] Fix | Delete
$templates[] = get_template_directory() . "/tag-{$slug_decoded}.php";
[316] Fix | Delete
}
[317] Fix | Delete
$templates[] = get_template_directory() . "/tag-{$tag->slug}.php";
[318] Fix | Delete
$templates[] = get_template_directory() . "/tag-{$tag->term_id}.php";
[319] Fix | Delete
}
[320] Fix | Delete
$templates[] = get_template_directory() . '/tag.php';
[321] Fix | Delete
foreach ( $templates as $key => $value ) {
[322] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[323] Fix | Delete
$file = $value;
[324] Fix | Delete
break;
[325] Fix | Delete
}
[326] Fix | Delete
}
[327] Fix | Delete
break;
[328] Fix | Delete
case is_author():
[329] Fix | Delete
$author = get_queried_object();
[330] Fix | Delete
$templates = array();
[331] Fix | Delete
if ( $author instanceof WP_User ) {
[332] Fix | Delete
$templates[] = get_template_directory() . "/author-{$author->user_nicename}.php";
[333] Fix | Delete
$templates[] = get_template_directory() . "/author-{$author->ID}.php";
[334] Fix | Delete
}
[335] Fix | Delete
$templates[] = get_template_directory() . "/author.php";
[336] Fix | Delete
foreach ( $templates as $key => $value ) {
[337] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[338] Fix | Delete
$file = $value;
[339] Fix | Delete
break;
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
break;
[343] Fix | Delete
case (is_archive()):
[344] Fix | Delete
$post_types = array_filter( (array) get_query_var( 'post_type' ) );
[345] Fix | Delete
$templates = array();
[346] Fix | Delete
if ( count( $post_types ) == 1 ) {
[347] Fix | Delete
$post_type = reset( $post_types );
[348] Fix | Delete
$templates[] = get_template_directory() . "/archive-{$post_type}.php";
[349] Fix | Delete
}
[350] Fix | Delete
$templates[] = get_template_directory() . '/archive.php';
[351] Fix | Delete
foreach ( $templates as $key => $value ) {
[352] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[353] Fix | Delete
$file = $value;
[354] Fix | Delete
break;
[355] Fix | Delete
}
[356] Fix | Delete
}
[357] Fix | Delete
break;
[358] Fix | Delete
case (is_post_type_archive()):
[359] Fix | Delete
$post_type = get_query_var( 'post_type' );
[360] Fix | Delete
if ( is_array( $post_type ) )
[361] Fix | Delete
$post_type = reset( $post_type );
[362] Fix | Delete
$obj = get_post_type_object( $post_type );
[363] Fix | Delete
if ( ! ($obj instanceof WP_Post_Type) || ! $obj->has_archive ) {
[364] Fix | Delete
//return '';
[365] Fix | Delete
break;
[366] Fix | Delete
}
[367] Fix | Delete
$post_types = array_filter( (array) get_query_var( 'post_type' ) );
[368] Fix | Delete
$templates = array();
[369] Fix | Delete
if ( count( $post_types ) == 1 ) {
[370] Fix | Delete
$post_type = reset( $post_types );
[371] Fix | Delete
$templates[] = get_template_directory() . "/archive-{$post_type}.php";
[372] Fix | Delete
}
[373] Fix | Delete
$templates[] = get_template_directory() . '/archive.php';
[374] Fix | Delete
foreach ( $templates as $key => $value ) {
[375] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[376] Fix | Delete
$file = $value;
[377] Fix | Delete
break;
[378] Fix | Delete
}
[379] Fix | Delete
}
[380] Fix | Delete
break;
[381] Fix | Delete
case is_single():
[382] Fix | Delete
$object = get_queried_object();
[383] Fix | Delete
$templates = array();
[384] Fix | Delete
if ( ! empty( $object->post_type ) ) {
[385] Fix | Delete
$template = get_page_template_slug( $object );
[386] Fix | Delete
if ( $template && 0 === validate_file( $template ) ) {
[387] Fix | Delete
$templates[] = get_template_directory().'/'.$template;
[388] Fix | Delete
}
[389] Fix | Delete
$name_decoded = urldecode( $object->post_name );
[390] Fix | Delete
if ( $name_decoded !== $object->post_name ) {
[391] Fix | Delete
$templates[] = get_template_directory() . "/single-{$object->post_type}-{$name_decoded}.php";
[392] Fix | Delete
}
[393] Fix | Delete
$templates[] = get_template_directory() . "/single-{$object->post_type}-{$object->post_name}.php";
[394] Fix | Delete
$templates[] = get_template_directory() . "/single-{$object->post_type}.php";
[395] Fix | Delete
}
[396] Fix | Delete
$templates[] = get_template_directory() . "/single.php";
[397] Fix | Delete
[398] Fix | Delete
foreach ( $templates as $key => $value ) {
[399] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[400] Fix | Delete
$file = $value;
[401] Fix | Delete
break;
[402] Fix | Delete
}
[403] Fix | Delete
}
[404] Fix | Delete
break;
[405] Fix | Delete
case is_page():
[406] Fix | Delete
$id = get_queried_object_id();
[407] Fix | Delete
$template = get_page_template_slug();
[408] Fix | Delete
$pagename = get_query_var('pagename');
[409] Fix | Delete
if ( ! $pagename && $id ) {
[410] Fix | Delete
// If a static page is set as the front page, $pagename will not be set. Retrieve it from the queried object
[411] Fix | Delete
$post = get_queried_object();
[412] Fix | Delete
if ( $post )
[413] Fix | Delete
$pagename = $post->post_name;
[414] Fix | Delete
}
[415] Fix | Delete
$templates = array();
[416] Fix | Delete
if ( $template && 0 === validate_file( $template ) )
[417] Fix | Delete
$templates[] = get_template_directory().'/'.$template;
[418] Fix | Delete
if ( $pagename ) {
[419] Fix | Delete
$pagename_decoded = urldecode( $pagename );
[420] Fix | Delete
if ( $pagename_decoded !== $pagename ) {
[421] Fix | Delete
$templates[] = get_template_directory() . "/page-{$pagename_decoded}.php";
[422] Fix | Delete
}
[423] Fix | Delete
$templates[] = get_template_directory() . "/page-{$pagename}.php";
[424] Fix | Delete
}
[425] Fix | Delete
if ( $id )
[426] Fix | Delete
$templates[] = get_template_directory() . "/page-{$id}.php";
[427] Fix | Delete
$templates[] = get_template_directory() . "/page.php";
[428] Fix | Delete
foreach ( $templates as $key => $value ) {
[429] Fix | Delete
if ( 'single' === $type && file_exists($value) ) {
[430] Fix | Delete
$file = $value;
[431] Fix | Delete
break;
[432] Fix | Delete
}
[433] Fix | Delete
}
[434] Fix | Delete
break;
[435] Fix | Delete
}
[436] Fix | Delete
// Polylang Frontpage #1779
[437] Fix | Delete
if ( 'single' === $type && ampforwp_polylang_front_page() && true == $redux_builder_amp['amp-frontpage-select-option'] ) {
[438] Fix | Delete
$file = get_template_directory() . '/page.php';
[439] Fix | Delete
}
[440] Fix | Delete
return $file;
[441] Fix | Delete
}
[442] Fix | Delete
/**
[443] Fix | Delete
* Sanitize featured image
[444] Fix | Delete
**/
[445] Fix | Delete
//For featured image
[446] Fix | Delete
public function featured_image_html($html, $post_id, $post_thumbnail_id, $size, $attr ){
[447] Fix | Delete
$html = $this->ampforwp_template_mode_cnt_sanitizer($html);
[448] Fix | Delete
return $html;
[449] Fix | Delete
}
[450] Fix | Delete
public function add_amp_html_attr($output, $doctype){
[451] Fix | Delete
$output .= ' amp ';
[452] Fix | Delete
return $output;
[453] Fix | Delete
}
[454] Fix | Delete
public function amp_the_content($content){
[455] Fix | Delete
global $ampforwpTemplate;
[456] Fix | Delete
if(empty($ampforwpTemplate)){ return $content; }
[457] Fix | Delete
$new_content = $ampforwpTemplate->get( 'post_amp_content' );
[458] Fix | Delete
$new_content = apply_filters("ampforwp_template_mode_the_content", $new_content);
[459] Fix | Delete
return $new_content;
[460] Fix | Delete
}
[461] Fix | Delete
public function amp_head_content(){
[462] Fix | Delete
global $ampforwpTemplate;
[463] Fix | Delete
$amp_url = get_permalink( get_queried_object_id() );
[464] Fix | Delete
printf( '<link rel="amphtml" href="%s" />', esc_url( $amp_url ) );
[465] Fix | Delete
do_action( 'amp_meta', $ampforwpTemplate );
[466] Fix | Delete
do_action( 'amp_post_template_head', $ampforwpTemplate );
[467] Fix | Delete
}
[468] Fix | Delete
public function amp_head_css(){
[469] Fix | Delete
global $ampforwpTemplate, $redux_builder_amp;
[470] Fix | Delete
$stylesheetUri = get_stylesheet_uri();
[471] Fix | Delete
$css = "";
[472] Fix | Delete
echo "<style amp-custom>";
[473] Fix | Delete
do_action( 'amp_post_template_css', $ampforwpTemplate );
[474] Fix | Delete
do_action( 'amp_css', $ampforwpTemplate );
[475] Fix | Delete
[476] Fix | Delete
$stylesheetCss = $this->ampforwp_get_remote_content($stylesheetUri);
[477] Fix | Delete
$stylesheetCss = str_replace(" img", 'amp-img', $stylesheetCss);
[478] Fix | Delete
$valuesrc = get_stylesheet_directory_uri();
[479] Fix | Delete
$stylesheetCss = preg_replace_callback('/url[(](.*?)[)]/', function($matches)use($valuesrc){
[480] Fix | Delete
$matches[1] = str_replace(array('"', "'"), array('', ''), $matches[1]);
[481] Fix | Delete
if(!wp_http_validate_url($matches[1]) && strpos($matches[1],"data:")===false){
[482] Fix | Delete
return 'url('.$valuesrc."/".$matches[1].")";
[483] Fix | Delete
}else{
[484] Fix | Delete
return $matches[0];
[485] Fix | Delete
}
[486] Fix | Delete
}, $stylesheetCss);
[487] Fix | Delete
$css .= $stylesheetCss;
[488] Fix | Delete
$css .= ampforwp_get_setting('css_editor');
[489] Fix | Delete
$css = str_replace(array('.accordion-mod'), array('.apac'), $css);
[490] Fix | Delete
if( is_user_logged_in() ){
[491] Fix | Delete
$pref = get_user_option( "show_admin_bar_front", get_current_user_id() );
[492] Fix | Delete
if($pref==="true"){
[493] Fix | Delete
$css .= $this->ampforwp_get_remote_content(AMPFORWP_PLUGIN_DIR_URI."/templates/template-mode/admin-bar.css");
[494] Fix | Delete
}
[495] Fix | Delete
}
[496] Fix | Delete
echo $this->css_sanitizer($css); // sanitized above
[497] Fix | Delete
echo "</style>";
[498] Fix | Delete
}
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function