ad_options('_amp_ad_pub_id') . '" data-ad-slot="' . $this->ad_options('_amp_ad_ad_slot') . '" data-auto-format="rspv" data-full-width>
'; $wp_amp_ad_para_pos = $this->ad_options('_amp_ad_para_pos'); // Insert Adsense ad between the content, after paragraph $wp_amp_ad_para_pos $new_content = $this->ad_insert_after_paragraph( $ad_code, $wp_amp_ad_para_pos, $content ); return $new_content; } public function ad_insert_after_paragraph( $insertion, $paragraph_id, $content ) { $closing_p = ''; $counters = 0; $p_index = $paragraph_id; if ( (int)$p_index === 0 ) { $paragraphs = $insertion.$content; return $paragraphs; } else { $paragraphs = explode( $closing_p, $content ); foreach ( $paragraphs as $index => $paragraph ) { if ( trim( $paragraph ) ) { $paragraphs[$index] .= $closing_p; } if ( (int)$p_index - 1 === $index ) { $paragraphs[$index] .= $insertion; } } return implode( '', $paragraphs ); } // End of (int)$p_index === 0 } // End of ad_insert_after_paragraph public function ad_amp_in_content_Admin() { if( current_user_can( 'manage_options' ) ) { add_options_page('AMP AdSense Content Ad', 'AMP AdSense Content Ad', 'manage_options', basename(__FILE__), array($this, 'ad_amp_in_content_options')); } } public function ad_amp_in_content_actions( $links ) { $links[] = '' . esc_html__('Settings', 'amp-adsense-post-content-ad'). ''; return $links; } public function ad_amp_post_content_data_update(){ if(isset( $_POST['_ad_amp_nonce'] )){ if(wp_verify_nonce($_POST['_ad_amp_nonce'], '_ad_amp_nonce' )){ //echo "Nonce has been create successfully"; exit; if ( isset( $_POST['amp_content_adSense_ad'] )) { if( isset( $_POST['_amp_ad_pub_id'])){ update_option('_amp_ad_pub_id', sanitize_text_field( $_POST['_amp_ad_pub_id']), true ); } if( isset( $_POST['_amp_ad_ad_slot'])){ update_option('_amp_ad_ad_slot', sanitize_text_field( $_POST['_amp_ad_ad_slot']), true); } if( isset( $_POST['_amp_ad_para_pos'])){ update_option('_amp_ad_para_pos', sanitize_text_field( $_POST['_amp_ad_para_pos']), true ); } } } } } // Admin Options public function ad_amp_in_content_options(){ if( ! current_user_can( 'manage_options' ) ) { exit(); } if(isset( $_POST['_ad_amp_nonce'] )){ if(wp_verify_nonce($_POST['_ad_amp_nonce'], '_ad_amp_nonce' )){ if ( isset( $_POST['amp_content_adSense_ad'] )) { echo ''; printf(__('
This Plugin have dependency. Please make sure you have installed any of the plugin. "AMP for WordPress" by Automattic or "AMP for WP – Accelerated Mobile Pages" by Ahmed Kaludi, Mohammed Kaludi. X
'), '?ignore_notice=0'); echo "