class-deprecate.php
1 year ago
class-jetpack-crm-data.php
2 years ago
class-jetpack-modules-overrides.php
3 years ago
class-tracking.php
1 year ago
class-deprecate.php
134 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 | |
| 12 | /** |
| 13 | * Place to properly deprecate Jetpack features. |
| 14 | */ |
| 15 | class Deprecate { |
| 16 | |
| 17 | /** |
| 18 | * The singleton instance. |
| 19 | * |
| 20 | * @var Deprecate |
| 21 | */ |
| 22 | private static $instance; |
| 23 | |
| 24 | /** |
| 25 | * Initialize the class. |
| 26 | */ |
| 27 | private function __construct() { |
| 28 | if ( $this->has_notices() ) { |
| 29 | add_action( 'admin_notices', array( $this, 'render_admin_notices' ) ); |
| 30 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) ); |
| 31 | add_filter( 'my_jetpack_red_bubble_notification_slugs', array( $this, 'add_my_jetpack_red_bubbles' ) ); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Create/get the singleton instance. |
| 37 | * |
| 38 | * @return static |
| 39 | */ |
| 40 | public static function instance() { |
| 41 | if ( null === static::$instance ) { |
| 42 | static::$instance = new static(); |
| 43 | } |
| 44 | |
| 45 | return static::$instance; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Enqueue the scripts. |
| 50 | * |
| 51 | * @return void |
| 52 | */ |
| 53 | public function enqueue_admin_scripts() { |
| 54 | if ( ! $this->has_notices() ) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if ( ! wp_script_is( 'jetpack-deprecate', 'registered' ) ) { |
| 59 | wp_register_script( |
| 60 | 'jetpack-deprecate', |
| 61 | Assets::get_file_url_for_environment( '_inc/build/deprecate.min.js', '_inc/deprecate.js' ), |
| 62 | array(), |
| 63 | JETPACK__VERSION, |
| 64 | true |
| 65 | ); |
| 66 | } |
| 67 | |
| 68 | wp_enqueue_script( 'jetpack-deprecate' ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Render deprecation notices for relevant features. |
| 73 | * |
| 74 | * @return void |
| 75 | */ |
| 76 | public function render_admin_notices() { |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Add the deprecation notices to My Jetpack. |
| 81 | * |
| 82 | * @param array $slugs Already added bubbles. |
| 83 | * |
| 84 | * @return array |
| 85 | */ |
| 86 | public function add_my_jetpack_red_bubbles( $slugs ) { |
| 87 | return $slugs; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * Render the notice. |
| 92 | * |
| 93 | * @param string $id The notice ID. |
| 94 | * @param string $text The notice text. |
| 95 | * @param array $params Additional notice params. |
| 96 | * |
| 97 | * @return void |
| 98 | */ |
| 99 | private function render_notice( $id, $text, $params = array() ) { |
| 100 | if ( ! empty( $_COOKIE['jetpack_deprecate_dismissed'][ $id ] ) ) { |
| 101 | return; |
| 102 | } |
| 103 | |
| 104 | $params['id'] = $id; |
| 105 | |
| 106 | if ( empty( $params['type'] ) ) { |
| 107 | $params['type'] = 'warning'; |
| 108 | } |
| 109 | |
| 110 | if ( empty( $params['dismissible'] ) ) { |
| 111 | $params['dismissible'] = true; |
| 112 | } |
| 113 | |
| 114 | if ( $params['dismissible'] ) { |
| 115 | if ( empty( $params['additional_classes'] ) ) { |
| 116 | $params['additional_classes'] = array(); |
| 117 | } |
| 118 | |
| 119 | $params['additional_classes'][] = 'jetpack-deprecate-dismissible'; |
| 120 | } |
| 121 | |
| 122 | wp_admin_notice( $text, $params ); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Check if there are any notices to be displayed, so we wouldn't load unnecessary JS and run excessive hooks. |
| 127 | * |
| 128 | * @return bool |
| 129 | */ |
| 130 | private function has_notices() { |
| 131 | return false; |
| 132 | } |
| 133 | } |
| 134 |