score_icon_helper = $score_icon_helper; $this->current_page_helper = $current_page_helper; } /** * {@inheritDoc} */ public function register_hooks() { \add_action( 'admin_init', [ $this, 'register_init_hooks' ] ); \add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] ); } /** * Register hooks that need to be registered after `init` due to all post types not yet being registered. * * @return void */ public function register_init_hooks() { $taxonomy = $this->current_page_helper->get_current_taxonomy(); $is_product = $this->current_page_helper->get_current_post_type() === 'product'; $is_product_cat = $taxonomy === 'product_cat'; $is_product_tag = $taxonomy === 'product_tag'; if ( ( $is_product && ( $is_product_cat || $is_product_tag ) ) || ( ! $is_product && $taxonomy ) ) { \add_filter( 'manage_edit-' . $taxonomy . '_columns', [ $this, 'add_inclusive_language_column' ] ); \add_filter( 'manage_' . $taxonomy . '_custom_column', [ $this, 'column_content' ], 10, 3 ); } } /** * Enqueues the assets needed for the integration to work. * * @return void */ public function enqueue_assets() { \wp_enqueue_style( WPSEO_Admin_Asset_Manager::PREFIX . 'premium-post-overview' ); } /** * Adds the inclusive language column for the term overview. * * @param array $columns Array with columns. * * @return array The extended array with columns. */ public function add_inclusive_language_column( $columns ) { if ( ! \is_array( $columns ) ) { return $columns; } $columns[ self::INCLUSIVE_LANGUAGE_COLUMN_NAME ] = \sprintf( ' %2$s ', \esc_attr__( 'Inclusive language score', 'wordpress-seo-premium' ), \esc_html__( 'Inclusive language score', 'wordpress-seo-premium' ) ); return $columns; } /** * Displays the column content for the given column. * * @param string $content The current content of the column. * @param string $column_name The name of the column. * @param int $term_id ID of requested taxonomy. * * @return string */ public function column_content( $content, $column_name, $term_id ) { $score = (int) WPSEO_Taxonomy_Meta::get_term_meta( $term_id, $this->current_page_helper->get_current_taxonomy(), 'inclusive_language_score' ); if ( $column_name === self::INCLUSIVE_LANGUAGE_COLUMN_NAME ) { return $this->score_icon_helper->for_inclusive_language( $score ); } return $content; } }