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/wp-conte.../plugins/wordpres.../admin/watchers
File: class-slug-change-watcher.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* WPSEO plugin file.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WPSEO\Admin\Watchers
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Class WPSEO_Slug_Change_Watcher.
[8] Fix | Delete
*/
[9] Fix | Delete
class WPSEO_Slug_Change_Watcher implements WPSEO_WordPress_Integration {
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Registers all hooks to WordPress.
[13] Fix | Delete
*
[14] Fix | Delete
* @return void
[15] Fix | Delete
*/
[16] Fix | Delete
public function register_hooks() {
[17] Fix | Delete
// If the current plugin is Yoast SEO Premium, stop registering.
[18] Fix | Delete
if ( YoastSEO()->helpers->product->is_premium() ) {
[19] Fix | Delete
return;
[20] Fix | Delete
}
[21] Fix | Delete
[22] Fix | Delete
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_assets' ] );
[23] Fix | Delete
[24] Fix | Delete
// Detect a post trash.
[25] Fix | Delete
add_action( 'wp_trash_post', [ $this, 'detect_post_trash' ] );
[26] Fix | Delete
[27] Fix | Delete
// Detect a post delete.
[28] Fix | Delete
add_action( 'before_delete_post', [ $this, 'detect_post_delete' ] );
[29] Fix | Delete
[30] Fix | Delete
// Detects deletion of a term.
[31] Fix | Delete
add_action( 'delete_term_taxonomy', [ $this, 'detect_term_delete' ] );
[32] Fix | Delete
}
[33] Fix | Delete
[34] Fix | Delete
/**
[35] Fix | Delete
* Enqueues the quick edit handler.
[36] Fix | Delete
*
[37] Fix | Delete
* @return void
[38] Fix | Delete
*/
[39] Fix | Delete
public function enqueue_assets() {
[40] Fix | Delete
global $pagenow;
[41] Fix | Delete
[42] Fix | Delete
if ( ! in_array( $pagenow, [ 'edit.php', 'edit-tags.php' ], true ) ) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$asset_manager = new WPSEO_Admin_Asset_Manager();
[47] Fix | Delete
$asset_manager->enqueue_script( 'quick-edit-handler' );
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Shows a message when a post is about to get trashed.
[52] Fix | Delete
*
[53] Fix | Delete
* @param int $post_id The current post ID.
[54] Fix | Delete
*
[55] Fix | Delete
* @return void
[56] Fix | Delete
*/
[57] Fix | Delete
public function detect_post_trash( $post_id ) {
[58] Fix | Delete
if ( ! $this->is_post_viewable( $post_id ) ) {
[59] Fix | Delete
return;
[60] Fix | Delete
}
[61] Fix | Delete
[62] Fix | Delete
$post_label = $this->get_post_type_label( get_post_type( $post_id ) );
[63] Fix | Delete
[64] Fix | Delete
/* translators: %1$s expands to the translated name of the post type. */
[65] Fix | Delete
$first_sentence = sprintf( __( 'You just trashed a %1$s.', 'wordpress-seo' ), $post_label );
[66] Fix | Delete
$second_sentence = __( 'Search engines and other websites can still send traffic to your trashed content.', 'wordpress-seo' );
[67] Fix | Delete
$message = $this->get_message( $first_sentence, $second_sentence );
[68] Fix | Delete
[69] Fix | Delete
$this->add_notification( $message );
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* Shows a message when a post is about to get trashed.
[74] Fix | Delete
*
[75] Fix | Delete
* @param int $post_id The current post ID.
[76] Fix | Delete
*
[77] Fix | Delete
* @return void
[78] Fix | Delete
*/
[79] Fix | Delete
public function detect_post_delete( $post_id ) {
[80] Fix | Delete
if ( ! $this->is_post_viewable( $post_id ) ) {
[81] Fix | Delete
return;
[82] Fix | Delete
}
[83] Fix | Delete
[84] Fix | Delete
$post_label = $this->get_post_type_label( get_post_type( $post_id ) );
[85] Fix | Delete
[86] Fix | Delete
/* translators: %1$s expands to the translated name of the post type. */
[87] Fix | Delete
$first_sentence = sprintf( __( 'You just deleted a %1$s.', 'wordpress-seo' ), $post_label );
[88] Fix | Delete
$second_sentence = __( 'Search engines and other websites can still send traffic to your deleted content.', 'wordpress-seo' );
[89] Fix | Delete
$message = $this->get_message( $first_sentence, $second_sentence );
[90] Fix | Delete
[91] Fix | Delete
$this->add_notification( $message );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
/**
[95] Fix | Delete
* Shows a message when a term is about to get deleted.
[96] Fix | Delete
*
[97] Fix | Delete
* @param int $term_taxonomy_id The term taxonomy ID that will be deleted.
[98] Fix | Delete
*
[99] Fix | Delete
* @return void
[100] Fix | Delete
*/
[101] Fix | Delete
public function detect_term_delete( $term_taxonomy_id ) {
[102] Fix | Delete
if ( ! $this->is_term_viewable( $term_taxonomy_id ) ) {
[103] Fix | Delete
return;
[104] Fix | Delete
}
[105] Fix | Delete
[106] Fix | Delete
$term = get_term_by( 'term_taxonomy_id', (int) $term_taxonomy_id );
[107] Fix | Delete
$term_label = $this->get_taxonomy_label_for_term( $term->term_id );
[108] Fix | Delete
[109] Fix | Delete
/* translators: %1$s expands to the translated name of the term. */
[110] Fix | Delete
$first_sentence = sprintf( __( 'You just deleted a %1$s.', 'wordpress-seo' ), $term_label );
[111] Fix | Delete
$second_sentence = __( 'Search engines and other websites can still send traffic to your deleted content.', 'wordpress-seo' );
[112] Fix | Delete
$message = $this->get_message( $first_sentence, $second_sentence );
[113] Fix | Delete
[114] Fix | Delete
$this->add_notification( $message );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
/**
[118] Fix | Delete
* Checks if the post is viewable.
[119] Fix | Delete
*
[120] Fix | Delete
* @param string $post_id The post id to check.
[121] Fix | Delete
*
[122] Fix | Delete
* @return bool Whether the post is viewable or not.
[123] Fix | Delete
*/
[124] Fix | Delete
protected function is_post_viewable( $post_id ) {
[125] Fix | Delete
$post_type = get_post_type( $post_id );
[126] Fix | Delete
if ( ! WPSEO_Post_Type::is_post_type_accessible( $post_type ) ) {
[127] Fix | Delete
return false;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
$post_status = get_post_status( $post_id );
[131] Fix | Delete
if ( ! $this->check_visible_post_status( $post_status ) ) {
[132] Fix | Delete
return false;
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return true;
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Checks if the term is viewable.
[140] Fix | Delete
*
[141] Fix | Delete
* @param int $term_taxonomy_id The term taxonomy ID to check.
[142] Fix | Delete
*
[143] Fix | Delete
* @return bool Whether the term is viewable or not.
[144] Fix | Delete
*/
[145] Fix | Delete
protected function is_term_viewable( $term_taxonomy_id ) {
[146] Fix | Delete
$term = get_term_by( 'term_taxonomy_id', (int) $term_taxonomy_id );
[147] Fix | Delete
[148] Fix | Delete
if ( ! $term || is_wp_error( $term ) ) {
[149] Fix | Delete
return false;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
$taxonomy = get_taxonomy( $term->taxonomy );
[153] Fix | Delete
if ( ! $taxonomy ) {
[154] Fix | Delete
return false;
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
return $taxonomy->publicly_queryable || $taxonomy->public;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
/**
[161] Fix | Delete
* Gets the taxonomy label to use for a term.
[162] Fix | Delete
*
[163] Fix | Delete
* @param int $term_id The term ID.
[164] Fix | Delete
*
[165] Fix | Delete
* @return string The taxonomy's singular label.
[166] Fix | Delete
*/
[167] Fix | Delete
protected function get_taxonomy_label_for_term( $term_id ) {
[168] Fix | Delete
$term = get_term( $term_id );
[169] Fix | Delete
$taxonomy = get_taxonomy( $term->taxonomy );
[170] Fix | Delete
[171] Fix | Delete
return $taxonomy->labels->singular_name;
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Retrieves the singular post type label.
[176] Fix | Delete
*
[177] Fix | Delete
* @param string $post_type Post type to retrieve label from.
[178] Fix | Delete
*
[179] Fix | Delete
* @return string The singular post type name.
[180] Fix | Delete
*/
[181] Fix | Delete
protected function get_post_type_label( $post_type ) {
[182] Fix | Delete
$post_type_object = get_post_type_object( $post_type );
[183] Fix | Delete
[184] Fix | Delete
// If the post type of this post wasn't registered default back to post.
[185] Fix | Delete
if ( $post_type_object === null ) {
[186] Fix | Delete
$post_type_object = get_post_type_object( 'post' );
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
return $post_type_object->labels->singular_name;
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
/**
[193] Fix | Delete
* Checks whether the given post status is visible or not.
[194] Fix | Delete
*
[195] Fix | Delete
* @param string $post_status The post status to check.
[196] Fix | Delete
*
[197] Fix | Delete
* @return bool Whether or not the post is visible.
[198] Fix | Delete
*/
[199] Fix | Delete
protected function check_visible_post_status( $post_status ) {
[200] Fix | Delete
$visible_post_statuses = [
[201] Fix | Delete
'publish',
[202] Fix | Delete
'static',
[203] Fix | Delete
'private',
[204] Fix | Delete
];
[205] Fix | Delete
[206] Fix | Delete
return in_array( $post_status, $visible_post_statuses, true );
[207] Fix | Delete
}
[208] Fix | Delete
[209] Fix | Delete
/**
[210] Fix | Delete
* Returns the message around changed URLs.
[211] Fix | Delete
*
[212] Fix | Delete
* @param string $first_sentence The first sentence of the notification.
[213] Fix | Delete
* @param string $second_sentence The second sentence of the notification.
[214] Fix | Delete
*
[215] Fix | Delete
* @return string The full notification.
[216] Fix | Delete
*/
[217] Fix | Delete
protected function get_message( $first_sentence, $second_sentence ) {
[218] Fix | Delete
return '<h2>' . __( 'Make sure you don\'t miss out on traffic!', 'wordpress-seo' ) . '</h2>'
[219] Fix | Delete
. '<p>'
[220] Fix | Delete
. $first_sentence
[221] Fix | Delete
. ' ' . $second_sentence
[222] Fix | Delete
. ' ' . __( 'You should create a redirect to ensure your visitors do not get a 404 error when they click on the no longer working URL.', 'wordpress-seo' )
[223] Fix | Delete
/* translators: %s expands to Yoast SEO Premium */
[224] Fix | Delete
. ' ' . sprintf( __( 'With %s, you can easily create such redirects.', 'wordpress-seo' ), 'Yoast SEO Premium' )
[225] Fix | Delete
. '</p>'
[226] Fix | Delete
. '<p><a class="yoast-button-upsell" data-action="load-nfd-ctb" data-ctb-id="f6a84663-465f-4cb5-8ba5-f7a6d72224b2" href="' . WPSEO_Shortlinker::get( 'https://yoa.st/1d0' ) . '" target="_blank">'
[227] Fix | Delete
/* translators: %s expands to Yoast SEO Premium */
[228] Fix | Delete
. sprintf( __( 'Get %s', 'wordpress-seo' ), 'Yoast SEO Premium' )
[229] Fix | Delete
/* translators: Hidden accessibility text. */
[230] Fix | Delete
. '<span class="screen-reader-text">' . __( '(Opens in a new browser tab)', 'wordpress-seo' ) . '</span>'
[231] Fix | Delete
. '<span aria-hidden="true" class="yoast-button-upsell__caret"></span>'
[232] Fix | Delete
. '</a></p>';
[233] Fix | Delete
}
[234] Fix | Delete
[235] Fix | Delete
/**
[236] Fix | Delete
* Adds a notification to be shown on the next page request since posts are updated in an ajax request.
[237] Fix | Delete
*
[238] Fix | Delete
* @param string $message The message to add to the notification.
[239] Fix | Delete
*
[240] Fix | Delete
* @return void
[241] Fix | Delete
*/
[242] Fix | Delete
protected function add_notification( $message ) {
[243] Fix | Delete
$notification = new Yoast_Notification(
[244] Fix | Delete
$message,
[245] Fix | Delete
[
[246] Fix | Delete
'type' => 'notice-warning is-dismissible',
[247] Fix | Delete
'yoast_branding' => true,
[248] Fix | Delete
]
[249] Fix | Delete
);
[250] Fix | Delete
[251] Fix | Delete
$notification_center = Yoast_Notification_Center::get();
[252] Fix | Delete
$notification_center->add_notification( $notification );
[253] Fix | Delete
}
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function