analytify = $analytify; $this->init_hooks(); } /** * Initialize hooks * * @return void */ private function init_hooks() { // Hooks are now managed by Analytify_Loader class. // This prevents duplicate hook registration. } /** * Show metabox under each Post type to display Analytics of single post/page in wp-admin. * * @return void */ public function show_admin_single_analytics_add_metabox() { // Return if disable post stats is on. $disable_post_stats = $this->analytify && $this->analytify->settings ? $this->analytify->settings->get_option( 'enable_back_end', 'wp-analytify-admin', 'on' ) : 'on'; if ( 'on' !== $disable_post_stats ) { return; } global $post; if ( ! isset( $post ) ) { return; } $display_draft_posts = apply_filters( 'analytify_filter_to_display_draft_posts', false ); // Don't show statistics on posts which are not published. if ( 'publish' !== $post->post_status && ! $display_draft_posts ) { return; } $post_types = $this->analytify && $this->analytify->settings ? $this->analytify->settings->get_option( 'show_analytics_post_types_back_end', 'wp-analytify-admin' ) : array(); // Don't load boxes/sections if no any post type is selected. if ( ! empty( $post_types ) ) { foreach ( $post_types as $post_type ) { add_meta_box( 'pa-single-admin-analytics', // $id __( 'Analytify - Stats of this Post/Page', 'wp-analytify' ), // $title. array( $this, 'show_admin_single_analytics', ), // $callback $post_type, // $posts 'normal', // $context 'high' // $priority ); } } } /** * Show Analytics of single post/page in wp-admin under EDIT screen. * * @return void */ public function show_admin_single_analytics() { global $post; $back_exclude_posts = false; $_exclude_profile = get_option( 'wp-analytify-admin' ); if ( isset( $_exclude_profile['exclude_pages_back_end'] ) ) { $back_exclude_posts = explode( ',', $_exclude_profile['exclude_pages_back_end'] ); } if ( is_array( $back_exclude_posts ) ) { if ( in_array( $post->ID, $back_exclude_posts, true ) ) { esc_html_e( 'This post is excluded and will NOT show Analytics.', 'wp-analytify' ); return; } } $url_post = ''; $url_post = wp_parse_url( get_permalink( $post->ID ) ? get_permalink( $post->ID ) : '' ); if ( get_the_time( 'Y', $post->ID ) < 2005 ) { $start_date = '2005-01-01'; } else { $start_date = (string) ( get_the_time( 'Y-m-d', $post->ID ) ? get_the_time( 'Y-m-d', $post->ID ) : '2005-01-01' ); } $end_date = gmdate( 'Y-m-d' ); $is_access_level = $this->analytify && $this->analytify->settings ? $this->analytify->settings->get_option( 'show_analytics_roles_back_end', 'wp-analytify-admin' ) : array(); if ( $this->analytify && $this->analytify->pa_check_roles( $is_access_level ) ) { ?>