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..78d061e713da --- /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( '