From 8eac887f63f5e9bdb967f72591d087206e331d93 Mon Sep 17 00:00:00 2001 From: Sergey Mitroshin Date: Sun, 15 Jan 2023 20:18:17 -0500 Subject: [PATCH 1/2] Debug Helper: add cookie state faker. --- .../changelog/add-jetpack-debug-state | 4 + .../modules/class-cookie-state.php | 198 ++++++++++++++++++ .../modules/inc/css/cookie-state.css | 64 ++++++ .../modules/inc/js/cookie-state.js | 62 ++++++ projects/plugins/debug-helper/plugin.php | 5 + 5 files changed, 333 insertions(+) create mode 100644 projects/plugins/debug-helper/changelog/add-jetpack-debug-state create mode 100644 projects/plugins/debug-helper/modules/class-cookie-state.php create mode 100644 projects/plugins/debug-helper/modules/inc/css/cookie-state.css create mode 100644 projects/plugins/debug-helper/modules/inc/js/cookie-state.js diff --git a/projects/plugins/debug-helper/changelog/add-jetpack-debug-state b/projects/plugins/debug-helper/changelog/add-jetpack-debug-state new file mode 100644 index 000000000000..95caaf0a9b91 --- /dev/null +++ b/projects/plugins/debug-helper/changelog/add-jetpack-debug-state @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add "Cookie State Faker" tool. diff --git a/projects/plugins/debug-helper/modules/class-cookie-state.php b/projects/plugins/debug-helper/modules/class-cookie-state.php new file mode 100644 index 000000000000..241bdd6a315e --- /dev/null +++ b/projects/plugins/debug-helper/modules/class-cookie-state.php @@ -0,0 +1,198 @@ + WP_REST_Server::EDITABLE, + 'callback' => array( $this, 'save' ), + 'permission_callback' => '__return_true', + 'args' => array( + 'key' => array( + 'description' => 'The state key.', + 'type' => 'string', + 'required' => true, + ), + 'value' => array( + 'description' => 'The state value.', + 'type' => 'string', + 'required' => true, + ), + ), + ) + ); + } + + /** + * Add submenu item. + */ + public function register_submenu_page() { + add_submenu_page( + 'jetpack-debug-tools', + 'Cookie State Faker', + 'Cookie State Faker', + 'manage_options', + 'cookie-state', + array( $this, 'render_ui' ), + 99 + ); + } + + /** + * Enqueue scripts! + * + * @param string $hook Page hook. + */ + public function enqueue_scripts( $hook ) { + if ( strpos( $hook, 'jetpack-debug_page_cookie-state' ) === 0 ) { + wp_enqueue_style( 'cookie_state_style', plugin_dir_url( __FILE__ ) . 'inc/css/cookie-state.css', array(), JETPACK_DEBUG_HELPER_VERSION ); + wp_enqueue_script( 'cookie_state_script', plugin_dir_url( __FILE__ ) . 'inc/js/cookie-state.js', array( 'wp-api' ), JETPACK_DEBUG_HELPER_VERSION, true ); + + add_filter( + 'script_loader_tag', + function ( $tag, $handle ) { + if ( 'cookie_state_script' === $handle ) { + $tag = str_replace( '