: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
use Yoast\WP\SEO\Context\Meta_Tags_Context;
use Yoast\WP\SEO\Helpers\Score_Icon_Helper;
use Yoast\WP\SEO\Integrations\Admin\Admin_Columns_Cache_Integration;
use Yoast\WP\SEO\Surfaces\Values\Meta;
* Class WPSEO_Meta_Columns.
class WPSEO_Meta_Columns {
* Holds the context objects for each indexable.
* @var Meta_Tags_Context[]
* Holds the SEO analysis.
* @var WPSEO_Metabox_Analysis_SEO
* Holds the readability analysis.
* @var WPSEO_Metabox_Analysis_Readability
private $analysis_readability;
* @var Admin_Columns_Cache_Integration
private $admin_columns_cache;
* Holds the Score_Icon_Helper.
private $score_icon_helper;
* When page analysis is enabled, just initialize the hooks.
public function __construct() {
if ( apply_filters( 'wpseo_use_page_analysis', true ) === true ) {
add_action( 'admin_init', [ $this, 'setup_hooks' ] );
$this->analysis_seo = new WPSEO_Metabox_Analysis_SEO();
$this->analysis_readability = new WPSEO_Metabox_Analysis_Readability();
$this->admin_columns_cache = YoastSEO()->classes->get( Admin_Columns_Cache_Integration::class );
$this->score_icon_helper = YoastSEO()->helpers->score_icon;
public function setup_hooks() {
$this->set_post_type_hooks();
if ( $this->analysis_seo->is_enabled() ) {
add_action( 'restrict_manage_posts', [ $this, 'posts_filter_dropdown' ] );
if ( $this->analysis_readability->is_enabled() ) {
add_action( 'restrict_manage_posts', [ $this, 'posts_filter_dropdown_readability' ] );
add_filter( 'request', [ $this, 'column_sort_orderby' ] );
add_filter( 'default_hidden_columns', [ $this, 'column_hidden' ], 10, 1 );
* Adds the column headings for the SEO plugin for edit posts / pages overview.
* @param array $columns Already existing columns.
* @return array Array containing the column headings.
public function column_heading( $columns ) {
if ( $this->display_metabox() === false ) {
if ( $this->analysis_seo->is_enabled() ) {
$added_columns['wpseo-score'] = '<span class="yoast-column-seo-score yoast-column-header-has-tooltip" data-tooltip-text="'
. esc_attr__( 'SEO score', 'wordpress-seo' )
. '"><span class="screen-reader-text">'
. __( 'SEO score', 'wordpress-seo' )
. '</span></span></span>';
if ( $this->analysis_readability->is_enabled() ) {
$added_columns['wpseo-score-readability'] = '<span class="yoast-column-readability yoast-column-header-has-tooltip" data-tooltip-text="'
. esc_attr__( 'Readability score', 'wordpress-seo' )
. '"><span class="screen-reader-text">'
. __( 'Readability score', 'wordpress-seo' )
. '</span></span></span>';
$added_columns['wpseo-title'] = __( 'SEO Title', 'wordpress-seo' );
$added_columns['wpseo-metadesc'] = __( 'Meta Desc.', 'wordpress-seo' );
if ( $this->analysis_seo->is_enabled() ) {
$added_columns['wpseo-focuskw'] = __( 'Keyphrase', 'wordpress-seo' );
return array_merge( $columns, $added_columns );
* Displays the column content for the given column.
* @param string $column_name Column to display the content for.
* @param int $post_id Post to display the column content for.
public function column_content( $column_name, $post_id ) {
if ( $this->display_metabox() === false ) {
switch ( $column_name ) {
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in render_score_indicator() method.
echo $this->parse_column_score( $post_id );
case 'wpseo-score-readability':
// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Correctly escaped in render_score_indicator() method.
echo $this->parse_column_score_readability( $post_id );
$meta = $this->get_meta( $post_id );
echo esc_html( $meta->title );
$meta = $this->get_meta( $post_id );
$metadesc_val = $meta->meta_description;
if ( $metadesc_val === '' ) {
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">',
/* translators: Hidden accessibility text. */
esc_html__( 'Meta description not set.', 'wordpress-seo' ),
echo esc_html( $metadesc_val );
$focuskw_val = WPSEO_Meta::get_value( 'focuskw', $post_id );
if ( $focuskw_val === '' ) {
echo '<span aria-hidden="true">—</span><span class="screen-reader-text">',
/* translators: Hidden accessibility text. */
esc_html__( 'Focus keyphrase not set.', 'wordpress-seo' ),
echo esc_html( $focuskw_val );
* Indicates which of the SEO columns are sortable.
* @param array $columns Appended with their orderby variable.
* @return array Array containing the sortable columns.
public function column_sort( $columns ) {
if ( $this->display_metabox() === false ) {
$columns['wpseo-metadesc'] = 'wpseo-metadesc';
if ( $this->analysis_seo->is_enabled() ) {
$columns['wpseo-focuskw'] = 'wpseo-focuskw';
$columns['wpseo-score'] = 'wpseo-score';
if ( $this->analysis_readability->is_enabled() ) {
$columns['wpseo-score-readability'] = 'wpseo-score-readability';
* Hides the SEO title, meta description and focus keyword columns if the user hasn't chosen which columns to hide.
* @param array $hidden The hidden columns.
* @return array Array containing the columns to hide.
public function column_hidden( $hidden ) {
if ( ! is_array( $hidden ) ) {
array_push( $hidden, 'wpseo-title', 'wpseo-metadesc' );
if ( $this->analysis_seo->is_enabled() ) {
$hidden[] = 'wpseo-focuskw';
* Adds a dropdown that allows filtering on the posts SEO Quality.
public function posts_filter_dropdown() {
if ( ! $this->can_display_filter() ) {
$ranks = WPSEO_Rank::get_all_ranks();
/* translators: Hidden accessibility text. */
echo '<label class="screen-reader-text" for="wpseo-filter">' . esc_html__( 'Filter by SEO Score', 'wordpress-seo' ) . '</label>';
echo '<select name="seo_filter" id="wpseo-filter">';
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( '', __( 'All SEO Scores', 'wordpress-seo' ) );
foreach ( $ranks as $rank ) {
$selected = selected( $this->get_current_seo_filter(), $rank->get_rank(), false );
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( $rank->get_rank(), $rank->get_drop_down_label(), $selected );
* Adds a dropdown that allows filtering on the posts Readability Quality.
public function posts_filter_dropdown_readability() {
if ( ! $this->can_display_filter() ) {
$ranks = WPSEO_Rank::get_all_readability_ranks();
/* translators: Hidden accessibility text. */
echo '<label class="screen-reader-text" for="wpseo-readability-filter">' . esc_html__( 'Filter by Readability Score', 'wordpress-seo' ) . '</label>';
echo '<select name="readability_filter" id="wpseo-readability-filter">';
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( '', __( 'All Readability Scores', 'wordpress-seo' ) );
foreach ( $ranks as $rank ) {
$selected = selected( $this->get_current_readability_filter(), $rank->get_rank(), false );
// phpcs:ignore WordPress.Security.EscapeOutput -- Output is correctly escaped in the generate_option() method.
echo $this->generate_option( $rank->get_rank(), $rank->get_drop_down_readability_labels(), $selected );
* Generates an <option> element.
* @param string $value The option's value.
* @param string $label The option's label.
* @param string $selected HTML selected attribute for an option.
* @return string The generated <option> element.
protected function generate_option( $value, $label, $selected = '' ) {
return '<option ' . $selected . ' value="' . esc_attr( $value ) . '">' . esc_html( $label ) . '</option>';
* Returns the meta object for a given post ID.
* @param int $post_id The post ID.
* @return Meta The meta object.
protected function get_meta( $post_id ) {
$indexable = $this->admin_columns_cache->get_indexable( $post_id );
return YoastSEO()->meta->for_indexable( $indexable, 'Post_Type' );
* Determines the SEO score filter to be later used in the meta query, based on the passed SEO filter.
* @param string $seo_filter The SEO filter to use to determine what further filter to apply.
* @return array The SEO score filter.
protected function determine_seo_filters( $seo_filter ) {
if ( $seo_filter === WPSEO_Rank::NO_FOCUS ) {
return $this->create_no_focus_keyword_filter();
if ( $seo_filter === WPSEO_Rank::NO_INDEX ) {
return $this->create_no_index_filter();
$rank = new WPSEO_Rank( $seo_filter );
return $this->create_seo_score_filter( $rank->get_starting_score(), $rank->get_end_score() );
* Determines the Readability score filter to the meta query, based on the passed Readability filter.
* @param string $readability_filter The Readability filter to use to determine what further filter to apply.
* @return array The Readability score filter.
protected function determine_readability_filters( $readability_filter ) {
$rank = new WPSEO_Rank( $readability_filter );
return $this->create_readability_score_filter( $rank->get_starting_score(), $rank->get_end_score() );
* Creates a keyword filter for the meta query, based on the passed Keyword filter.
* @param string $keyword_filter The keyword filter to use.
* @return array The keyword filter.
protected function get_keyword_filter( $keyword_filter ) {
'post_type' => get_query_var( 'post_type', 'post' ),
'key' => WPSEO_Meta::$meta_prefix . 'focuskw',
'value' => sanitize_text_field( $keyword_filter ),
* Determines whether the passed filter is considered to be valid.
* @param mixed $filter The filter to check against.
* @return bool Whether the filter is considered valid.
protected function is_valid_filter( $filter ) {
return ! empty( $filter ) && is_string( $filter );
* Collects the filters and merges them into a single array.
* @return array Array containing all the applicable filters.
protected function collect_filters() {
$seo_filter = $this->get_current_seo_filter();
$readability_filter = $this->get_current_readability_filter();
$current_keyword_filter = $this->get_current_keyword_filter();
if ( $this->is_valid_filter( $seo_filter ) ) {
$active_filters = array_merge(
$this->determine_seo_filters( $seo_filter )
if ( $this->is_valid_filter( $readability_filter ) ) {
$active_filters = array_merge(
$this->determine_readability_filters( $readability_filter )
if ( $this->is_valid_filter( $current_keyword_filter ) ) {
* Adapt the meta query used to filter the post overview on keyphrase.
* @param array $keyphrase The keyphrase used in the filter.
* @param array $keyword_filter The current keyword filter.
$keyphrase_filter = apply_filters(
'wpseo_change_keyphrase_filter_in_request',
$this->get_keyword_filter( $current_keyword_filter ),
if ( is_array( $keyphrase_filter ) ) {
$active_filters = array_merge(
* Adapt the active applicable filters on the posts overview.
* @param array $active_filters The current applicable filters.
return apply_filters( 'wpseo_change_applicable_filters', $active_filters );
* Modify the query based on the filters that are being passed.
* @param array $vars Query variables that need to be modified based on the filters.
* @return array Array containing the meta query to use for filtering the posts overview.
public function column_sort_orderby( $vars ) {
$collected_filters = $this->collect_filters();
$order_by_column = $vars['orderby'];
if ( isset( $order_by_column ) ) {
// Based on the selected column, create a meta query.
$order_by = $this->filter_order_by( $order_by_column );
* Adapt the order by part of the query on the posts overview.
* @param array $order_by The current order by.
* @param string $order_by_column The current order by column.
$order_by = apply_filters( 'wpseo_change_order_by', $order_by, $order_by_column );
$vars = array_merge( $vars, $order_by );
return $this->build_filter_query( $vars, $collected_filters );
* Retrieves the meta robots query values to be used within the meta query.
* @return array Array containing the query parameters regarding meta robots.
protected function get_meta_robots_query_values() {
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
'compare' => 'NOT EXISTS',
'key' => WPSEO_Meta::$meta_prefix . 'meta-robots-noindex',
* Determines the score filters to be used. If more than one is passed, it created an AND statement for the query.