Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordpres.../src/integrat.../admin
File: link-count-columns-integration.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Admin;
[2] Fix | Delete
[3] Fix | Delete
use WP_Query;
[4] Fix | Delete
use wpdb;
[5] Fix | Delete
use Yoast\WP\Lib\Model;
[6] Fix | Delete
use Yoast\WP\SEO\Actions\Indexing\Post_Link_Indexing_Action;
[7] Fix | Delete
use Yoast\WP\SEO\Conditionals\Admin\Posts_Overview_Or_Ajax_Conditional;
[8] Fix | Delete
use Yoast\WP\SEO\Conditionals\Admin_Conditional;
[9] Fix | Delete
use Yoast\WP\SEO\Conditionals\Should_Index_Links_Conditional;
[10] Fix | Delete
use Yoast\WP\SEO\Helpers\Post_Type_Helper;
[11] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Link_Count_Columns_Integration class.
[15] Fix | Delete
*/
[16] Fix | Delete
class Link_Count_Columns_Integration implements Integration_Interface {
[17] Fix | Delete
[18] Fix | Delete
/**
[19] Fix | Delete
* Partial column name.
[20] Fix | Delete
*
[21] Fix | Delete
* @var string
[22] Fix | Delete
*/
[23] Fix | Delete
public const COLUMN_LINKED = 'linked';
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Partial column name.
[27] Fix | Delete
*
[28] Fix | Delete
* @var string
[29] Fix | Delete
*/
[30] Fix | Delete
public const COLUMN_LINKS = 'links';
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* The post type helper.
[34] Fix | Delete
*
[35] Fix | Delete
* @var Post_Type_Helper
[36] Fix | Delete
*/
[37] Fix | Delete
protected $post_type_helper;
[38] Fix | Delete
[39] Fix | Delete
/**
[40] Fix | Delete
* The database object.
[41] Fix | Delete
*
[42] Fix | Delete
* @var wpdb
[43] Fix | Delete
*/
[44] Fix | Delete
protected $wpdb;
[45] Fix | Delete
[46] Fix | Delete
/**
[47] Fix | Delete
* The post link builder.
[48] Fix | Delete
*
[49] Fix | Delete
* @var Post_Link_Indexing_Action
[50] Fix | Delete
*/
[51] Fix | Delete
protected $post_link_indexing_action;
[52] Fix | Delete
[53] Fix | Delete
/**
[54] Fix | Delete
* The admin columns cache.
[55] Fix | Delete
*
[56] Fix | Delete
* @var Admin_Columns_Cache_Integration
[57] Fix | Delete
*/
[58] Fix | Delete
protected $admin_columns_cache;
[59] Fix | Delete
[60] Fix | Delete
/**
[61] Fix | Delete
* {@inheritDoc}
[62] Fix | Delete
*/
[63] Fix | Delete
public static function get_conditionals() {
[64] Fix | Delete
return [
[65] Fix | Delete
Admin_Conditional::class,
[66] Fix | Delete
Posts_Overview_Or_Ajax_Conditional::class,
[67] Fix | Delete
Should_Index_Links_Conditional::class,
[68] Fix | Delete
];
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
/**
[72] Fix | Delete
* Link_Count_Columns_Integration constructor
[73] Fix | Delete
*
[74] Fix | Delete
* @param Post_Type_Helper $post_type_helper The post type helper.
[75] Fix | Delete
* @param wpdb $wpdb The wpdb object.
[76] Fix | Delete
* @param Post_Link_Indexing_Action $post_link_indexing_action The post link indexing action.
[77] Fix | Delete
* @param Admin_Columns_Cache_Integration $admin_columns_cache The admin columns cache.
[78] Fix | Delete
*/
[79] Fix | Delete
public function __construct(
[80] Fix | Delete
Post_Type_Helper $post_type_helper,
[81] Fix | Delete
wpdb $wpdb,
[82] Fix | Delete
Post_Link_Indexing_Action $post_link_indexing_action,
[83] Fix | Delete
Admin_Columns_Cache_Integration $admin_columns_cache
[84] Fix | Delete
) {
[85] Fix | Delete
$this->post_type_helper = $post_type_helper;
[86] Fix | Delete
$this->wpdb = $wpdb;
[87] Fix | Delete
$this->post_link_indexing_action = $post_link_indexing_action;
[88] Fix | Delete
$this->admin_columns_cache = $admin_columns_cache;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
/**
[92] Fix | Delete
* {@inheritDoc}
[93] Fix | Delete
*/
[94] Fix | Delete
public function register_hooks() {
[95] Fix | Delete
\add_filter( 'posts_clauses', [ $this, 'order_by_links' ], 1, 2 );
[96] Fix | Delete
\add_filter( 'posts_clauses', [ $this, 'order_by_linked' ], 1, 2 );
[97] Fix | Delete
[98] Fix | Delete
\add_action( 'admin_init', [ $this, 'register_init_hooks' ] );
[99] Fix | Delete
[100] Fix | Delete
// Adds a filter to exclude the attachments from the link count.
[101] Fix | Delete
\add_filter( 'wpseo_link_count_post_types', [ 'WPSEO_Post_Type', 'filter_attachment_post_type' ] );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
/**
[105] Fix | Delete
* Register hooks that need to be registered after `init` due to all post types not yet being registered.
[106] Fix | Delete
*
[107] Fix | Delete
* @return void
[108] Fix | Delete
*/
[109] Fix | Delete
public function register_init_hooks() {
[110] Fix | Delete
$public_post_types = \apply_filters( 'wpseo_link_count_post_types', $this->post_type_helper->get_accessible_post_types() );
[111] Fix | Delete
[112] Fix | Delete
if ( ! \is_array( $public_post_types ) || empty( $public_post_types ) ) {
[113] Fix | Delete
return;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
foreach ( $public_post_types as $post_type ) {
[117] Fix | Delete
\add_filter( 'manage_' . $post_type . '_posts_columns', [ $this, 'add_post_columns' ] );
[118] Fix | Delete
\add_action( 'manage_' . $post_type . '_posts_custom_column', [ $this, 'column_content' ], 10, 2 );
[119] Fix | Delete
\add_filter( 'manage_edit-' . $post_type . '_sortable_columns', [ $this, 'column_sort' ] );
[120] Fix | Delete
}
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Adds the columns for the post overview.
[125] Fix | Delete
*
[126] Fix | Delete
* @param array $columns Array with columns.
[127] Fix | Delete
*
[128] Fix | Delete
* @return array The extended array with columns.
[129] Fix | Delete
*/
[130] Fix | Delete
public function add_post_columns( $columns ) {
[131] Fix | Delete
if ( ! \is_array( $columns ) ) {
[132] Fix | Delete
return $columns;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
$columns[ 'wpseo-' . self::COLUMN_LINKS ] = \sprintf(
[136] Fix | Delete
'<span class="yoast-linked-to yoast-column-header-has-tooltip" data-tooltip-text="%1$s"><span class="screen-reader-text">%2$s</span></span>',
[137] Fix | Delete
\esc_attr__( 'Number of outgoing internal links in this post. See "Yoast Columns" text in the help tab for more info.', 'wordpress-seo' ),
[138] Fix | Delete
/* translators: Hidden accessibility text. */
[139] Fix | Delete
\esc_html__( 'Outgoing internal links', 'wordpress-seo' )
[140] Fix | Delete
);
[141] Fix | Delete
[142] Fix | Delete
if ( $this->post_link_indexing_action->get_total_unindexed() === 0 ) {
[143] Fix | Delete
$columns[ 'wpseo-' . self::COLUMN_LINKED ] = \sprintf(
[144] Fix | Delete
'<span class="yoast-linked-from yoast-column-header-has-tooltip" data-tooltip-text="%1$s"><span class="screen-reader-text">%2$s</span></span>',
[145] Fix | Delete
\esc_attr__( 'Number of internal links linking to this post. See "Yoast Columns" text in the help tab for more info.', 'wordpress-seo' ),
[146] Fix | Delete
/* translators: Hidden accessibility text. */
[147] Fix | Delete
\esc_html__( 'Received internal links', 'wordpress-seo' )
[148] Fix | Delete
);
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
return $columns;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Modifies the query pieces to allow ordering column by links to post.
[156] Fix | Delete
*
[157] Fix | Delete
* @param array $pieces Array of Query pieces.
[158] Fix | Delete
* @param WP_Query $query The Query on which to apply.
[159] Fix | Delete
*
[160] Fix | Delete
* @return array
[161] Fix | Delete
*/
[162] Fix | Delete
public function order_by_linked( $pieces, $query ) {
[163] Fix | Delete
if ( $query->get( 'orderby' ) !== 'wpseo-' . self::COLUMN_LINKED ) {
[164] Fix | Delete
return $pieces;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
return $this->build_sort_query_pieces( $pieces, $query, 'incoming_link_count' );
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
/**
[171] Fix | Delete
* Modifies the query pieces to allow ordering column by links to post.
[172] Fix | Delete
*
[173] Fix | Delete
* @param array $pieces Array of Query pieces.
[174] Fix | Delete
* @param WP_Query $query The Query on which to apply.
[175] Fix | Delete
*
[176] Fix | Delete
* @return array
[177] Fix | Delete
*/
[178] Fix | Delete
public function order_by_links( $pieces, $query ) {
[179] Fix | Delete
if ( $query->get( 'orderby' ) !== 'wpseo-' . self::COLUMN_LINKS ) {
[180] Fix | Delete
return $pieces;
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
return $this->build_sort_query_pieces( $pieces, $query, 'link_count' );
[184] Fix | Delete
}
[185] Fix | Delete
[186] Fix | Delete
/**
[187] Fix | Delete
* Builds the pieces for a sorting query.
[188] Fix | Delete
*
[189] Fix | Delete
* @param array $pieces Array of Query pieces.
[190] Fix | Delete
* @param WP_Query $query The Query on which to apply.
[191] Fix | Delete
* @param string $field The field in the table to JOIN on.
[192] Fix | Delete
*
[193] Fix | Delete
* @return array Modified Query pieces.
[194] Fix | Delete
*/
[195] Fix | Delete
protected function build_sort_query_pieces( $pieces, $query, $field ) {
[196] Fix | Delete
// We only want our code to run in the main WP query.
[197] Fix | Delete
if ( ! $query->is_main_query() ) {
[198] Fix | Delete
return $pieces;
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
// Get the order query variable - ASC or DESC.
[202] Fix | Delete
$order = \strtoupper( $query->get( 'order' ) );
[203] Fix | Delete
[204] Fix | Delete
// Make sure the order setting qualifies. If not, set default as ASC.
[205] Fix | Delete
if ( ! \in_array( $order, [ 'ASC', 'DESC' ], true ) ) {
[206] Fix | Delete
$order = 'ASC';
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
$table = Model::get_table_name( 'Indexable' );
[210] Fix | Delete
[211] Fix | Delete
$pieces['join'] .= " LEFT JOIN $table AS yoast_indexable ON yoast_indexable.object_id = {$this->wpdb->posts}.ID AND yoast_indexable.object_type = 'post' ";
[212] Fix | Delete
$pieces['orderby'] = "yoast_indexable.$field $order, FIELD( {$this->wpdb->posts}.post_status, 'publish' ) $order, {$pieces['orderby']}";
[213] Fix | Delete
[214] Fix | Delete
return $pieces;
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Displays the column content for the given column.
[219] Fix | Delete
*
[220] Fix | Delete
* @param string $column_name Column to display the content for.
[221] Fix | Delete
* @param int $post_id Post to display the column content for.
[222] Fix | Delete
*
[223] Fix | Delete
* @return void
[224] Fix | Delete
*/
[225] Fix | Delete
public function column_content( $column_name, $post_id ) {
[226] Fix | Delete
$indexable = $this->admin_columns_cache->get_indexable( $post_id );
[227] Fix | Delete
// Nothing to output if we don't have the value.
[228] Fix | Delete
if ( $indexable === false ) {
[229] Fix | Delete
return;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
switch ( $column_name ) {
[233] Fix | Delete
case 'wpseo-' . self::COLUMN_LINKS:
[234] Fix | Delete
echo (int) $indexable->link_count;
[235] Fix | Delete
return;
[236] Fix | Delete
case 'wpseo-' . self::COLUMN_LINKED:
[237] Fix | Delete
if ( \get_post_status( $post_id ) === 'publish' ) {
[238] Fix | Delete
echo (int) $indexable->incoming_link_count;
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
[243] Fix | Delete
/**
[244] Fix | Delete
* Sets the sortable columns.
[245] Fix | Delete
*
[246] Fix | Delete
* @param array $columns Array with sortable columns.
[247] Fix | Delete
*
[248] Fix | Delete
* @return array The extended array with sortable columns.
[249] Fix | Delete
*/
[250] Fix | Delete
public function column_sort( array $columns ) {
[251] Fix | Delete
$columns[ 'wpseo-' . self::COLUMN_LINKS ] = 'wpseo-' . self::COLUMN_LINKS;
[252] Fix | Delete
$columns[ 'wpseo-' . self::COLUMN_LINKED ] = 'wpseo-' . self::COLUMN_LINKED;
[253] Fix | Delete
[254] Fix | Delete
return $columns;
[255] Fix | Delete
}
[256] Fix | Delete
}
[257] Fix | Delete
[258] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function