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 ) ) { ?>
'view_analytics' ) ); ?>
get_single_admin_analytics( $start_date, $end_date, $post->ID, 0 ); ?>
$plugin_data ) { if ( $plugin_file === $module_slug ) { $plugin_found = true; break; } } if ( ! $plugin_found ) { echo esc_html__( 'Failed', 'wp-analytify' ); wp_die(); } if ( 'active' === $set_state ) { $plugin_change_state = activate_plugin( $module_slug ); } else { $plugin_change_state = deactivate_plugins( $module_slug ); } // Error in response. if ( is_wp_error( $plugin_change_state ) || ! empty( $plugin_change_state ) ) { $return = 'failed'; } } echo esc_html( $return ); wp_die(); } /** * Add analytics stats to post row actions * * @param array $actions Post actions. * @param WP_Post $post Post object. * @return array */ public function post_rows_stats( $actions, $post ) { // 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 $actions; } $display_draft_posts = apply_filters( 'analytify_filter_to_display_draft_posts', false ); if ( 'publish' === $post->post_status || true === $display_draft_posts ) { $actions['post_row_stats'] = 'Stats'; } return $actions; } /** * Add analytics stats to post submit box * * @param WP_Post $post Post object. * @return void */ public function post_submitbox_stats_action( $post ) { $display_draft_posts = apply_filters( 'analytify_filter_to_display_draft_posts', false ); // Check if the post is published or if the filter allows displaying draft posts. if ( 'publish' === $post->post_status || $display_draft_posts ) { if ( in_array( $post->post_type, $this->analytify && $this->analytify->settings ? $this->analytify->settings->get_option( 'show_analytics_post_types_back_end', 'wp-analytify-admin', array() ) : array(), true ) ) { echo '' . esc_html__( 'View Stats', 'wp-analytify' ) . ''; } } } }