'0.4.2' ) {
return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer-new.php' ;
} else {
return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ;
}
} else {
return require AMPFORWP_PLUGIN_DIR .'templates/customizer/customizer.php' ;
}
}
ampforwp_include_customizer_files();
//0.
define('AMPFORWP_COMMENTS_PER_PAGE', ampforwp_define_comments_number() );
// Define number of comments
function ampforwp_define_comments_number(){
global $redux_builder_amp;
$number_of_comments = '';
if(isset($redux_builder_amp['ampforwp-number-of-comments'])){
$number_of_comments = $redux_builder_amp['ampforwp-number-of-comments'];
}
return $number_of_comments;
}
// 1. Add Home REL canonical
// Add AMP rel-canonical for home and archive pages
add_action('amp_init','ampforwp_allow_homepage');
function ampforwp_allow_homepage() {
add_action( 'wp', 'ampforwp_add_endpoint_actions' );
}
function ampforwp_add_endpoint_actions() {
$ampforwp_is_amp_endpoint = ampforwp_is_amp_endpoint();
if ( $ampforwp_is_amp_endpoint ) {
amp_prepare_render();
} else {
add_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' );
}
$cpage_var = get_query_var('cpage');
if ( $cpage_var >= 1) :
remove_action( 'wp_head', 'ampforwp_home_archive_rel_canonical' );
endif;
}
function ampforwp_amphtml_generator(){
global $redux_builder_amp;
global $wp, $post;
if( is_attachment() ) {
return;
}
if( is_home() && !$redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if( is_front_page() && ! $redux_builder_amp['ampforwp-homepage-on-off-support'] ) {
return;
}
if ( is_archive() && !$redux_builder_amp['ampforwp-archive-support'] ) {
return;
}
// #1192 Password Protected posts exclusion
if(post_password_required( $post )){
return;
}
// #1443 AMP should be skip on the check out page
if(class_exists( 'WooCommerce' )){
if(function_exists('is_checkout') && is_checkout()){
return;
}
}
// #872 no-amphtml if selected as hide from settings
if(is_archive() && $redux_builder_amp['ampforwp-archive-support']){
$selected_cats = array();
$categories = get_the_category();
if ( $categories ) {
$category_id = $categories[0]->cat_ID;
$get_categories_from_checkbox = $redux_builder_amp['hide-amp-categories'];
// Check if $get_categories_from_checkbox has some cats then only show
if ( $get_categories_from_checkbox ) {
$get_selected_cats = array_filter($get_categories_from_checkbox);
foreach ($get_selected_cats as $key => $value) {
$selected_cats[] = $key;
}
if($selected_cats && $category_id){
if(in_array($category_id, $selected_cats)){
return;
}
}
}
}
}
if( is_page() && !$redux_builder_amp['amp-on-off-for-all-pages'] ) {
return;
}
$query_arg_array = $wp->query_vars;
if( in_array( "cpage" , $query_arg_array ) ) {
if( is_front_page() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
if( is_singular() && $wp->query_vars['cpage'] >= '2' ) {
return;
}
}
if ( is_home() || is_front_page() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->request );
$amp_url = trailingslashit($current_archive_url);
} else {
$amp_url = amp_get_permalink( get_queried_object_id() );
}
global $post;
$ampforwp_amp_post_on_off_meta = get_post_meta( get_the_ID(),'ampforwp-amp-on-off',true);
if( is_singular() && $ampforwp_amp_post_on_off_meta === 'hide-amp' ) {
//dont Echo anything
} else {
$supported_types = ampforwp_get_all_post_types();
$supported_types = apply_filters('get_amp_supported_post_types',$supported_types);
$type = get_post_type();
$supported_amp_post_types = in_array( $type , $supported_types );
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
if ( (is_home() || is_archive()) && $wp->query_vars['paged'] >= '2' ) {
$new_url = home_url('/');
$category_path = $wp->request;
$explode_path = explode("/",$category_path);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
array_splice( $explode_path, -2, 0, $inserted );
$impode_url = implode('/', $explode_path);
$amp_url = $new_url . $impode_url ;
}
if( is_search() && $wp->query_vars['paged'] >= '2' ) {
$current_search_url =trailingslashit(get_home_url()) . $wp->request .'/'."?amp=1&s=".get_search_query();
}
}
$amp_url = user_trailingslashit($amp_url);
if( is_search() ) {
$current_search_url =trailingslashit(get_home_url())."?amp=1&s=".get_search_query();
$amp_url = untrailingslashit($current_search_url);
}
$amp_url = ampforwp_url_purifier($amp_url);
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
if( get_option('permalink_structure') && is_plugin_active( 'sitepress-multilingual-cms/sitepress.php' )){
global $sitepress_settings, $wp;
if($sitepress_settings[ 'language_negotiation_type' ] == 3){
if( is_singular() ){
$wpml_url =get_permalink( get_queried_object_id() );
$explode_url = explode('/', $wpml_url);
$append_amp = 'amp';
array_splice( $explode_url, 5, 0, $append_amp );
$impode_url = implode('/', $explode_url);
$amp_url = untrailingslashit($impode_url);
}
if ( is_home() || is_archive() ){
global $wp;
$current_archive_url = home_url( $wp->request );
$explode_path = explode("/",$current_archive_url);
$inserted = array(AMPFORWP_AMP_QUERY_VAR);
$query_arg_array = $wp->query_vars;
if( array_key_exists( 'paged' , $query_arg_array ) ) {
array_splice( $explode_path, -3, 0, $inserted );
}
else{
array_splice( $explode_path, -1, 0, $inserted );
}
$impode_url = implode('/', $explode_path);
$amp_url = $impode_url;
}
}
}
$amp_url = apply_filters('ampforwp_modify_rel_canonical',$amp_url);
if( $supported_amp_post_types) {
return $amp_url;
}
}
return;
}
function ampforwp_home_archive_rel_canonical() {
$amp_url = "";
$amp_url = ampforwp_amphtml_generator();
if ( $amp_url ) {
printf('', esc_url($amp_url));
}
} //end of ampforwp_home_archive_rel_canonical()
// Remove default wordpress rel canonical
add_filter('amp_frontend_show_canonical','ampforwp_remove_default_canonical');
if (! function_exists('ampforwp_remove_default_canonical') ) {
function ampforwp_remove_default_canonical() {
return false;
}
}
// 2. Custom Design
// Add Homepage AMP file code
add_filter( 'amp_post_template_file', 'ampforwp_custom_template', 10, 3 );
function ampforwp_custom_template( $file, $type, $post ) {
// Custom Homepage and Archive file
global $redux_builder_amp;
$slug = array();
$current_url_in_pieces = array();
$ampforwp_custom_post_page = ampforwp_custom_post_page();
// Homepage and FrontPage
if ( is_home() ) {
if ( 'single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php';
if ($redux_builder_amp['amp-frontpage-select-option'] == 1) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/frontpage.php';
}
if ( $ampforwp_custom_post_page == "page" && ampforwp_name_blog_page() ) {
$current_url = home_url( $GLOBALS['wp']->request );
$current_url_in_pieces = explode( '/', $current_url );
if( in_array( ampforwp_name_blog_page() , $current_url_in_pieces ) ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/index.php';
}
}
}
}
// Archive Pages
if ( is_archive() && $redux_builder_amp['ampforwp-archive-support'] ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/archive.php';
}
// Search pages
if ( is_search() &&
( $redux_builder_amp['amp-design-1-search-feature'] ||
$redux_builder_amp['amp-design-2-search-feature'] ||
$redux_builder_amp['amp-design-3-search-feature'] )
) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/search.php';
}
// Custom Single file
if ( is_single() || is_page() ) {
if('single' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/single.php';
}
}
return $file;
}
// 3. Custom Style files
add_filter( 'amp_post_template_file', 'ampforwp_set_custom_style', 10, 3 );
function ampforwp_set_custom_style( $file, $type, $post ) {
if ( 'style' === $type ) {
$file = '';
}
return $file;
}
//3.5
add_filter( 'amp_post_template_file', 'ampforwp_empty_filter', 10, 3 );
function ampforwp_empty_filter( $file, $type, $post ) {
if ( 'empty-filter' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php';
}
return $file;
}
// 4. Custom Header files
add_filter( 'amp_post_template_file', 'ampforwp_custom_header', 10, 3 );
function ampforwp_custom_header( $file, $type, $post ) {
if ( 'header-bar' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/header-bar.php';
}
return $file;
}
// 4.1 Custom Meta-Author files
add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_author', 10, 3 );
function ampforwp_set_custom_meta_author( $file, $type, $post ) {
if ( 'meta-author' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/empty-filter.php';
}
return $file;
}
// 4.2 Custom Meta-Taxonomy files
add_filter( 'amp_post_template_file', 'ampforwp_set_custom_meta_taxonomy', 10, 3 );
function ampforwp_set_custom_meta_taxonomy( $file, $type, $post ) {
if ( 'meta-taxonomy' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . 'templates/design-manager/empty-filter.php';
}
return $file;
}
// 4.5 Added hook to add more layout.
do_action('ampforwp_after_features_include');
// 5. Customize with Width of the site
add_filter( 'amp_content_max_width', 'ampforwp_change_content_width' );
function ampforwp_change_content_width( $content_max_width ) {
return 1000;
}
// 6. Add required Javascripts for extra AMP features
// Code updated and added the JS proper way #336
add_filter('amp_post_template_data','ampforwp_add_amp_social_share_script', 20);
function ampforwp_add_amp_social_share_script( $data ){
global $redux_builder_amp;
if( $redux_builder_amp['enable-single-social-icons'] == true || defined('AMPFORWP_DM_SOCIAL_CHECK') && AMPFORWP_DM_SOCIAL_CHECK === 'true' ) {
if( is_single() && is_socialshare_or_socialsticky_enabled_in_ampforwp() ) {
if ( empty( $data['amp_component_scripts']['amp-social-share'] ) ) {
$data['amp_component_scripts']['amp-social-share'] = 'https://cdn.ampproject.org/v0/amp-social-share-0.1.js';
}
}
}
// Facebook Like Script
if( true == $redux_builder_amp['ampforwp-facebook-like-button'] && is_single() && defined('AMPFORWP_DM_SOCIAL_CHECK') && 'true' === AMPFORWP_DM_SOCIAL_CHECK ){
if(empty($data['amp_component_scripts']['amp-facebook-like'])){
$data['amp_component_scripts']['amp-facebook-like'] = 'https://cdn.ampproject.org/v0/amp-facebook-like-0.1.js';
}
}
return $data;
}
// 6.1 Adding Analytics Scripts
add_filter('amp_post_template_data','ampforwp_register_analytics_script', 20);
function ampforwp_register_analytics_script( $data ){
global $redux_builder_amp;
if( false == $redux_builder_amp['ampforwp-Piwik-switch'] && false == $redux_builder_amp['ampforwp-Effective-switch'] && false == $redux_builder_amp['ampforwp-StatCounter-switch'] && false == $redux_builder_amp['ampforwp-Histats-switch'] ) {
// if( $redux_builder_amp['amp-analytics-select-option'] && $redux_builder_amp['amp-analytics-select-option'] != '3' && $redux_builder_amp['amp-analytics-select-option'] != '6' && $redux_builder_amp['amp-analytics-select-option'] != '7' && $redux_builder_amp['amp-analytics-select-option'] != '8'){
if ( empty( $data['amp_component_scripts']['amp-analytics'] ) ) {
$data['amp_component_scripts']['amp-analytics'] = 'https://cdn.ampproject.org/v0/amp-analytics-0.1.js';
}
}
return $data;
}
add_filter( 'amp_post_template_data', 'ampforwp_add_amp_related_scripts', 20 );
function ampforwp_add_amp_related_scripts( $data ) {
global $redux_builder_amp;
// Adding Sidebar Script
if(isset($redux_builder_amp['ampforwp-amp-menu']) && $redux_builder_amp['ampforwp-amp-menu']){
if ( empty( $data['amp_component_scripts']['amp-sidebar'] ) ) {
$data['amp_component_scripts']['amp-sidebar'] = 'https://cdn.ampproject.org/v0/amp-sidebar-0.1.js';
}
}
return $data;
}
// 7. Footer for AMP Pages
add_filter( 'amp_post_template_file', 'ampforwp_custom_footer', 10, 3 );
function ampforwp_custom_footer( $file, $type, $post ) {
if ( 'footer' === $type ) {
$file = AMPFORWP_PLUGIN_DIR . '/templates/design-manager/design-'. ampforwp_design_selector() .'/footer.php';
}
return $file;
}
add_action('ampforwp_global_after_footer','ampforwp_footer');
function ampforwp_footer() {
global $redux_builder_amp; ?>