$param_val ) { printf( '', \esc_attr( $param_key ), \esc_attr( $param_val ) ); } ?>

←

prepare_items(); $rules = Rest_Api_Helper::get_endpoint_rules(); $disabled_count = 0; $obfuscated_count = 0; foreach ( $rules as $rule ) { if ( ! empty( $rule['disabled'] ) ) { ++$disabled_count; } if ( ! empty( $rule['obfuscate'] ) ) { ++$obfuscated_count; } } ?>


search_box( \esc_html__( 'Search Endpoints', '0-day-analytics' ), Rest_Api_List::SEARCH_INPUT ); $table->display(); ?>
Rest_Api_List::REST_API_MENU_SLUG, 'action' => 'edit_route', 'route_hash' => $route_hash, '_wpnonce' => \wp_create_nonce( 'bulk-rest-api-endpoints' ), 'updated' => 'true', ) ), \admin_url( 'admin.php' ) ) ); exit; } /** * Toggle an endpoint enabled/disabled. * * @return void * * @since 5.0.0 */ public static function toggle_endpoint(): void { if ( ! \current_user_can( 'manage_options' ) ) { \wp_die( \esc_html__( 'You do not have permission to manage REST API endpoints.', '0-day-analytics' ) ); } if ( ! isset( $_GET['_wpnonce'] ) || ! \wp_verify_nonce( \sanitize_text_field( \wp_unslash( $_GET['_wpnonce'] ) ), Rest_Api_List::NONCE_NAME ) ) { \wp_die( \esc_html__( 'Security check failed.', '0-day-analytics' ) ); } $route_hash = isset( $_GET['route_hash'] ) ? \sanitize_text_field( \wp_unslash( $_GET['route_hash'] ) ) : ''; $toggle = isset( $_GET['toggle'] ) ? \sanitize_key( \wp_unslash( $_GET['toggle'] ) ) : ''; if ( empty( $route_hash ) || ! in_array( $toggle, array( 'enable', 'disable' ), true ) ) { \wp_die( \esc_html__( 'Invalid request.', '0-day-analytics' ) ); } $all_endpoints = Rest_Api_Helper::get_all_endpoints(); $route = null; foreach ( $all_endpoints as $ep ) { if ( $ep['route_hash'] === $route_hash ) { $route = $ep['route']; break; } } if ( ! $route ) { \wp_die( \esc_html__( 'Endpoint not found.', '0-day-analytics' ) ); } $rules = Rest_Api_Helper::get_endpoint_rules(); if ( 'disable' === $toggle ) { if ( ! isset( $rules[ $route ] ) ) { $rules[ $route ] = array(); } $rules[ $route ]['disabled'] = true; } elseif ( 'enable' === $toggle ) { if ( isset( $rules[ $route ]['disabled'] ) ) { unset( $rules[ $route ]['disabled'] ); } if ( empty( $rules[ $route ] ) ) { unset( $rules[ $route ] ); } } Rest_Api_Helper::save_endpoint_rules( $rules ); // Preserve list filters in redirect. $redirect_params = Rest_Api_List::get_preserved_list_params(); $redirect_params['page'] = Rest_Api_List::REST_API_MENU_SLUG; $redirect_params['updated'] = 'true'; \wp_safe_redirect( \add_query_arg( $redirect_params, \admin_url( 'admin.php' ) ) ); exit; } /** * Get the color for an HTTP method badge. * * @param string $method HTTP method. * * @return string Hex color code. * * @since 5.0.0 */ private static function get_method_color( string $method ): string { $colors = array( 'GET' => '#00a32a', 'POST' => '#2271b1', 'PUT' => '#dba617', 'PATCH' => '#dba617', 'DELETE' => '#d63638', 'OPTIONS' => '#8c8f94', 'HEAD' => '#8c8f94', ); return $colors[ strtoupper( $method ) ] ?? '#8c8f94'; } } }