Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/jetpack/src
File: class-deprecate.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Place to properly deprecate Jetpack features.
[2] Fix | Delete
*
[3] Fix | Delete
* @package automattic/jetpack
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
namespace Automattic\Jetpack\Plugin;
[7] Fix | Delete
[8] Fix | Delete
use Automattic\Jetpack\Assets;
[9] Fix | Delete
use Automattic\Jetpack\Redirect;
[10] Fix | Delete
use Automattic\Jetpack\Status\Host;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Place to properly deprecate Jetpack features.
[14] Fix | Delete
*/
[15] Fix | Delete
class Deprecate {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* The singleton instance.
[19] Fix | Delete
*
[20] Fix | Delete
* @var Deprecate
[21] Fix | Delete
*/
[22] Fix | Delete
private static $instance;
[23] Fix | Delete
[24] Fix | Delete
/**
[25] Fix | Delete
* An array of notices to display.
[26] Fix | Delete
*
[27] Fix | Delete
* @var array
[28] Fix | Delete
*/
[29] Fix | Delete
private $notices = array();
[30] Fix | Delete
[31] Fix | Delete
/**
[32] Fix | Delete
* Initialize the class.
[33] Fix | Delete
*/
[34] Fix | Delete
private function __construct() {
[35] Fix | Delete
// Modify the notices array to include the notices you want to display.
[36] Fix | Delete
// For more information, see /docs/deprecating-features.md.
[37] Fix | Delete
$this->notices = array(
[38] Fix | Delete
'my-admin' => array(
[39] Fix | Delete
'title' => __( "Retired feature: Jetpack's XYZ Feature", 'jetpack' ),
[40] Fix | Delete
'message' => __( 'This feature is being retired and will be removed effective November, 2024. Please use the Classic Theme Helper plugin instead.', 'jetpack' ),
[41] Fix | Delete
'link' => array(
[42] Fix | Delete
'label' => __( 'Learn more', 'jetpack' ),
[43] Fix | Delete
'url' => 'jetpack-support-xyz',
[44] Fix | Delete
),
[45] Fix | Delete
'show' => false, // 'show' is not required, but setting it to false will ensure that the notice will not be displayed.
[46] Fix | Delete
'hide_in_woa' => true, // 'hide_in_woa' is not required, but setting it to true will ensure that the notice will not be displayed in the WoA admin (none will display in Simple regardless).
[47] Fix | Delete
),
[48] Fix | Delete
);
[49] Fix | Delete
$this->set_notices();
[50] Fix | Delete
[51] Fix | Delete
if ( $this->has_notices() ) {
[52] Fix | Delete
// We only want the notice to appear on the main WP Admin dashboard, which hooking into load-index.php will allow.
[53] Fix | Delete
add_action(
[54] Fix | Delete
'load-index.php',
[55] Fix | Delete
function () {
[56] Fix | Delete
add_action( 'admin_notices', array( $this, 'render_admin_notices' ) );
[57] Fix | Delete
}
[58] Fix | Delete
);
[59] Fix | Delete
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
[60] Fix | Delete
add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) );
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
/**
[65] Fix | Delete
* Create/get the singleton instance.
[66] Fix | Delete
*
[67] Fix | Delete
* @return static
[68] Fix | Delete
*/
[69] Fix | Delete
public static function instance() {
[70] Fix | Delete
if ( null === static::$instance ) {
[71] Fix | Delete
static::$instance = new static();
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
return static::$instance;
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
/**
[78] Fix | Delete
* Enqueue the scripts.
[79] Fix | Delete
*
[80] Fix | Delete
* @return void
[81] Fix | Delete
*/
[82] Fix | Delete
public function enqueue_admin_scripts() {
[83] Fix | Delete
if ( ! $this->has_notices() ) {
[84] Fix | Delete
return;
[85] Fix | Delete
}
[86] Fix | Delete
[87] Fix | Delete
if ( ! wp_script_is( 'jetpack-deprecate', 'registered' ) ) {
[88] Fix | Delete
wp_register_script(
[89] Fix | Delete
'jetpack-deprecate',
[90] Fix | Delete
Assets::get_file_url_for_environment( '_inc/build/deprecate.min.js', '_inc/deprecate.js' ),
[91] Fix | Delete
array(),
[92] Fix | Delete
JETPACK__VERSION,
[93] Fix | Delete
true
[94] Fix | Delete
);
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
wp_enqueue_script( 'jetpack-deprecate' );
[98] Fix | Delete
wp_add_inline_script(
[99] Fix | Delete
'jetpack-deprecate',
[100] Fix | Delete
'window.noticeInfo = ' . wp_json_encode( $this->notices ) . ';',
[101] Fix | Delete
'before'
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
/**
[106] Fix | Delete
* Ensure the notices variable is properly formatted and includes the required suffix and show value.
[107] Fix | Delete
*
[108] Fix | Delete
* @return void
[109] Fix | Delete
*/
[110] Fix | Delete
private function set_notices() {
[111] Fix | Delete
$notices = array();
[112] Fix | Delete
$required_id_suffix = '-deprecate-feature';
[113] Fix | Delete
$host = new Host();
[114] Fix | Delete
[115] Fix | Delete
foreach ( $this->notices as $id => $notice ) {
[116] Fix | Delete
if ( $host->is_woa_site() && isset( $notice['hide_in_woa'] ) && true === $notice['hide_in_woa'] ) {
[117] Fix | Delete
continue;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if ( isset( $notice['show'] ) && false === $notice['show'] ) {
[121] Fix | Delete
continue;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( empty( $notice['title'] ) || empty( $notice['message'] ) || empty( $notice['link']['url'] ) ) {
[125] Fix | Delete
continue;
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
if ( empty( $notice['link']['label'] ) ) {
[129] Fix | Delete
$notice['link']['label'] = __( 'Learn more', 'jetpack' );
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
if ( strpos( $id, $required_id_suffix ) === false ) {
[133] Fix | Delete
$id .= $required_id_suffix;
[134] Fix | Delete
}
[135] Fix | Delete
[136] Fix | Delete
$notices[ $id ] = $notice;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
$this->notices = $notices;
[140] Fix | Delete
}
[141] Fix | Delete
[142] Fix | Delete
/**
[143] Fix | Delete
* Render deprecation notices for relevant features.
[144] Fix | Delete
*
[145] Fix | Delete
* @return void
[146] Fix | Delete
*/
[147] Fix | Delete
public function render_admin_notices() {
[148] Fix | Delete
[149] Fix | Delete
foreach ( $this->notices as $id => $notice ) {
[150] Fix | Delete
if ( $this->show_feature_notice( $id ) ) {
[151] Fix | Delete
$support_url = Redirect::get_url( $notice['link']['url'] );
[152] Fix | Delete
[153] Fix | Delete
$this->render_notice(
[154] Fix | Delete
$id,
[155] Fix | Delete
'<div class="jetpack-deprecation-notice-container">' .
[156] Fix | Delete
'<div class="jetpack-deprecation-notice-svg">' .
[157] Fix | Delete
'<svg class="jetpack-deprecation-notice-icon gridicon gridicons-info-outline needs-offset" height="20" width="20" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" color="#000000">' .
[158] Fix | Delete
'<g><path d="M13 9h-2V7h2v2zm0 2h-2v6h2v-6zm-1-7c-4.41 0-8 3.59-8 8s3.59 8 8 8 8-3.59 8-8-3.59-8-8-8m0-2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2z"></path></g>' .
[159] Fix | Delete
'</svg>' .
[160] Fix | Delete
'</div>' .
[161] Fix | Delete
'<div class="jetpack-deprecation-notice-text">' .
[162] Fix | Delete
'<p class="jetpack-deprection-notice-title">' . esc_html( $notice['title'] ) . '</p>' .
[163] Fix | Delete
'<p>' . esc_html( $notice['message'] ) . '</p>' .
[164] Fix | Delete
'<a href="' . $support_url . '" target="_blank" class="jetpack-deprecation-notice-link"> ' . esc_html( $notice['link']['label'] ) . '</a>' .
[165] Fix | Delete
'<svg class="gridicons-external" height="14" width="14" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 22 20">' .
[166] Fix | Delete
'<g><path d="M19 13v6c0 1.105-.895 2-2 2H5c-1.105 0-2-.895-2-2V7c0-1.105.895-2 2-2h6v2H5v12h12v-6h2zM13 3v2h4.586l-7.793 7.793 1.414 1.414L19 6.414V11h2V3h-8z"></path></g>' .
[167] Fix | Delete
'</svg>' .
[168] Fix | Delete
'</div>' .
[169] Fix | Delete
'</div>'
[170] Fix | Delete
);
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
/**
[176] Fix | Delete
* Add the deprecation notices to My Jetpack.
[177] Fix | Delete
*
[178] Fix | Delete
* @param array $slugs Already added bubbles.
[179] Fix | Delete
*
[180] Fix | Delete
* @return array
[181] Fix | Delete
*/
[182] Fix | Delete
public function add_my_jetpack_red_bubbles( $slugs ) {
[183] Fix | Delete
[184] Fix | Delete
foreach ( $this->notices as $id => $notice ) {
[185] Fix | Delete
if ( $this->show_feature_notice( $id ) ) {
[186] Fix | Delete
$slugs[ $id ] = array(
[187] Fix | Delete
'data' => array(
[188] Fix | Delete
'text' => $notice['message'],
[189] Fix | Delete
'title' => $notice['title'],
[190] Fix | Delete
'link' => array(
[191] Fix | Delete
'label' => esc_html( $notice['link']['label'] ),
[192] Fix | Delete
'url' => Redirect::get_url( $notice['link']['url'] ),
[193] Fix | Delete
),
[194] Fix | Delete
'id' => $id,
[195] Fix | Delete
),
[196] Fix | Delete
);
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
return $slugs;
[200] Fix | Delete
}
[201] Fix | Delete
[202] Fix | Delete
/**
[203] Fix | Delete
* Render the notice.
[204] Fix | Delete
*
[205] Fix | Delete
* @param string $id The notice ID.
[206] Fix | Delete
* @param string $text The notice text.
[207] Fix | Delete
*
[208] Fix | Delete
* @return void
[209] Fix | Delete
*/
[210] Fix | Delete
private function render_notice( $id, $text ) {
[211] Fix | Delete
printf(
[212] Fix | Delete
'<div id="%1$s" class="notice notice-warning is-dismissible jetpack-deprecate-dismissible" style="border-left-color: #000000;">%2$s</div>',
[213] Fix | Delete
esc_html( $id ),
[214] Fix | Delete
$text // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Output already escaped in render_admin_notices
[215] Fix | Delete
);
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
/**
[219] Fix | Delete
* Check if there are any notices to be displayed, so we wouldn't load unnecessary JS and run excessive hooks.
[220] Fix | Delete
*
[221] Fix | Delete
* @return bool
[222] Fix | Delete
*/
[223] Fix | Delete
private function has_notices() {
[224] Fix | Delete
foreach ( $this->notices as $id => $notice ) {
[225] Fix | Delete
if ( $this->show_feature_notice( $id ) ) {
[226] Fix | Delete
return true;
[227] Fix | Delete
}
[228] Fix | Delete
}
[229] Fix | Delete
return false;
[230] Fix | Delete
}
[231] Fix | Delete
[232] Fix | Delete
/**
[233] Fix | Delete
* Check if the feature notice should be shown, based on the existence of the cookie.
[234] Fix | Delete
*
[235] Fix | Delete
* @param string $id The notice ID.
[236] Fix | Delete
*
[237] Fix | Delete
* @return bool
[238] Fix | Delete
*/
[239] Fix | Delete
private function show_feature_notice( $id ) {
[240] Fix | Delete
return empty( $_COOKIE['jetpack_deprecate_dismissed'][ $id ] );
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function