1, '_builtin' => false, ) ); // Merge post types. $post_types = array_merge( array( 'post' => 'post', ), $post_types ); foreach ( $post_types as $post_type ) { add_filter( "manage_{$post_type}_posts_columns", array( $this, 'column_views' ) ); add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'custom_column_views' ), 6, 2 ); } } ); add_action( 'admin_menu', array( $this, 'register_options_page' ) ); add_action( 'admin_head', array( $this, 'column_style' ) ); add_action( 'admin_notices', array( $this, 'admin_notice' ) ); } /** * Register admin page */ public function register_options_page() { add_options_page( esc_html__( 'Post Views', 'powerkit' ), esc_html__( 'Post Views', 'powerkit' ), 'manage_options', powerkit_get_page_slug( $this->slug ), array( $this, 'build_options_page' ) ); } /** * Build admin page */ public function build_options_page() { if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have sufficient rights to view this page.', 'powerkit' ) ); } $this->process_options_page(); $options = powerkit_post_views_options(); ?>
%s
', esc_html__( 'Settings saved.', 'powerkit' ) ); } /** Actions */ /** ------------------- */ if ( isset( $_GET['state'] ) && 'init' === $_GET['state'] ) { // Input var ok; sanitization ok. $request = new WP_Http(); $result = $request->request( 'https://accounts.google.com/o/oauth2/token', array( 'method' => 'POST', 'body' => array( 'code' => sanitize_text_field( isset( $_GET['code'] ) ? $_GET['code'] : null ), // Input var ok; sanitization ok. 'client_id' => $options['clientid'], 'client_secret' => $options['psecret'], 'redirect_uri' => powerkit_get_page_url( $this->slug ), 'grant_type' => 'authorization_code', ), ) ); if ( ! is_array( $result ) || ! isset( $result['response']['code'] ) && 200 !== $result['response']['code'] ) { ?>
%s
', esc_html__( 'API Keys removed.', 'powerkit' ) ); } elseif ( isset( $_GET['state'] ) && 'refresh-token' === $_GET['state'] ) { // Input var ok; sanitization ok. if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'] ) ) { // Input var ok; sanitization ok. return; } powerkit_post_views_refresh_token(); printf( '%s
%s
' . esc_html__( 'Google Post Views Warning: You have to (re)connect the plugin to your Google account.' ) . '
' . esc_html__( 'Update settings', 'powerkit' ) . ' →
' . esc_html__( 'Google Post Views Error: ', 'powerkit' ) . wp_kses( $options['error'], 'post' ) . '
' . esc_html__( 'Update settings', 'powerkit' ) . ' →