class-deprecate.php
2 years ago
class-jetpack-crm-data.php
2 years ago
class-jetpack-modules-overrides.php
3 years ago
class-tracking.php
2 years ago
class-deprecate.php
167 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Place to properly deprecate Jetpack features. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Plugin; |
| 9 | |
| 10 | use Automattic\Jetpack\Assets; |
| 11 | use Automattic\Jetpack\Modules; |
| 12 | use Automattic\Jetpack\Redirect; |
| 13 | use Automattic\Jetpack\Status\Host; |
| 14 | |
| 15 | /** |
| 16 | * Place to properly deprecate Jetpack features. |
| 17 | */ |
| 18 | class Deprecate { |
| 19 | |
| 20 | /** |
| 21 | * The singleton instance. |
| 22 | * |
| 23 | * @var Deprecate |
| 24 | */ |
| 25 | private static $instance; |
| 26 | |
| 27 | /** |
| 28 | * Initialize the class. |
| 29 | */ |
| 30 | private function __construct() { |
| 31 | add_action( 'admin_notices', array( $this, 'render_admin_notices' ) ); |
| 32 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 33 | add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) ); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * Create/get the singleton instance. |
| 38 | * |
| 39 | * @return static |
| 40 | */ |
| 41 | public static function instance() { |
| 42 | if ( null === static::$instance ) { |
| 43 | static::$instance = new static(); |
| 44 | } |
| 45 | |
| 46 | return static::$instance; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Enqueue the scripts. |
| 51 | * |
| 52 | * @return void |
| 53 | */ |
| 54 | public function enqueue_admin_scripts() { |
| 55 | if ( ! $this->has_notices() ) { |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | if ( ! wp_script_is( 'jetpack-deprecate', 'registered' ) ) { |
| 60 | wp_register_script( |
| 61 | 'jetpack-deprecate', |
| 62 | Assets::get_file_url_for_environment( '_inc/build/deprecate.min.js', '_inc/deprecate.js' ), |
| 63 | array(), |
| 64 | JETPACK__VERSION, |
| 65 | true |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | wp_enqueue_script( 'jetpack-deprecate' ); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Render Google Analytics deprecation notice. |
| 74 | * |
| 75 | * @return void |
| 76 | */ |
| 77 | public function render_admin_notices() { |
| 78 | if ( $this->show_ga_notice() ) { |
| 79 | $support_url = Redirect::get_url( 'jetpack-support-google-analytics' ); |
| 80 | |
| 81 | $this->render_notice( |
| 82 | 'jetpack-ga-admin-notice', |
| 83 | esc_html__( "Jetpack's Google Analytics feature will be removed on August 6, 2024.", 'jetpack' ) |
| 84 | . ' <a href="' . $support_url . '" target="_blank">' . esc_html__( 'Read this document for details and how to keep tracking visits with Google Analytics', 'jetpack' ) . '</a>.' |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Add the deprecation notices to My Jetpack. |
| 91 | * |
| 92 | * @param array $slugs Already added bubbles. |
| 93 | * |
| 94 | * @return mixed |
| 95 | */ |
| 96 | public function add_my_jetpack_red_bubbles( $slugs ) { |
| 97 | if ( $this->show_ga_notice() ) { |
| 98 | $slugs['jetpack-google-analytics-deprecate-feature'] = array( |
| 99 | 'data' => array( |
| 100 | 'text' => __( "Jetpack's Google Analytics feature will be removed on August 6, 2024. Read the documentation for details and how to keep tracking visits with Google Analytics.", 'jetpack' ), |
| 101 | 'link' => array( |
| 102 | 'label' => esc_html__( 'See documentation', 'jetpack' ), |
| 103 | 'url' => Redirect::get_url( 'jetpack-support-google-analytics' ), |
| 104 | ), |
| 105 | ), |
| 106 | ); |
| 107 | } |
| 108 | |
| 109 | return $slugs; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Render the notice. |
| 114 | * |
| 115 | * @param string $id The notice ID. |
| 116 | * @param string $text The notice text. |
| 117 | * @param array $params Additional notice params. |
| 118 | * |
| 119 | * @return void |
| 120 | */ |
| 121 | private function render_notice( $id, $text, $params = array() ) { |
| 122 | if ( ! empty( $_COOKIE['jetpack_deprecate_dismissed'][ $id ] ) ) { |
| 123 | return; |
| 124 | } |
| 125 | |
| 126 | $params['id'] = $id; |
| 127 | |
| 128 | if ( empty( $params['type'] ) ) { |
| 129 | $params['type'] = 'warning'; |
| 130 | } |
| 131 | |
| 132 | if ( empty( $params['dismissible'] ) ) { |
| 133 | $params['dismissible'] = true; |
| 134 | } |
| 135 | |
| 136 | if ( $params['dismissible'] ) { |
| 137 | if ( empty( $params['additional_classes'] ) ) { |
| 138 | $params['additional_classes'] = array(); |
| 139 | } |
| 140 | |
| 141 | $params['additional_classes'][] = 'jetpack-deprecate-dismissible'; |
| 142 | } |
| 143 | |
| 144 | wp_admin_notice( $text, $params ); |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Check if there are any notices to be displayed, so we wouldn't load unnecessary JS. |
| 149 | * |
| 150 | * @return bool |
| 151 | */ |
| 152 | private function has_notices() { |
| 153 | return $this->show_ga_notice(); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Check if Google Analytics notice should show up. |
| 158 | * |
| 159 | * @return bool |
| 160 | */ |
| 161 | private function show_ga_notice() { |
| 162 | return ( new Modules() )->is_active( 'google-analytics', false ) |
| 163 | && ! is_plugin_active( 'jetpack-legacy-google-analytics/jetpack-legacy-google-analytics.php' ) |
| 164 | && ! ( new Host() )->is_woa_site(); |
| 165 | } |
| 166 | } |
| 167 |