because ajax request are fired with the admin_url(), even on front-end. * more here : https://codex.wordpress.org/AJAX_in_Plugins * */ if ( ! class_exists( 'CZR_placeholders' ) ) : class CZR_placeholders { //Access any method or var of the class with classname::$instance -> var or method(): static $instance; public $nonce_handle; function __construct () { self::$instance =& $this; add_action( 'init' , array( $this, 'czr_fn_placeholders_ajax_setup') ); add_action( 'template_redirect' , array( $this, 'czr_fn_maybe_register_front_placeholders'), 500 ); /* * To display widget placeholders in the customizer preview * @since WP 3.9.0 */ add_filter( 'dynamic_sidebar_has_widgets' , array( $this, 'czr_fn_maybe_add_preview_widget_placeholders' ), 9999, 2 ); } /***************************************************** * ADMIN AJAX HOOKS ALL PLACEHOLDERS *****************************************************/ /** * hook : init => because we need to fire this function before the admin_ajax.php call * @since v3.4+ */ function czr_fn_placeholders_ajax_setup() { if ( ! czr_fn_is_front_help_enabled() ) return; add_action( 'wp_ajax_dismiss_thumbnail_help' , array( $this, 'czr_fn_dismiss_thumbnail_help' ) ); add_action( 'wp_ajax_dismiss_img_smartload_help', array( $this, 'czr_fn_dismiss_img_smartload_help' ) ); /* add_action( 'wp_ajax_dismiss_sidenav_help' , array( $this, 'czr_fn_dismiss_sidenav_help' ) ); add_action( 'wp_ajax_dismiss_second_menu_notice', array( $this, 'czr_fn_dismiss_second_menu_notice' ) ); add_action( 'wp_ajax_dismiss_main_menu_notice' , array( $this, 'czr_fn_dismiss_main_menu_notice' ) ); add_action( 'wp_ajax_dismiss_slider_notice' , array( $this, 'czr_fn_dismiss_slider_notice' ) ); add_action( 'wp_ajax_remove_slider' , array( $this, 'czr_fn_remove_slider' ) ); */ add_action( 'wp_ajax_dismiss_fp_notice' , array( $this, 'czr_fn_dismiss_fp_notice' ) ); add_action( 'wp_ajax_remove_fp' , array( $this, 'czr_fn_remove_fp' ) ); add_action( 'wp_ajax_dismiss_widget_notice' , array( $this, 'czr_fn_dismiss_widget_notice' ) ); } //hook: template_redirect function czr_fn_maybe_register_front_placeholders() { //do nothing when is customizing or is admin or front help notices disabled if ( is_admin() || czr_fn_is_customizing() || ! czr_fn_is_front_help_enabled() ) return; //do nothing when user not logged in or cannot edit theme options, unless is CZR_DEV == true if ( !( defined('CZR_DEV') && true === CZR_DEV ) ) { if ( ! ( is_user_logged_in() && current_user_can('edit_theme_options') ) ) return; } //enqueue resources add_filter( 'czr_enqueue_placeholders_resources', '__return_true' ); //one noce for all $this->nonce_handle = wp_create_nonce( 'czr-helpblock-nonce' ); $this->placeholder_template_callback = array( $this, 'czr_fn_help_block_template' ); $help_blocks = array( //left sidebar array( 'template' => false, 'hook' => '__before_left_sidebar_widgets', 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_widget_notice', 'element_tag' => 'aside', 'position' => 'sidebar', 'help_title' => __( 'The left sidebar has no widgets', 'customizr' ), 'help_message' => sprintf( __( 'Add widgets to this sidebar %s or %s.', 'customizr' ), sprintf( '%3$s', czr_fn_get_customizer_url( array( 'panel' => 'widgets' ) ), __( 'Add widgets', 'customizr' ), __( 'now', 'customizr' ) ), sprintf('%1$s', __( 'dismiss this notice', 'customizr') ) ), 'help_secondary_message' => sprintf('
%1s %4$s
', __( 'You can also remove this sidebar by changing the current page layout.', 'customizr' ), '//docs.presscustomizr.com/article/107-customizr-theme-options-pages-and-posts-layout', __( 'Changing the layout in the Customizr theme' , 'customizr'), __( 'See the theme documentation.' , 'customizr' ) ) ), 'controller' => array( $this, 'czr_fn_is_left_sidebar_widget_placeholder_enabled' ) ), //right sidebar array( 'template' => false, 'hook' => '__before_right_sidebar_widgets', 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_widget_notice', 'element_tag' => 'aside', 'position' => 'sidebar', 'help_title' => __( 'The right sidebar has no widgets', 'customizr'), 'help_message' => sprintf( __( 'Add widgets to the footer %s or %s.', 'customizr'), sprintf( '%3$s', czr_fn_get_customizer_url( array( 'panel' => 'widgets') ), __( 'Add widgets', 'customizr'), __('now', 'customizr') ), sprintf('%1$s', __( 'dismiss this notice', 'customizr') ) ), 'help_secondary_message' => sprintf('%1s %4$s
', __( 'You can also remove this sidebar by changing the current page layout.', 'customizr' ), '//docs.presscustomizr.com/article/107-customizr-theme-options-pages-and-posts-layout', __( 'Changing the layout in the Customizr theme' , 'customizr'), __( 'See the theme documentation.' , 'customizr' ) ) ), 'controller' => array( $this, 'czr_fn_is_right_sidebar_widget_placeholder_enabled' ) ), //footer_horizontal_widgets // array( // 'template' => false, // 'hook' => '__before_footer', // 'priority' => '999', // 'callback' => $this->placeholder_template_callback, // 'cb_params' => array( // 'dismiss_action' => 'dismiss_widget_notice', // 'element_tag' => 'aside', // 'element_class' => 'col-12 horizontal-footer', // 'position' => 'horizontal_footer', // 'help_title' => __( 'The horizontal footer widget area has no widgets', 'customizr'), // 'help_message' => sprintf( __( 'Add widgets to the horizontal footer widget area %s or %s.', 'customizr'), // sprintf( '%3$s', czr_fn_get_customizer_url( array( 'panel' => 'widgets') ), __( 'Add widgets', 'customizr'), __('now', 'customizr') ), // sprintf('%1$s', // __( 'dismiss this notice', 'customizr') // ) // ), // ), // 'controller' => array( $this, 'czr_fn_is_horizontal_footer_widgets_placeholder_enabled' ) // ), //footer widgets array( 'template' => false, 'hook' => '__before_inner_footer', 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_widget_notice', 'element_tag' => 'aside', 'position' => 'footer', 'help_title' => __( 'The footer has no widgets', 'customizr'), 'help_message' => sprintf( __( 'Add widgets to the footer %s or %s.', 'customizr'), sprintf( '%3$s', czr_fn_get_customizer_url( array( 'panel' => 'widgets') ), __( 'Add widgets', 'customizr'), __('now', 'customizr') ), sprintf('%1$s', __( 'dismiss this notice', 'customizr') ) ), ), 'controller' => array( $this, 'czr_fn_is_footer_widgets_placeholder_enabled' ) ), //featured image in posts array( 'template' => false, 'hook' => '__before_content_inner', 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_thumbnail_help', 'help_message' => __( "You can display your post's featured image here if you have set one.", 'customizr' ), 'help_secondary_message' => sprintf( '%1$s
%2$s
', sprintf( __("%s to display a featured image here.", 'customizr'), sprintf( '%2$s', czr_fn_get_customizer_url( array( "section" => "single_posts_sec") ), __( 'Jump to the customizer now', 'customizr') ) ), sprintf( __( "Don't know how to set a featured image to a post? Learn how in the %s.", 'customizr' ), sprintf('%2$s ' , esc_url('codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail'), __('WordPress documentation' , 'customizr' ) ) ) ), ), 'controller' => array( $this, 'czr_fn_is_post_thumbnail_help_on' ) ), //featured image in pages array( 'template' => false, 'hook' => '__before_content_inner', 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_thumbnail_help', 'help_message' => __( "You can display your page's featured image here if you have set one.", 'customizr' ), 'help_secondary_message' => sprintf( '%1$s
%2$s
', sprintf( __("%s to display a featured image here.", 'customizr'), sprintf( '%2$s', czr_fn_get_customizer_url( array( "section" => "single_pages_sec" ) ), __( 'Jump to the customizer now', 'customizr') ) ), sprintf( __( "Don't know how to set a featured image to a page? Learn how in the %s.", 'customizr' ), sprintf('%2$s ' , esc_url('codex.wordpress.org/Post_Thumbnails#Setting_a_Post_Thumbnail'), __('WordPress documentation' , 'customizr' ) ) ) ), ), 'controller' => array( $this, 'czr_fn_is_page_thumbnail_help_on' ) ), //smartload in lists of posts array( 'template' => false, 'callback' => $this->placeholder_template_callback, 'hook' => '__loop_start', 'cb_params' => array( 'dismiss_action' => 'dismiss_img_smartload_help', 'element_class' => 'col-12 tc-post-list-smarload-help', 'help_message' => __( 'Did you know you can easily speed up your page load by deferring the loading of the non visible images?', 'customizr' ), 'help_secondary_message' => sprintf( "%s
", sprintf( __("%s and check the option 'Load images on scroll' under 'Website Performances' section.", 'customizr'), sprintf( '%2$s', czr_fn_get_customizer_url( array( "control" => "tc_img_smart_load", "section" => "performances_sec" ) ), __( "Jump to the customizer now", "customizr") ) ) ) ), 'controller' => array( $this, 'czr_fn_is_post_lists_img_smartload_help_on' ) ), //featured pages // array( // 'template' => false, // 'hook' => '__after_fp', // 'callback' => $this->placeholder_template_callback, // 'cb_params' => array( // 'dismiss_action' => 'dismiss_fp_notice', // 'remove_action' => 'remove_fp', // 'remove_selector' => '.marketing', // 'element_class' => 'col-12 offset-md-6 col-md-6', // 'help_message' => sprintf( __("Edit those featured pages %s, or %s (you'll be able to add yours later)." , "customizr"), // sprintf( '%2$s', __( "Edit those featured pages", "customizr" ), __( "now", "customizr" ), czr_fn_get_customizer_url( array( 'control' => 'tc_show_featured_pages', 'section' => 'frontpage_sec') ) ), // sprintf( '%2$s', __( "Remove the featured pages", "customizr" ), __( "remove them", "customizr" ) ) // ), // ), // 'controller' => array( $this, 'czr_fn_is_fp_notice_on' ) // ), ); //register help blocks foreach ( $help_blocks as $help_block_model ) { CZR() -> collection -> czr_fn_register( $help_block_model ); }//foreach //different treatment for the smartload in singular as we want to know the number of images present in the post/page content //this action hook is triggered only in a page or in a post add_action( '__before_content_inner' , array( $this, 'czr_fn_maybe_filter_the_content_for_smartload_help' ) ); } //hook: __before_content_inner function czr_fn_maybe_filter_the_content_for_smartload_help() { //not in home if ( czr_fn_is_real_home() ) { return; } add_filter( 'the_content' , array( $this, 'czr_fn_maybe_display_img_smartload_help') , PHP_INT_MAX ); } /** * Maybe displays a help block about images smartload for single pages/posts prepended to the content * hook : the_content */ function czr_fn_maybe_display_img_smartload_help( $the_content ) { if ( $this->czr_fn_is_img_smartload_help_on( $text = $the_content, $min_img_num = 2 ) ) { ob_start(); CZR() -> collection -> czr_fn_register( array( 'template' => false, 'callback' => $this->placeholder_template_callback, 'cb_params' => array( 'dismiss_action' => 'dismiss_img_smartload_help', 'help_message' => __( 'Did you know you can easily speed up your page load by deferring the loading of the non visible images?', 'customizr' ), 'help_secondary_message' => sprintf( "%s
", sprintf( __("%s and check the option 'Load images on scroll' under 'Website Performances' section.", 'customizr'), sprintf( '%2$s', czr_fn_get_customizer_url( array( "control" => "tc_img_smart_load", "section" => "performances_sec" ) ), __( 'Jump to the customizer now', 'customizr' ) ) ) ) ), 'render' => true, ) ); $ph = ob_get_clean(); return $ph . $the_content; } return $the_content; } /* * Maybe adds widget placeholders when in customizer preview to the widget areas with no widgets */ //hook: dynamic_sidebar_has_widgets function czr_fn_maybe_add_preview_widget_placeholders( $did_one, $index ) { if ( !czr_fn_is_customize_preview_frame() || czr_fn_isprevdem() ) return $did_one; if ( $did_one ) { return $did_one; } //gets the filtered default values $widgets = CZR_widgets::$instance->widgets; //Inline style, we really don't need to add this to our syle css or enqueue a different style, right? $placeholder_style = ' style="background:#f7f8f9;padding:7%;text-align:center;border:2px dotted #008ec2;font-size:.875em;"'; $placeholder_title_style = ' style="margin:0.5em;font-size:1.2em;line-height:1.5em;color:#444"'; $placeholder_zone_name_style = ' style="font-weight:bold"'; if ( array_key_exists( $index, $widgets ) ) { printf('', __('Add widgets to the zone :', 'customizr'), isset( $widgets[ $index ][ 'name' ] ) ? $widgets[ $index ][ 'name' ] : $widgets[ $index ], $placeholder_style, $placeholder_title_style, $placeholder_zone_name_style, sprintf( '