is_disabled_for_products() ) { add_filter( 'manage_edit-product_cat_columns', [ $this, 'set_custom_columns_tax' ] ); add_filter( 'manage_product_cat_custom_column', [ $this, 'custom_column_product_cat' ], 10, 3 ); } } /** * Add custom column for posts and pages screens * * @param array $columns Columns list. * @param string $post_type Current post type. * @return array Columns list. */ public function set_custom_columns( $columns, $post_type = 'page' ) { // Callback. Do not use parameter types. switch ( $post_type ) { case 'page': case 'post': case '_tax': // predefined string for internal calls. $add = true; break; case 'product': $add = ! ( new Ahrefs_Seo_Content() )->is_disabled_for_products(); break; default: $add = in_array( $post_type, ( new Ahrefs_Seo_Content() )->get_custom_post_types_enabled(), true ); } if ( $add ) { $columns['ahrefs_organic'] = _x( 'Organic traffic', 'Table column title', 'ahrefs-seo' ); } return $columns; } /** * Add post columns to categories and product categories. * * @since 0.8.0 * * @param array $columns Columns list. * @return array Columns list. */ public function set_custom_columns_tax( $columns ) { // Callback. Do not use parameter types. return $this->set_custom_columns( $columns, '_tax' ); } /** * Show content for post custom columns. * Monthly amount of organic traffic + total amount of organic traffic from post created/modified time. * * @param string $column Column name. * @param int $post_id Post ID. * @param string $taxonomy Taxonomy. Always is empty when called as callback. Filled only when called from other methods. */ public function custom_column( $column, $post_id, $taxonomy = '' ) : void { // Callback. Do not use parameter types. if ( 'ahrefs_organic' === $column ) { $post_tax = new Post_Tax( (int) $post_id, (string) $taxonomy ); $traffic = ( new Content_Db() )->content_get_organic_traffic_data_for_post( intval( $post_id ), $taxonomy ); if ( ! $post_tax->is_tax_or_published() || is_null( $traffic ) || ( is_null( $traffic['organic_month'] ) && is_null( $traffic['organic_total'] ) ) || ( $traffic['organic_month'] < 0 ) || ( $traffic['organic_total'] < 0 ) ) { ?>
add_admin_css_posts(); } } /** * Show content for category custom columns. Callback. * * @since 0.8.0 * * @param string $value Current value. * @param string $column Column name. * @param int $term_id Term ID. * @return string */ public function custom_column_category( $value, $column = '', $term_id = 0 ) { // Callback. Do not use parameter types. ob_start(); $this->custom_column( (string) $column, intval( $term_id ), 'category' ); return (string) ob_get_clean(); } /** * Show content for product category custom columns. Callback. * * @since 0.8.0 * * @param string $value Initial value. * @param string $column Column name. * @param int $term_id Term ID. * @return string */ public function custom_column_product_cat( $value, $column = '', $term_id = 0 ) { // Callback. Do not use parameter types. ob_start(); $this->custom_column( (string) $column, intval( $term_id ), 'product_cat' ); return (string) ob_get_clean(); } /** * Add styles for post columns */ private function add_admin_css_posts() : void { static $added = null; if ( is_null( $added ) ) { $added = true; ?>