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/clone/wp-conte.../plugins/accelera.../template...
File: custom-amp-content.php
<?php
[0] Fix | Delete
use AMPforWP\AMPVendor\AMP_Content;
[1] Fix | Delete
// Exit if accessed directly
[2] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[3] Fix | Delete
exit;
[4] Fix | Delete
}
[5] Fix | Delete
// Adding Custom meta Sanitizer to sanitize the custom content added throught tinymce post meta
[6] Fix | Delete
add_filter( 'amp_post_template_data', 'ampforwp_custom_post_content_sanitizer', 10, 2 );
[7] Fix | Delete
[8] Fix | Delete
function ampforwp_custom_post_content_sanitizer( $data, $post ) {
[9] Fix | Delete
global $redux_builder_amp;
[10] Fix | Delete
[11] Fix | Delete
if ( is_home() && $redux_builder_amp['amp-frontpage-select-option'] === 0 ) {
[12] Fix | Delete
return $data;
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
global $post;
[16] Fix | Delete
$amp_current_post_id = get_the_ID();
[17] Fix | Delete
if ( ampforwp_is_front_page() && ampforwp_get_frontpage_id() ) {
[18] Fix | Delete
//Custom AMP Editor Support for WPML #1138
[19] Fix | Delete
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
[20] Fix | Delete
if ( is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' ) ) {
[21] Fix | Delete
$amp_current_post_id = get_option('page_on_front');
[22] Fix | Delete
[23] Fix | Delete
}
[24] Fix | Delete
else {
[25] Fix | Delete
$amp_current_post_id = ampforwp_get_frontpage_id();
[26] Fix | Delete
}
[27] Fix | Delete
}
[28] Fix | Delete
// Custom AMP Editor Support for Polylang #1779
[29] Fix | Delete
if ( ampforwp_polylang_front_page() ) {
[30] Fix | Delete
$amp_current_post_id = pll_get_post(get_option('page_on_front'));
[31] Fix | Delete
}
[32] Fix | Delete
$amp_custom_post_content_input = get_post_meta($amp_current_post_id, 'ampforwp_custom_content_editor', true);
[33] Fix | Delete
$amp_custom_post_content_input = html_entity_decode($amp_custom_post_content_input);
[34] Fix | Delete
$amp_custom_post_content_check = get_post_meta($amp_current_post_id, 'ampforwp_custom_content_editor_checkbox', true);
[35] Fix | Delete
[36] Fix | Delete
if ( empty( $amp_custom_post_content_input ) ) {
[37] Fix | Delete
$data['ampforwp_amp_content'] = false;
[38] Fix | Delete
return $data;
[39] Fix | Delete
}
[40] Fix | Delete
[41] Fix | Delete
if ( 'yes' === $amp_custom_post_content_check ) {
[42] Fix | Delete
$amp_custom_content = new AMP_Content( $amp_custom_post_content_input,
[43] Fix | Delete
apply_filters( 'amp_content_embed_handlers', array(
[44] Fix | Delete
'AMP_Reddit_Embed_Handler' => array(),
[45] Fix | Delete
'AMP_Twitter_Embed_Handler' => array(),
[46] Fix | Delete
'AMP_YouTube_Embed_Handler' => array(),
[47] Fix | Delete
'AMP_DailyMotion_Embed_Handler' => array(),
[48] Fix | Delete
'AMP_Vimeo_Embed_Handler' => array(),
[49] Fix | Delete
'AMP_SoundCloud_Embed_Handler' => array(),
[50] Fix | Delete
'AMP_Instagram_Embed_Handler' => array(),
[51] Fix | Delete
'AMP_Vine_Embed_Handler' => array(),
[52] Fix | Delete
'AMP_Facebook_Embed_Handler' => array(),
[53] Fix | Delete
'AMP_Pinterest_Embed_Handler' => array(),
[54] Fix | Delete
'AMP_Gallery_Embed_Handler' => array(),
[55] Fix | Delete
'AMP_Playlist_Embed_Handler' => array(),
[56] Fix | Delete
'AMP_Tiktok_Embed_Handler'=>array(),
[57] Fix | Delete
) ),
[58] Fix | Delete
apply_filters( 'amp_content_sanitizers', array(
[59] Fix | Delete
'AMP_Style_Sanitizer' => array(),
[60] Fix | Delete
'AMP_Blacklist_Sanitizer' => array(),
[61] Fix | Delete
'AMP_Img_Sanitizer' => array(),
[62] Fix | Delete
'AMP_Video_Sanitizer' => array(),
[63] Fix | Delete
'AMP_Audio_Sanitizer' => array(),
[64] Fix | Delete
'AMP_Playbuzz_Sanitizer' => array(),
[65] Fix | Delete
'AMP_Iframe_Sanitizer' => array(
[66] Fix | Delete
'add_placeholder' => true,
[67] Fix | Delete
),
[68] Fix | Delete
) )
[69] Fix | Delete
);
[70] Fix | Delete
[71] Fix | Delete
if ( $amp_custom_content ) {
[72] Fix | Delete
$data['ampforwp_amp_content'] = $amp_custom_content->get_amp_content();
[73] Fix | Delete
$data['amp_component_scripts'] = $amp_custom_content->get_amp_scripts();
[74] Fix | Delete
$data['post_amp_styles'] = $amp_custom_content->get_amp_styles();
[75] Fix | Delete
}
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
return $data;
[79] Fix | Delete
}
[80] Fix | Delete
[81] Fix | Delete
[82] Fix | Delete
function ampforwp_custom_content_meta_register() {
[83] Fix | Delete
global $redux_builder_amp;
[84] Fix | Delete
global $post_id;
[85] Fix | Delete
[86] Fix | Delete
if( ampforwp_role_based_access_options() == true && ( current_user_can('edit_posts') || current_user_can('edit_pages') ) ){
[87] Fix | Delete
if ( $redux_builder_amp['amp-on-off-for-all-posts'] ) {
[88] Fix | Delete
add_meta_box( 'custom_content_editor', esc_html__( 'Custom AMP Editor', 'accelerated-mobile-pages' ), 'amp_content_editor_title_callback', 'post','normal', 'default' );
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
$frontpage_id = ampforwp_get_the_ID();
[92] Fix | Delete
if ( true == ampforwp_get_setting('amp-on-off-for-all-pages') || ( true == ampforwp_get_setting('amp-frontpage-select-option') && $post_id == $frontpage_id )) {
[93] Fix | Delete
add_meta_box( 'custom_content_editor', esc_html__( 'Custom AMP Editor','accelerated-mobile-pages' ), 'amp_content_editor_title_callback', 'page','normal', 'default' );
[94] Fix | Delete
}
[95] Fix | Delete
// Custom AMP Editor for Custom Post Types
[96] Fix | Delete
$post_types = ampforwp_get_all_post_types();
[97] Fix | Delete
if ( $post_types ) {
[98] Fix | Delete
foreach ( $post_types as $post_type ) {
[99] Fix | Delete
if ( 'post' !== $post_type && 'page' !== $post_type ) {
[100] Fix | Delete
add_meta_box( 'custom_content_editor', esc_html__( 'Custom AMP Editor', 'accelerated-mobile-pages' ), 'amp_content_editor_title_callback', $post_type ,'normal', 'default' );
[101] Fix | Delete
}
[102] Fix | Delete
}
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
// Assign Pagebuilder Meta Box // Legecy pagebuilder
[106] Fix | Delete
if ( function_exists('ampforwp_custom_theme_files_register') ) {
[107] Fix | Delete
add_meta_box( 'custom_content_sidebar', esc_html__( 'AMP Page Builder', 'accelerated-mobile-pages' ), 'amp_content_sidebar_callback', 'page','side', 'default' );
[108] Fix | Delete
}
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
}
[112] Fix | Delete
add_action('add_meta_boxes','ampforwp_custom_content_meta_register');
[113] Fix | Delete
[114] Fix | Delete
function amp_content_sidebar_callback( $post ) {
[115] Fix | Delete
global $post;
[116] Fix | Delete
global $redux_builder_amp;
[117] Fix | Delete
$current_post_id = $post->ID;
[118] Fix | Delete
[119] Fix | Delete
wp_nonce_field( basename( __FILE__) , 'custom_content_sidebar_nonce' );
[120] Fix | Delete
$amp_content_sidebar = get_post_meta($current_post_id, 'ampforwp_custom_sidebar_select', true);
[121] Fix | Delete
$amp_content_sidebar = esc_attr($amp_content_sidebar); ?>
[122] Fix | Delete
<select name="ampforwp_custom_sidebar_select" id="ampforwp-sidebars-page-sidebar-name">
[123] Fix | Delete
<option <?php if ( isset ( $amp_content_sidebar ) ) selected( $amp_content_sidebar, 'none' ); ?> value="none"><?php esc_attr_e( 'None', 'accelerated-mobile-pages' ); ?></option>
[124] Fix | Delete
<option <?php if ( isset ( $amp_content_sidebar ) ) selected( $amp_content_sidebar, 'layout-builder' ); ?> value="layout-builder"><?php esc_attr_e( 'Page Builder (AMP)', 'accelerated-mobile-pages' ); ?></option>
[125] Fix | Delete
</select>
[126] Fix | Delete
<p>Assign an AMP Page Builder Widget Area which will be used AMP page.<br /><a href="https://ampforwp.com/tutorials/page-builder">(Need Help?)</a></p>
[127] Fix | Delete
[128] Fix | Delete
<?php
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
function amp_content_editor_title_callback( $post ) {
[132] Fix | Delete
global $post;
[133] Fix | Delete
global $redux_builder_amp;
[134] Fix | Delete
$amp_current_post_id = $post->ID;
[135] Fix | Delete
if ( is_home() && $redux_builder_amp['amp-frontpage-select-option'] ) {
[136] Fix | Delete
$amp_current_post_id = ampforwp_get_frontpage_id();
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
wp_nonce_field( basename( __FILE__) , 'amp_content_editor_nonce' );
[140] Fix | Delete
$amp_content_on_off = get_post_meta($amp_current_post_id, 'ampforwp_custom_content_editor_checkbox', true);
[141] Fix | Delete
$amp_content_on_off = esc_attr($amp_content_on_off);
[142] Fix | Delete
?>
[143] Fix | Delete
<!--HTML content starts here-->
[144] Fix | Delete
[145] Fix | Delete
<label for="meta-checkbox">
[146] Fix | Delete
<p>
[147] Fix | Delete
<input type="checkbox" name="ampforwp_custom_content_editor_checkbox" id="meta-checkbox" value="yes" <?php if ( isset ( $amp_content_on_off ) ) checked( $amp_content_on_off, 'yes' ); ?> />
[148] Fix | Delete
<?php esc_attr_e( 'Use This Content as AMP Content','accelerated-mobile-pages' )?> </p>
[149] Fix | Delete
<p><?php esc_attr_e('If you want to add some special tags, then please use normal HTML into this area, it will automatically convert them into AMP compatible tags.','accelerated-mobile-pages') ?></p>
[150] Fix | Delete
</label>
[151] Fix | Delete
<div class="amp-editor-content" id="amp-editor-checker" style="background: #FFF59D;padding: 8px 14px;width:96%;margin-bottom:12px;"><b>Note: </b> <span id="ampforwp-amp-content-error-msg">AMP contents is blank, Please enter content</span></div>
[152] Fix | Delete
<!--HTML content Ends here-->
[153] Fix | Delete
<?php
[154] Fix | Delete
$content = get_post_meta ( $amp_current_post_id, 'ampforwp_custom_content_editor', true );
[155] Fix | Delete
$content = html_entity_decode($content);
[156] Fix | Delete
$editor_id = 'ampforwp_custom_content_editor';
[157] Fix | Delete
wp_editor( $content, $editor_id );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
// Save Rating Meta Field function
[161] Fix | Delete
function amp_content_editor_meta_save( $post_id ) {
[162] Fix | Delete
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
[163] Fix | Delete
return ;
[164] Fix | Delete
}
[165] Fix | Delete
// Checks save status
[166] Fix | Delete
$is_autosave = wp_is_post_autosave( $post_id );
[167] Fix | Delete
$is_revision = wp_is_post_revision( $post_id );
[168] Fix | Delete
$is_valid_nonce = (isset( $_POST['amp_content_editor_nonce'] ) && wp_verify_nonce( $_POST[ 'amp_content_editor_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
[169] Fix | Delete
[170] Fix | Delete
// Exits script depending on save status
[171] Fix | Delete
if ( $is_autosave || $is_revision || ! $is_valid_nonce ) {
[172] Fix | Delete
return;
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
//if there is data to be saved to DB
[176] Fix | Delete
// Save data of Custom AMP Editor
[177] Fix | Delete
if ( isset( $_POST['ampforwp_custom_content_editor'] ) ) {
[178] Fix | Delete
$unsan_ampforwp_custom_content_editor = htmlentities($_POST[ 'ampforwp_custom_content_editor' ]);
[179] Fix | Delete
$ampforwp_custom_content_editor = sanitize_post( $unsan_ampforwp_custom_content_editor );
[180] Fix | Delete
update_post_meta($post_id, 'ampforwp_custom_content_editor', $ampforwp_custom_content_editor );
[181] Fix | Delete
}
[182] Fix | Delete
// Save data of Custom AMP Editor CheckBox
[183] Fix | Delete
if ( isset( $_POST['ampforwp_custom_content_editor'] ) ) {
[184] Fix | Delete
$ampforwp_custom_editor_checkbox = null;
[185] Fix | Delete
if ( isset($_POST['ampforwp_custom_content_editor_checkbox']) ) {
[186] Fix | Delete
$ampforwp_custom_editor_checkbox = sanitize_text_field($_POST[ 'ampforwp_custom_content_editor_checkbox' ]);
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
update_post_meta($post_id, 'ampforwp_custom_content_editor_checkbox', $ampforwp_custom_editor_checkbox );
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
// Save data of Sidebar Select
[193] Fix | Delete
if ( isset( $_POST['ampforwp_custom_sidebar_select'] ) ) {
[194] Fix | Delete
$ampforwp_custom_sidebar_select = sanitize_text_field($_POST['ampforwp_custom_sidebar_select'] );
[195] Fix | Delete
update_post_meta($post_id, 'ampforwp_custom_sidebar_select', $ampforwp_custom_sidebar_select );
[196] Fix | Delete
}
[197] Fix | Delete
}
[198] Fix | Delete
add_action ( 'save_post' , 'amp_content_editor_meta_save' );
[199] Fix | Delete
//Add Button
[200] Fix | Delete
add_action('admin_head', 'ampforwp_add_my_tc_button');
[201] Fix | Delete
function ampforwp_add_my_tc_button() {
[202] Fix | Delete
global $typenow;
[203] Fix | Delete
// check user permissions
[204] Fix | Delete
if ( ! current_user_can('edit_posts') && ! current_user_can('edit_pages') ) {
[205] Fix | Delete
return;
[206] Fix | Delete
}
[207] Fix | Delete
// verify the post type
[208] Fix | Delete
[209] Fix | Delete
$posts = array();
[210] Fix | Delete
$post_types = ampforwp_get_all_post_types();
[211] Fix | Delete
if ( $post_types ) {
[212] Fix | Delete
foreach ( $post_types as $post_type ) {
[213] Fix | Delete
$posts[] = $post_type;
[214] Fix | Delete
}
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
if ( ! in_array( $typenow, $posts ) )
[218] Fix | Delete
return;
[219] Fix | Delete
// check if WYSIWYG is enabled
[220] Fix | Delete
if ( get_user_option('rich_editing') == 'true') {
[221] Fix | Delete
add_filter('mce_buttons', 'ampforwp_register_my_tc_button');
[222] Fix | Delete
add_filter("mce_external_plugins", "ampforwp_add_tinymce_plugin");
[223] Fix | Delete
}
[224] Fix | Delete
}
[225] Fix | Delete
//Load the js file
[226] Fix | Delete
function ampforwp_add_tinymce_plugin( $plugin_array ) {
[227] Fix | Delete
$plugin_array['ampforwp_tc_button'] = plugins_url( '/custom-amp-content-button.js', __FILE__ ); // CHANGE THE BUTTON SCRIPT HERE
[228] Fix | Delete
return $plugin_array;
[229] Fix | Delete
}
[230] Fix | Delete
//Register the Button
[231] Fix | Delete
function ampforwp_register_my_tc_button( $buttons ) {
[232] Fix | Delete
array_push($buttons, "|", "ampforwp_tc_button");
[233] Fix | Delete
return $buttons;
[234] Fix | Delete
}
[235] Fix | Delete
//Style to hide Button in the main Editor
[236] Fix | Delete
add_action('admin_head', function( ) { ?>
[237] Fix | Delete
<style type="text/css">
[238] Fix | Delete
#wp-content-editor-container .mce-container .mce-ampforwp-copy-content-button{
[239] Fix | Delete
display: none;
[240] Fix | Delete
}
[241] Fix | Delete
.dashicons-clipboard:before{
[242] Fix | Delete
font: 400 18px/1.25 dashicons;
[243] Fix | Delete
}
[244] Fix | Delete
.mce-ampforwp-copy-content-button .mce-txt{
[245] Fix | Delete
margin-left: 5px;
[246] Fix | Delete
}
[247] Fix | Delete
</style>
[248] Fix | Delete
<?php });
[249] Fix | Delete
[250] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function