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.../front-en...
File: force-rewrite-title.php
<?php
[0] Fix | Delete
[1] Fix | Delete
namespace Yoast\WP\SEO\Integrations\Front_End;
[2] Fix | Delete
[3] Fix | Delete
use Yoast\WP\SEO\Conditionals\Front_End_Conditional;
[4] Fix | Delete
use Yoast\WP\SEO\Helpers\Options_Helper;
[5] Fix | Delete
use Yoast\WP\SEO\Integrations\Integration_Interface;
[6] Fix | Delete
use Yoast\WP\SEO\Wrappers\WP_Query_Wrapper;
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Class Force_Rewrite_Title.
[10] Fix | Delete
*/
[11] Fix | Delete
class Force_Rewrite_Title implements Integration_Interface {
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The options helper.
[15] Fix | Delete
*
[16] Fix | Delete
* @var Options_Helper
[17] Fix | Delete
*/
[18] Fix | Delete
private $options;
[19] Fix | Delete
[20] Fix | Delete
/**
[21] Fix | Delete
* Toggle indicating whether output buffering has been started.
[22] Fix | Delete
*
[23] Fix | Delete
* @var bool
[24] Fix | Delete
*/
[25] Fix | Delete
private $ob_started = false;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* The WP Query wrapper.
[29] Fix | Delete
*
[30] Fix | Delete
* @var WP_Query_Wrapper
[31] Fix | Delete
*/
[32] Fix | Delete
private $wp_query;
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Sets the helpers.
[36] Fix | Delete
*
[37] Fix | Delete
* @codeCoverageIgnore It just handles dependencies.
[38] Fix | Delete
*
[39] Fix | Delete
* @param Options_Helper $options Options helper.
[40] Fix | Delete
* @param WP_Query_Wrapper $wp_query WP query wrapper.
[41] Fix | Delete
*/
[42] Fix | Delete
public function __construct( Options_Helper $options, WP_Query_Wrapper $wp_query ) {
[43] Fix | Delete
$this->options = $options;
[44] Fix | Delete
$this->wp_query = $wp_query;
[45] Fix | Delete
}
[46] Fix | Delete
[47] Fix | Delete
/**
[48] Fix | Delete
* Returns the conditionals based in which this loadable should be active.
[49] Fix | Delete
*
[50] Fix | Delete
* @return array
[51] Fix | Delete
*/
[52] Fix | Delete
public static function get_conditionals() {
[53] Fix | Delete
return [ Front_End_Conditional::class ];
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
/**
[57] Fix | Delete
* Initializes the integration.
[58] Fix | Delete
*
[59] Fix | Delete
* This is the place to register hooks and filters.
[60] Fix | Delete
*
[61] Fix | Delete
* @codeCoverageIgnore
[62] Fix | Delete
*
[63] Fix | Delete
* @return void
[64] Fix | Delete
*/
[65] Fix | Delete
public function register_hooks() {
[66] Fix | Delete
// When the option is disabled.
[67] Fix | Delete
if ( ! $this->options->get( 'forcerewritetitle', false ) ) {
[68] Fix | Delete
return;
[69] Fix | Delete
}
[70] Fix | Delete
[71] Fix | Delete
// For WordPress versions below 4.4.
[72] Fix | Delete
if ( \current_theme_supports( 'title-tag' ) ) {
[73] Fix | Delete
return;
[74] Fix | Delete
}
[75] Fix | Delete
[76] Fix | Delete
\add_action( 'template_redirect', [ $this, 'force_rewrite_output_buffer' ], 99999 );
[77] Fix | Delete
\add_action( 'wp_footer', [ $this, 'flush_cache' ], -1 );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
/**
[81] Fix | Delete
* Used in the force rewrite functionality this retrieves the output, replaces the title with the proper SEO
[82] Fix | Delete
* title and then flushes the output.
[83] Fix | Delete
*
[84] Fix | Delete
* @return bool
[85] Fix | Delete
*/
[86] Fix | Delete
public function flush_cache() {
[87] Fix | Delete
if ( $this->ob_started !== true ) {
[88] Fix | Delete
return false;
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
$content = $this->get_buffered_output();
[92] Fix | Delete
[93] Fix | Delete
$old_wp_query = $this->wp_query->get_query();
[94] Fix | Delete
[95] Fix | Delete
\wp_reset_query();
[96] Fix | Delete
[97] Fix | Delete
// When the file has the debug mark.
[98] Fix | Delete
if ( \preg_match( '/(?\'before\'.*)<!-- This site is optimized with the Yoast SEO.*<!-- \/ Yoast SEO( Premium)? plugin. -->(?\'after\'.*)/is', $content, $matches ) ) {
[99] Fix | Delete
$content = $this->replace_titles_from_content( $content, $matches );
[100] Fix | Delete
[101] Fix | Delete
unset( $matches );
[102] Fix | Delete
}
[103] Fix | Delete
[104] Fix | Delete
// phpcs:ignore WordPress.WP.GlobalVariablesOverride -- The query gets reset here with the original query.
[105] Fix | Delete
$GLOBALS['wp_query'] = $old_wp_query;
[106] Fix | Delete
[107] Fix | Delete
// phpcs:ignore WordPress.Security.EscapeOutput -- The output should already have been escaped, we are only filtering it.
[108] Fix | Delete
echo $content;
[109] Fix | Delete
[110] Fix | Delete
return true;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
/**
[114] Fix | Delete
* Starts the output buffer so it can later be fixed by flush_cache().
[115] Fix | Delete
*
[116] Fix | Delete
* @return void
[117] Fix | Delete
*/
[118] Fix | Delete
public function force_rewrite_output_buffer() {
[119] Fix | Delete
$this->ob_started = true;
[120] Fix | Delete
$this->start_output_buffering();
[121] Fix | Delete
}
[122] Fix | Delete
[123] Fix | Delete
/**
[124] Fix | Delete
* Replaces the titles from the parts that contains a title.
[125] Fix | Delete
*
[126] Fix | Delete
* @param string $content The content to remove the titles from.
[127] Fix | Delete
* @param array $parts_with_title The parts containing a title.
[128] Fix | Delete
*
[129] Fix | Delete
* @return string The modified content.
[130] Fix | Delete
*/
[131] Fix | Delete
protected function replace_titles_from_content( $content, $parts_with_title ) {
[132] Fix | Delete
if ( isset( $parts_with_title['before'] ) && \is_string( $parts_with_title['before'] ) ) {
[133] Fix | Delete
$content = $this->replace_title( $parts_with_title['before'], $content );
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
if ( isset( $parts_with_title['after'] ) ) {
[137] Fix | Delete
$content = $this->replace_title( $parts_with_title['after'], $content );
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
return $content;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* Removes the title from the part that contains the title and put this modified part back
[145] Fix | Delete
* into the content.
[146] Fix | Delete
*
[147] Fix | Delete
* @param string $part_with_title The part with the title that needs to be replaced.
[148] Fix | Delete
* @param string $content The entire content.
[149] Fix | Delete
*
[150] Fix | Delete
* @return string The altered content.
[151] Fix | Delete
*/
[152] Fix | Delete
protected function replace_title( $part_with_title, $content ) {
[153] Fix | Delete
$part_without_title = \preg_replace( '/<title.*?\/title>/i', '', $part_with_title );
[154] Fix | Delete
[155] Fix | Delete
return \str_replace( $part_with_title, $part_without_title, $content );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
/**
[159] Fix | Delete
* Starts the output buffering.
[160] Fix | Delete
*
[161] Fix | Delete
* @codeCoverageIgnore
[162] Fix | Delete
*
[163] Fix | Delete
* @return void
[164] Fix | Delete
*/
[165] Fix | Delete
protected function start_output_buffering() {
[166] Fix | Delete
\ob_start();
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Retrieves the buffered output.
[171] Fix | Delete
*
[172] Fix | Delete
* @codeCoverageIgnore
[173] Fix | Delete
*
[174] Fix | Delete
* @return false|string The buffered output.
[175] Fix | Delete
*/
[176] Fix | Delete
protected function get_buffered_output() {
[177] Fix | Delete
return \ob_get_clean();
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function