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.../public_h.../wp-conte.../plugins/wordpres.../src/integrat...
File: primary-category.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations;
[2] Fix | Delete
[3] Fix | Delete
use stdClass;
[4] Fix | Delete
use WP_Error;
[5] Fix | Delete
use WP_Post;
[6] Fix | Delete
use WPSEO_Primary_Term;
[7] Fix | Delete
use Yoast\WP\SEO\Conditionals\Primary_Category_Conditional;
[8] Fix | Delete
[9] Fix | Delete
/**
[10] Fix | Delete
* Adds customizations to the front end for the primary category.
[11] Fix | Delete
*/
[12] Fix | Delete
class Primary_Category implements Integration_Interface {
[13] Fix | Delete
[14] Fix | Delete
/**
[15] Fix | Delete
* Returns the conditionals based on which this loadable should be active.
[16] Fix | Delete
*
[17] Fix | Delete
* In this case only when on the frontend, the post overview, post edit or new post admin page.
[18] Fix | Delete
*
[19] Fix | Delete
* @return array The conditionals.
[20] Fix | Delete
*/
[21] Fix | Delete
public static function get_conditionals() {
[22] Fix | Delete
return [ Primary_Category_Conditional::class ];
[23] Fix | Delete
}
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* Registers a filter to change a post's primary category.
[27] Fix | Delete
*
[28] Fix | Delete
* @return void
[29] Fix | Delete
*/
[30] Fix | Delete
public function register_hooks() {
[31] Fix | Delete
\add_filter( 'post_link_category', [ $this, 'post_link_category' ], 10, 3 );
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Filters post_link_category to change the category to the chosen category by the user.
[36] Fix | Delete
*
[37] Fix | Delete
* @param stdClass $category The category that is now used for the post link.
[38] Fix | Delete
* @param array|null $categories This parameter is not used.
[39] Fix | Delete
* @param WP_Post|null $post The post in question.
[40] Fix | Delete
*
[41] Fix | Delete
* @return array|object|WP_Error|null The category we want to use for the post link.
[42] Fix | Delete
*/
[43] Fix | Delete
public function post_link_category( $category, $categories = null, $post = null ) {
[44] Fix | Delete
$post = \get_post( $post );
[45] Fix | Delete
if ( $post === null ) {
[46] Fix | Delete
return $category;
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
$primary_category = $this->get_primary_category( $post );
[50] Fix | Delete
if ( $primary_category !== false && $primary_category !== $category->cat_ID ) {
[51] Fix | Delete
$category = \get_category( $primary_category );
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
return $category;
[55] Fix | Delete
}
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* Get the id of the primary category.
[59] Fix | Delete
*
[60] Fix | Delete
* @codeCoverageIgnore It justs wraps a dependency.
[61] Fix | Delete
*
[62] Fix | Delete
* @param WP_Post $post The post in question.
[63] Fix | Delete
*
[64] Fix | Delete
* @return int Primary category id.
[65] Fix | Delete
*/
[66] Fix | Delete
protected function get_primary_category( $post ) {
[67] Fix | Delete
$primary_term = new WPSEO_Primary_Term( 'category', $post->ID );
[68] Fix | Delete
[69] Fix | Delete
return $primary_term->get_primary_term();
[70] Fix | Delete
}
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function