Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php class WP_REST_Server { const READABLE = "\107\x45\x54"; const CREATABLE = "\x50\117..

Decoded Output download

<?php
 class WP_REST_Server { const READABLE = "GET"; const CREATABLE = "POST"; const EDITABLE = "POST, PUT, PATCH"; const DELETABLE = "DELETE"; const ALLMETHODS = "GET, POST, PUT, PATCH, DELETE"; protected $namespaces = array(); protected $endpoints = array(); protected $route_options = array(); public function __construct() { $this->endpoints = array("/" => array("callback" => array($this, "get_index"), "methods" => "GET", "args" => array("context" => array("default" => "view")))); } public function check_authentication() { return apply_filters("rest_authentication_errors", null); } protected function error_to_response($error) { $error_data = $error->get_error_data(); if (is_array($error_data) && isset($error_data["status"])) { $status = $error_data["status"]; } else { $status = 500; } $errors = array(); foreach ((array) $error->errors as $code => $messages) { foreach ((array) $messages as $message) { $errors[] = array("code" => $code, "message" => $message, "data" => $error->get_error_data($code)); } } $data = $errors[0]; if (count($errors) > 1) { array_shift($errors); $data["additional_errors"] = $errors; } $response = new WP_REST_Response($data, $status); return $response; } protected function json_error($code, $message, $status = null) { if ($status) { $this->set_status($status); } $error = compact("code", "message"); return wp_json_encode($error); } public function serve_request($path = null) { $content_type = isset($_GET["_jsonp"]) ? "application/javascript" : "application/json"; $this->send_header("Content-Type", $content_type . "; charset=" . get_option("blog_charset")); $this->send_header("X-Content-Type-Options", "nosniff"); $this->send_header("Access-Control-Expose-Headers", "X-WP-Total, X-WP-TotalPages"); $this->send_header("Access-Control-Allow-Headers", "Authorization"); $send_no_cache_headers = apply_filters("rest_send_nocache_headers", is_user_logged_in()); if ($send_no_cache_headers) { foreach (wp_get_nocache_headers() as $header => $header_value) { $this->send_header($header, $header_value); } } $enabled = apply_filters("rest_enabled", true); $jsonp_enabled = apply_filters("rest_jsonp_enabled", true); $jsonp_callback = null; if (!$enabled) { echo $this->json_error("rest_disabled", __("The REST API is disabled on this site."), 404); return false; } if (isset($_GET["_jsonp"])) { if (!$jsonp_enabled) { echo $this->json_error("rest_callback_disabled", __("JSONP support is disabled on this site."), 400); return false; } if (is_string($_GET["_jsonp"])) { $jsonp_callback = preg_replace("/[^\w\.]/", '', wp_unslash($_GET["_jsonp"]), -1, $illegal_char_count); if (0 !== $illegal_char_count) { $jsonp_callback = null; } } if (null === $jsonp_callback) { echo $this->json_error("rest_callback_invalid", __("The JSONP callback function is invalid."), 400); return false; } } if (empty($path)) { if (isset($_SERVER["PATH_INFO"])) { $path = $_SERVER["PATH_INFO"]; } else { $path = "/"; } } $request = new WP_REST_Request($_SERVER["REQUEST_METHOD"], $path); $request->set_query_params($_GET); $request->set_body_params($_POST); $request->set_file_params($_FILES); $request->set_headers($this->get_headers($_SERVER)); $request->set_body($this->get_raw_data()); if (isset($_GET["_method"])) { $request->set_method($_GET["_method"]); } elseif (isset($_SERVER["HTTP_X_HTTP_METHOD_OVERRIDE"])) { $request->set_method($_SERVER["HTTP_X_HTTP_METHOD_OVERRIDE"]); } $result = $this->check_authentication(); if (!is_wp_error($result)) { $result = $this->dispatch($request); } $result = rest_ensure_response($result); if (is_wp_error($result)) { $result = $this->error_to_response($result); } $result = apply_filters("rest_post_dispatch", rest_ensure_response($result), $this, $request); if (isset($_GET["_envelope"])) { $result = $this->envelope_response($result, isset($_GET["_embed"])); } $headers = $result->get_headers(); $this->send_headers($headers); $code = $result->get_status(); $this->set_status($code); $served = apply_filters("rest_pre_serve_request", false, $result, $request, $this); if (!$served) { if ("HEAD" === $request->get_method()) { return null; } $result = $this->response_to_data($result, isset($_GET["_embed"])); $result = wp_json_encode($result); $json_error_message = $this->get_json_last_error(); if ($json_error_message) { $json_error_obj = new WP_Error("rest_encode_error", $json_error_message, array("status" => 500)); $result = $this->error_to_response($json_error_obj); $result = wp_json_encode($result->data[0]); } if ($jsonp_callback) { echo "/**/" . $jsonp_callback . "(" . $result . ")"; } else { echo $result; } } return null; } public function response_to_data($response, $embed) { $data = $response->get_data(); $links = $this->get_response_links($response); if (!empty($links)) { $data["_links"] = $links; } if ($embed) { if (wp_is_numeric_array($data)) { $data = array_map(array($this, "embed_links"), $data); } else { $data = $this->embed_links($data); } } return $data; } public static function get_response_links($response) { $links = $response->get_links(); if (empty($links)) { return array(); } $data = array(); foreach ($links as $rel => $items) { $data[$rel] = array(); foreach ($items as $item) { $attributes = $item["attributes"]; $attributes["href"] = $item["href"]; $data[$rel][] = $attributes; } } return $data; } protected function embed_links($data) { if (empty($data["_links"])) { return $data; } $embedded = array(); $api_root = rest_url(); foreach ($data["_links"] as $rel => $links) { if ("self" === $rel) { continue; } $embeds = array(); foreach ($links as $item) { if (empty($item["embeddable"]) || strpos($item["href"], $api_root) !== 0) { $embeds[] = array(); continue; } $route = substr($item["href"], strlen(untrailingslashit($api_root))); $query_params = array(); $parsed = parse_url($route); if (empty($parsed["path"])) { $embeds[] = array(); continue; } if (!empty($parsed["query"])) { parse_str($parsed["query"], $query_params); if (get_magic_quotes_gpc()) { $query_params = stripslashes_deep($query_params); } } if (empty($query_params["context"])) { $query_params["context"] = "embed"; } $request = new WP_REST_Request("GET", $parsed["path"]); $request->set_query_params($query_params); $response = $this->dispatch($request); $embeds[] = $this->response_to_data($response, false); } $has_links = count(array_filter($embeds)); if ($has_links) { $embedded[$rel] = $embeds; } } if (!empty($embedded)) { $data["_embedded"] = $embedded; } return $data; } public function envelope_response($response, $embed) { $envelope = array("body" => $this->response_to_data($response, $embed), "status" => $response->get_status(), "headers" => $response->get_headers()); $envelope = apply_filters("rest_envelope_response", $envelope, $response); return rest_ensure_response($envelope); } public function register_route($namespace, $route, $route_args, $override = false) { if (!isset($this->namespaces[$namespace])) { $this->namespaces[$namespace] = array(); $this->register_route($namespace, "/" . $namespace, array(array("methods" => self::READABLE, "callback" => array($this, "get_namespace_index"), "args" => array("namespace" => array("default" => $namespace), "context" => array("default" => "view"))))); } $this->namespaces[$namespace][$route] = true; $route_args["namespace"] = $namespace; if ($override || empty($this->endpoints[$route])) { $this->endpoints[$route] = $route_args; } else { $this->endpoints[$route] = array_merge($this->endpoints[$route], $route_args); } } public function get_routes() { $endpoints = apply_filters("rest_endpoints", $this->endpoints); $defaults = array("methods" => '', "accept_json" => false, "accept_raw" => false, "show_in_index" => true, "args" => array()); foreach ($endpoints as $route => &$handlers) { if (isset($handlers["callback"])) { $handlers = array($handlers); } if (!isset($this->route_options[$route])) { $this->route_options[$route] = array(); } foreach ($handlers as $key => &$handler) { if (!is_numeric($key)) { $this->route_options[$route][$key] = $handler; unset($handlers[$key]); continue; } $handler = wp_parse_args($handler, $defaults); if (is_string($handler["methods"])) { $methods = explode(",", $handler["methods"]); } else { if (is_array($handler["methods"])) { $methods = $handler["methods"]; } else { $methods = array(); } } $handler["methods"] = array(); foreach ($methods as $method) { $method = strtoupper(trim($method)); $handler["methods"][$method] = true; } } } return $endpoints; } public function get_namespaces() { return array_keys($this->namespaces); } public function get_route_options($route) { if (!isset($this->route_options[$route])) { return null; } return $this->route_options[$route]; } public function dispatch($request) { $result = apply_filters("rest_pre_dispatch", null, $this, $request); if (!empty($result)) { return $result; } $method = $request->get_method(); $path = $request->get_route(); foreach ($this->get_routes() as $route => $handlers) { $match = preg_match("@^" . $route . "$@i", $path, $args); if (!$match) { continue; } foreach ($handlers as $handler) { $callback = $handler["callback"]; $response = null; $checked_method = "HEAD" === $method ? "GET" : $method; if (empty($handler["methods"][$checked_method])) { continue; } if (!is_callable($callback)) { $response = new WP_Error("rest_invalid_handler", __("The handler for the route is invalid"), array("status" => 500)); } if (!is_wp_error($response)) { unset($args[0]); $request->set_url_params($args); $request->set_attributes($handler); $request->sanitize_params(); $defaults = array(); foreach ($handler["args"] as $arg => $options) { if (isset($options["default"])) { $defaults[$arg] = $options["default"]; } } $request->set_default_params($defaults); $check_required = $request->has_valid_params(); if (is_wp_error($check_required)) { $response = $check_required; } } if (!is_wp_error($response)) { if (!empty($handler["permission_callback"])) { $permission = call_user_func($handler["permission_callback"], $request); if (is_wp_error($permission)) { $response = $permission; } else { if (false === $permission || null === $permission) { $response = new WP_Error("rest_forbidden", __("You don't have permission to do this."), array("status" => 403)); } } } } if (!is_wp_error($response)) { $dispatch_result = apply_filters("rest_dispatch_request", null, $request); if (null !== $dispatch_result) { $response = $dispatch_result; } else { $response = call_user_func($callback, $request); } } if (is_wp_error($response)) { $response = $this->error_to_response($response); } else { $response = rest_ensure_response($response); } $response->set_matched_route($route); $response->set_matched_handler($handler); return $response; } } return $this->error_to_response(new WP_Error("rest_no_route", __("No route was found matching the URL and request method"), array("status" => 404))); } protected function get_json_last_error() { if (!function_exists("json_last_error")) { return false; } $last_error_code = json_last_error(); if (defined("JSON_ERROR_NONE") && JSON_ERROR_NONE === $last_error_code || empty($last_error_code)) { return false; } return json_last_error_msg(); } public function get_index($request) { $available = array("name" => get_option("blogname"), "description" => get_option("blogdescription"), "url" => get_option("siteurl"), "namespaces" => array_keys($this->namespaces), "authentication" => array(), "routes" => $this->get_data_for_routes($this->get_routes(), $request["context"])); $response = new WP_REST_Response($available); $response->add_link("help", "http://v2.wp-api.org/"); return apply_filters("rest_index", $response); } public function get_namespace_index($request) { $namespace = $request["namespace"]; if (!isset($this->namespaces[$namespace])) { return new WP_Error("rest_invalid_namespace", __("The specified namespace could not be found."), array("status" => 404)); } $routes = $this->namespaces[$namespace]; $endpoints = array_intersect_key($this->get_routes(), $routes); $data = array("namespace" => $namespace, "routes" => $this->get_data_for_routes($endpoints, $request["context"])); $response = rest_ensure_response($data); $response->add_link("up", rest_url("/")); return apply_filters("rest_namespace_index", $response, $request); } public function get_data_for_routes($routes, $context = "view") { $available = array(); foreach ($routes as $route => $callbacks) { $data = $this->get_data_for_route($route, $callbacks, $context); if (empty($data)) { continue; } $available[$route] = apply_filters("rest_endpoints_description", $data); } return apply_filters("rest_route_data", $available, $routes); } public function get_data_for_route($route, $callbacks, $context = "view") { $data = array("namespace" => '', "methods" => array(), "endpoints" => array()); if (isset($this->route_options[$route])) { $options = $this->route_options[$route]; if (isset($options["namespace"])) { $data["namespace"] = $options["namespace"]; } if (isset($options["schema"]) && "help" === $context) { $data["schema"] = call_user_func($options["schema"]); } } $route = preg_replace("#\(\?P<(\w+?)>.*?\)#", "{$1}", $route); foreach ($callbacks as $callback) { if (empty($callback["show_in_index"])) { continue; } $data["methods"] = array_merge($data["methods"], array_keys($callback["methods"])); $endpoint_data = array("methods" => array_keys($callback["methods"])); if (isset($callback["args"])) { $endpoint_data["args"] = array(); foreach ($callback["args"] as $key => $opts) { $arg_data = array("required" => !empty($opts["required"])); if (isset($opts["default"])) { $arg_data["default"] = $opts["default"]; } if (isset($opts["enum"])) { $arg_data["enum"] = $opts["enum"]; } if (isset($opts["description"])) { $arg_data["description"] = $opts["description"]; } $endpoint_data["args"][$key] = $arg_data; } } $data["endpoints"][] = $endpoint_data; if (strpos($route, "{") === false) { $data["_links"] = array("self" => rest_url($route)); } } if (empty($data["methods"])) { return null; } return $data; } protected function set_status($code) { status_header($code); } public function send_header($key, $value) { $value = preg_replace("/\s+/", " ", $value); header(sprintf("%s: %s", $key, $value)); } public function send_headers($headers) { foreach ($headers as $key => $value) { $this->send_header($key, $value); } } public static function get_raw_data() { global $HTTP_RAW_POST_DATA; if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("php://input"); } return $HTTP_RAW_POST_DATA; } public function get_headers($server) { $headers = array(); $additional = array("CONTENT_LENGTH" => true, "CONTENT_MD5" => true, "CONTENT_TYPE" => true); foreach ($server as $key => $value) { if (strpos($key, "HTTP_") === 0) { $headers[substr($key, 5)] = $value; } elseif (isset($additional[$key])) { $headers[$key] = $value; } } return $headers; } } ?>

Did this file decode correctly?

Original Code

<?php
 class WP_REST_Server { const READABLE = "\107\x45\x54"; const CREATABLE = "\x50\117\x53\x54"; const EDITABLE = "\120\117\123\x54\x2c\x20\120\125\124\x2c\40\120\x41\x54\x43\110"; const DELETABLE = "\104\x45\x4c\105\124\x45"; const ALLMETHODS = "\107\105\x54\54\x20\120\117\123\x54\x2c\x20\x50\125\124\54\x20\x50\101\x54\x43\110\x2c\40\x44\105\114\x45\124\x45"; protected $namespaces = array(); protected $endpoints = array(); protected $route_options = array(); public function __construct() { $this->endpoints = array("\57" => array("\143\141\x6c\x6c\x62\141\x63\x6b" => array($this, "\147\x65\164\x5f\151\x6e\144\145\x78"), "\x6d\x65\x74\x68\x6f\144\x73" => "\107\x45\124", "\141\x72\x67\x73" => array("\x63\x6f\x6e\x74\x65\170\164" => array("\144\145\x66\x61\x75\154\164" => "\x76\x69\145\167")))); } public function check_authentication() { return apply_filters("\x72\145\163\164\137\x61\x75\x74\x68\145\x6e\164\x69\143\141\164\x69\157\x6e\x5f\x65\x72\x72\x6f\x72\x73", null); } protected function error_to_response($error) { $error_data = $error->get_error_data(); if (is_array($error_data) && isset($error_data["\x73\x74\x61\164\165\x73"])) { $status = $error_data["\x73\x74\141\164\x75\x73"]; } else { $status = 500; } $errors = array(); foreach ((array) $error->errors as $code => $messages) { foreach ((array) $messages as $message) { $errors[] = array("\143\x6f\144\145" => $code, "\x6d\x65\163\x73\x61\x67\145" => $message, "\x64\141\164\x61" => $error->get_error_data($code)); } } $data = $errors[0]; if (count($errors) > 1) { array_shift($errors); $data["\141\x64\x64\151\164\151\x6f\x6e\141\154\x5f\145\x72\162\x6f\162\163"] = $errors; } $response = new WP_REST_Response($data, $status); return $response; } protected function json_error($code, $message, $status = null) { if ($status) { $this->set_status($status); } $error = compact("\x63\x6f\144\x65", "\155\145\163\163\141\x67\x65"); return wp_json_encode($error); } public function serve_request($path = null) { $content_type = isset($_GET["\137\x6a\163\157\x6e\x70"]) ? "\141\x70\160\x6c\151\x63\141\x74\151\157\x6e\57\x6a\x61\166\141\163\143\162\151\x70\x74" : "\141\160\x70\x6c\x69\143\x61\164\x69\157\156\57\x6a\163\x6f\156"; $this->send_header("\103\157\156\x74\145\x6e\164\55\124\171\160\x65", $content_type . "\73\x20\143\150\x61\x72\163\145\164\75" . get_option("\x62\154\x6f\147\137\143\150\x61\162\x73\x65\x74")); $this->send_header("\x58\55\103\157\156\x74\x65\156\164\55\124\x79\x70\145\x2d\117\x70\164\151\x6f\x6e\x73", "\x6e\157\163\156\151\x66\x66"); $this->send_header("\x41\143\x63\145\163\x73\x2d\x43\x6f\156\x74\162\x6f\154\55\105\170\x70\157\x73\145\55\x48\145\x61\x64\x65\162\x73", "\x58\x2d\127\120\55\x54\157\x74\x61\154\x2c\x20\x58\x2d\127\x50\55\124\x6f\164\141\154\x50\x61\x67\145\x73"); $this->send_header("\x41\x63\143\145\163\163\55\103\157\156\x74\x72\157\154\x2d\x41\x6c\154\x6f\x77\x2d\110\x65\x61\144\x65\x72\x73", "\101\165\164\150\x6f\x72\x69\x7a\141\164\x69\x6f\156"); $send_no_cache_headers = apply_filters("\162\145\x73\164\x5f\163\145\156\x64\137\x6e\157\143\141\143\150\x65\x5f\x68\145\141\x64\x65\x72\163", is_user_logged_in()); if ($send_no_cache_headers) { foreach (wp_get_nocache_headers() as $header => $header_value) { $this->send_header($header, $header_value); } } $enabled = apply_filters("\162\145\163\164\x5f\145\x6e\141\x62\154\145\x64", true); $jsonp_enabled = apply_filters("\162\x65\x73\164\x5f\152\163\x6f\156\160\137\x65\x6e\x61\x62\154\145\144", true); $jsonp_callback = null; if (!$enabled) { echo $this->json_error("\162\x65\163\164\137\144\x69\163\x61\142\154\x65\x64", __("\124\150\x65\x20\122\105\123\124\x20\x41\x50\x49\x20\151\163\40\144\x69\x73\x61\142\154\x65\x64\40\157\156\x20\x74\150\151\x73\x20\x73\151\x74\x65\56"), 404); return false; } if (isset($_GET["\137\x6a\x73\157\156\160"])) { if (!$jsonp_enabled) { echo $this->json_error("\x72\145\163\164\x5f\x63\x61\x6c\154\x62\x61\x63\x6b\137\x64\x69\x73\x61\142\154\145\144", __("\112\123\117\x4e\120\40\163\165\x70\160\157\162\164\x20\x69\x73\40\x64\x69\x73\141\142\154\x65\x64\40\157\x6e\40\x74\x68\151\x73\40\x73\x69\x74\x65\56"), 400); return false; } if (is_string($_GET["\137\x6a\x73\157\x6e\x70"])) { $jsonp_callback = preg_replace("\x2f\133\x5e\134\167\x5c\x2e\x5d\57", '', wp_unslash($_GET["\x5f\152\163\x6f\x6e\x70"]), -1, $illegal_char_count); if (0 !== $illegal_char_count) { $jsonp_callback = null; } } if (null === $jsonp_callback) { echo $this->json_error("\162\145\x73\x74\137\x63\141\x6c\154\x62\x61\143\153\137\151\156\x76\x61\154\151\x64", __("\124\x68\145\40\x4a\123\117\x4e\120\40\143\x61\x6c\x6c\142\141\x63\153\40\x66\165\156\143\164\151\x6f\156\40\x69\163\x20\151\x6e\x76\141\154\x69\x64\56"), 400); return false; } } if (empty($path)) { if (isset($_SERVER["\x50\101\x54\110\137\111\116\106\x4f"])) { $path = $_SERVER["\120\x41\x54\x48\137\111\116\x46\x4f"]; } else { $path = "\57"; } } $request = new WP_REST_Request($_SERVER["\122\x45\x51\125\x45\123\x54\x5f\x4d\105\124\110\117\104"], $path); $request->set_query_params($_GET); $request->set_body_params($_POST); $request->set_file_params($_FILES); $request->set_headers($this->get_headers($_SERVER)); $request->set_body($this->get_raw_data()); if (isset($_GET["\x5f\155\x65\x74\x68\157\144"])) { $request->set_method($_GET["\x5f\x6d\x65\164\150\157\x64"]); } elseif (isset($_SERVER["\110\124\124\120\x5f\130\x5f\x48\124\124\x50\x5f\115\105\x54\x48\x4f\x44\137\x4f\x56\105\122\x52\x49\x44\x45"])) { $request->set_method($_SERVER["\110\124\x54\x50\x5f\x58\x5f\110\124\124\x50\137\115\105\124\x48\117\x44\x5f\117\x56\x45\122\122\111\104\105"]); } $result = $this->check_authentication(); if (!is_wp_error($result)) { $result = $this->dispatch($request); } $result = rest_ensure_response($result); if (is_wp_error($result)) { $result = $this->error_to_response($result); } $result = apply_filters("\x72\145\163\164\x5f\160\x6f\x73\x74\x5f\x64\x69\x73\160\141\x74\143\x68", rest_ensure_response($result), $this, $request); if (isset($_GET["\137\x65\156\x76\145\x6c\x6f\x70\145"])) { $result = $this->envelope_response($result, isset($_GET["\x5f\145\x6d\x62\145\x64"])); } $headers = $result->get_headers(); $this->send_headers($headers); $code = $result->get_status(); $this->set_status($code); $served = apply_filters("\x72\145\163\x74\x5f\160\162\145\137\163\x65\x72\166\x65\x5f\162\x65\x71\x75\x65\x73\164", false, $result, $request, $this); if (!$served) { if ("\110\x45\101\104" === $request->get_method()) { return null; } $result = $this->response_to_data($result, isset($_GET["\137\145\155\142\x65\144"])); $result = wp_json_encode($result); $json_error_message = $this->get_json_last_error(); if ($json_error_message) { $json_error_obj = new WP_Error("\x72\145\x73\164\137\x65\x6e\143\157\144\x65\x5f\x65\x72\x72\x6f\162", $json_error_message, array("\163\x74\141\164\165\x73" => 500)); $result = $this->error_to_response($json_error_obj); $result = wp_json_encode($result->data[0]); } if ($jsonp_callback) { echo "\x2f\x2a\52\57" . $jsonp_callback . "\50" . $result . "\51"; } else { echo $result; } } return null; } public function response_to_data($response, $embed) { $data = $response->get_data(); $links = $this->get_response_links($response); if (!empty($links)) { $data["\137\154\x69\156\153\163"] = $links; } if ($embed) { if (wp_is_numeric_array($data)) { $data = array_map(array($this, "\145\155\142\145\x64\137\154\x69\x6e\x6b\x73"), $data); } else { $data = $this->embed_links($data); } } return $data; } public static function get_response_links($response) { $links = $response->get_links(); if (empty($links)) { return array(); } $data = array(); foreach ($links as $rel => $items) { $data[$rel] = array(); foreach ($items as $item) { $attributes = $item["\x61\164\x74\162\151\142\x75\164\x65\163"]; $attributes["\x68\162\x65\146"] = $item["\x68\x72\x65\x66"]; $data[$rel][] = $attributes; } } return $data; } protected function embed_links($data) { if (empty($data["\137\154\151\x6e\x6b\163"])) { return $data; } $embedded = array(); $api_root = rest_url(); foreach ($data["\x5f\x6c\x69\156\x6b\x73"] as $rel => $links) { if ("\163\x65\x6c\x66" === $rel) { continue; } $embeds = array(); foreach ($links as $item) { if (empty($item["\145\x6d\142\x65\144\x64\141\142\154\145"]) || strpos($item["\x68\162\145\146"], $api_root) !== 0) { $embeds[] = array(); continue; } $route = substr($item["\150\162\x65\x66"], strlen(untrailingslashit($api_root))); $query_params = array(); $parsed = parse_url($route); if (empty($parsed["\x70\141\164\x68"])) { $embeds[] = array(); continue; } if (!empty($parsed["\x71\x75\x65\162\171"])) { parse_str($parsed["\x71\165\145\x72\171"], $query_params); if (get_magic_quotes_gpc()) { $query_params = stripslashes_deep($query_params); } } if (empty($query_params["\x63\157\156\164\x65\x78\x74"])) { $query_params["\x63\157\156\x74\x65\x78\164"] = "\x65\155\142\145\144"; } $request = new WP_REST_Request("\x47\105\x54", $parsed["\160\141\164\x68"]); $request->set_query_params($query_params); $response = $this->dispatch($request); $embeds[] = $this->response_to_data($response, false); } $has_links = count(array_filter($embeds)); if ($has_links) { $embedded[$rel] = $embeds; } } if (!empty($embedded)) { $data["\x5f\x65\155\x62\145\144\x64\145\144"] = $embedded; } return $data; } public function envelope_response($response, $embed) { $envelope = array("\142\x6f\144\171" => $this->response_to_data($response, $embed), "\163\164\x61\164\x75\x73" => $response->get_status(), "\150\x65\141\x64\145\x72\163" => $response->get_headers()); $envelope = apply_filters("\x72\x65\163\x74\137\145\156\166\145\x6c\x6f\x70\145\x5f\x72\145\163\x70\x6f\x6e\x73\145", $envelope, $response); return rest_ensure_response($envelope); } public function register_route($namespace, $route, $route_args, $override = false) { if (!isset($this->namespaces[$namespace])) { $this->namespaces[$namespace] = array(); $this->register_route($namespace, "\57" . $namespace, array(array("\155\145\164\150\x6f\x64\163" => self::READABLE, "\143\x61\x6c\154\x62\141\143\153" => array($this, "\147\x65\164\x5f\x6e\x61\x6d\x65\x73\x70\x61\x63\x65\137\x69\156\x64\145\170"), "\141\162\x67\163" => array("\x6e\141\x6d\145\163\x70\141\143\x65" => array("\144\145\146\x61\x75\154\x74" => $namespace), "\x63\x6f\156\x74\145\170\x74" => array("\x64\x65\x66\141\165\154\164" => "\x76\x69\x65\167"))))); } $this->namespaces[$namespace][$route] = true; $route_args["\x6e\x61\x6d\x65\x73\x70\141\x63\145"] = $namespace; if ($override || empty($this->endpoints[$route])) { $this->endpoints[$route] = $route_args; } else { $this->endpoints[$route] = array_merge($this->endpoints[$route], $route_args); } } public function get_routes() { $endpoints = apply_filters("\162\145\163\x74\137\x65\x6e\144\160\x6f\151\x6e\x74\x73", $this->endpoints); $defaults = array("\155\145\164\x68\157\x64\163" => '', "\x61\143\x63\145\160\x74\137\152\x73\157\156" => false, "\141\x63\x63\x65\160\164\137\x72\x61\167" => false, "\163\150\x6f\167\x5f\151\x6e\x5f\151\156\144\x65\x78" => true, "\141\x72\147\x73" => array()); foreach ($endpoints as $route => &$handlers) { if (isset($handlers["\143\141\154\154\x62\x61\x63\153"])) { $handlers = array($handlers); } if (!isset($this->route_options[$route])) { $this->route_options[$route] = array(); } foreach ($handlers as $key => &$handler) { if (!is_numeric($key)) { $this->route_options[$route][$key] = $handler; unset($handlers[$key]); continue; } $handler = wp_parse_args($handler, $defaults); if (is_string($handler["\155\x65\164\150\157\x64\163"])) { $methods = explode("\x2c", $handler["\x6d\145\164\x68\x6f\144\163"]); } else { if (is_array($handler["\155\145\x74\x68\157\144\x73"])) { $methods = $handler["\155\145\x74\150\x6f\x64\x73"]; } else { $methods = array(); } } $handler["\155\145\x74\150\157\x64\x73"] = array(); foreach ($methods as $method) { $method = strtoupper(trim($method)); $handler["\155\145\x74\x68\x6f\x64\x73"][$method] = true; } } } return $endpoints; } public function get_namespaces() { return array_keys($this->namespaces); } public function get_route_options($route) { if (!isset($this->route_options[$route])) { return null; } return $this->route_options[$route]; } public function dispatch($request) { $result = apply_filters("\x72\x65\163\164\137\160\162\145\x5f\144\x69\163\x70\141\164\143\150", null, $this, $request); if (!empty($result)) { return $result; } $method = $request->get_method(); $path = $request->get_route(); foreach ($this->get_routes() as $route => $handlers) { $match = preg_match("\x40\x5e" . $route . "\44\x40\151", $path, $args); if (!$match) { continue; } foreach ($handlers as $handler) { $callback = $handler["\x63\141\154\x6c\142\x61\143\x6b"]; $response = null; $checked_method = "\110\105\x41\x44" === $method ? "\107\x45\x54" : $method; if (empty($handler["\155\x65\164\x68\157\144\163"][$checked_method])) { continue; } if (!is_callable($callback)) { $response = new WP_Error("\x72\x65\x73\x74\x5f\x69\156\x76\141\x6c\x69\x64\137\x68\x61\x6e\x64\x6c\x65\162", __("\x54\150\x65\x20\x68\x61\156\144\x6c\x65\162\40\x66\157\162\x20\164\150\x65\40\162\x6f\165\x74\145\40\x69\x73\40\151\x6e\166\141\x6c\x69\144"), array("\163\164\141\164\x75\x73" => 500)); } if (!is_wp_error($response)) { unset($args[0]); $request->set_url_params($args); $request->set_attributes($handler); $request->sanitize_params(); $defaults = array(); foreach ($handler["\x61\x72\x67\163"] as $arg => $options) { if (isset($options["\144\145\x66\141\x75\x6c\164"])) { $defaults[$arg] = $options["\x64\x65\146\x61\x75\x6c\164"]; } } $request->set_default_params($defaults); $check_required = $request->has_valid_params(); if (is_wp_error($check_required)) { $response = $check_required; } } if (!is_wp_error($response)) { if (!empty($handler["\160\145\x72\155\151\163\163\151\157\156\x5f\143\141\x6c\x6c\x62\x61\143\153"])) { $permission = call_user_func($handler["\x70\x65\x72\x6d\x69\163\163\151\157\x6e\137\143\141\x6c\x6c\x62\x61\x63\x6b"], $request); if (is_wp_error($permission)) { $response = $permission; } else { if (false === $permission || null === $permission) { $response = new WP_Error("\162\145\x73\x74\137\x66\x6f\x72\x62\x69\144\x64\145\156", __("\x59\x6f\165\40\144\x6f\156\47\164\40\150\x61\x76\x65\40\160\145\162\155\151\x73\x73\x69\x6f\156\x20\x74\x6f\40\144\x6f\40\164\x68\151\163\56"), array("\163\164\141\x74\165\163" => 403)); } } } } if (!is_wp_error($response)) { $dispatch_result = apply_filters("\162\145\163\x74\x5f\x64\151\x73\x70\141\164\x63\x68\137\162\x65\161\165\x65\163\x74", null, $request); if (null !== $dispatch_result) { $response = $dispatch_result; } else { $response = call_user_func($callback, $request); } } if (is_wp_error($response)) { $response = $this->error_to_response($response); } else { $response = rest_ensure_response($response); } $response->set_matched_route($route); $response->set_matched_handler($handler); return $response; } } return $this->error_to_response(new WP_Error("\x72\x65\163\164\x5f\x6e\157\137\162\157\165\x74\145", __("\116\x6f\x20\162\x6f\x75\164\x65\40\x77\141\x73\x20\x66\x6f\165\156\144\40\155\141\x74\x63\150\151\x6e\x67\40\x74\x68\145\x20\x55\122\x4c\40\141\x6e\144\40\162\145\161\165\145\x73\x74\x20\x6d\x65\164\150\157\144"), array("\x73\x74\x61\164\x75\163" => 404))); } protected function get_json_last_error() { if (!function_exists("\x6a\163\x6f\x6e\x5f\x6c\x61\x73\164\x5f\x65\x72\x72\x6f\162")) { return false; } $last_error_code = json_last_error(); if (defined("\112\123\x4f\x4e\137\105\x52\x52\117\x52\x5f\116\x4f\x4e\x45") && JSON_ERROR_NONE === $last_error_code || empty($last_error_code)) { return false; } return json_last_error_msg(); } public function get_index($request) { $available = array("\156\x61\155\x65" => get_option("\x62\x6c\157\147\x6e\x61\x6d\145"), "\x64\145\163\x63\162\x69\x70\164\151\x6f\156" => get_option("\x62\154\x6f\147\x64\x65\163\x63\162\x69\x70\164\151\x6f\x6e"), "\165\x72\154" => get_option("\x73\151\164\x65\x75\x72\x6c"), "\x6e\141\x6d\x65\x73\x70\x61\143\145\163" => array_keys($this->namespaces), "\141\x75\x74\x68\145\x6e\164\x69\143\x61\x74\x69\x6f\x6e" => array(), "\162\x6f\165\164\x65\x73" => $this->get_data_for_routes($this->get_routes(), $request["\143\x6f\156\164\145\x78\x74"])); $response = new WP_REST_Response($available); $response->add_link("\150\145\154\160", "\150\164\164\x70\x3a\x2f\x2f\x76\62\x2e\167\x70\55\141\x70\x69\x2e\x6f\x72\147\57"); return apply_filters("\x72\145\x73\x74\137\x69\156\x64\145\170", $response); } public function get_namespace_index($request) { $namespace = $request["\x6e\141\155\x65\x73\x70\141\x63\145"]; if (!isset($this->namespaces[$namespace])) { return new WP_Error("\162\x65\x73\164\x5f\x69\156\166\x61\154\151\144\137\156\x61\x6d\x65\163\160\x61\143\145", __("\124\x68\x65\x20\x73\160\x65\x63\151\146\x69\x65\x64\40\156\141\155\145\x73\x70\141\x63\x65\40\143\x6f\x75\154\144\x20\156\157\164\x20\x62\145\x20\x66\x6f\165\156\x64\56"), array("\163\164\141\164\165\x73" => 404)); } $routes = $this->namespaces[$namespace]; $endpoints = array_intersect_key($this->get_routes(), $routes); $data = array("\x6e\x61\x6d\x65\x73\160\x61\x63\145" => $namespace, "\x72\157\x75\x74\x65\163" => $this->get_data_for_routes($endpoints, $request["\143\157\x6e\164\145\x78\164"])); $response = rest_ensure_response($data); $response->add_link("\x75\160", rest_url("\x2f")); return apply_filters("\x72\x65\x73\164\x5f\156\141\155\x65\163\x70\x61\x63\x65\137\x69\156\144\x65\170", $response, $request); } public function get_data_for_routes($routes, $context = "\x76\x69\x65\x77") { $available = array(); foreach ($routes as $route => $callbacks) { $data = $this->get_data_for_route($route, $callbacks, $context); if (empty($data)) { continue; } $available[$route] = apply_filters("\x72\145\163\x74\x5f\x65\x6e\144\x70\x6f\151\156\164\163\x5f\x64\145\163\143\162\x69\160\x74\151\x6f\x6e", $data); } return apply_filters("\162\145\163\x74\x5f\x72\x6f\165\164\x65\x5f\x64\141\164\x61", $available, $routes); } public function get_data_for_route($route, $callbacks, $context = "\166\151\145\167") { $data = array("\x6e\141\x6d\145\163\x70\x61\143\x65" => '', "\x6d\x65\164\x68\x6f\144\x73" => array(), "\x65\x6e\x64\160\157\x69\x6e\x74\163" => array()); if (isset($this->route_options[$route])) { $options = $this->route_options[$route]; if (isset($options["\156\x61\155\145\163\x70\x61\143\145"])) { $data["\156\x61\x6d\145\x73\x70\141\143\x65"] = $options["\x6e\x61\x6d\x65\x73\x70\141\x63\x65"]; } if (isset($options["\163\x63\x68\x65\155\141"]) && "\150\x65\154\x70" === $context) { $data["\163\x63\x68\145\x6d\x61"] = call_user_func($options["\163\143\x68\x65\155\x61"]); } } $route = preg_replace("\43\x5c\x28\134\x3f\x50\x3c\50\x5c\x77\x2b\77\51\x3e\x2e\x2a\77\x5c\x29\43", "\173\44\61\x7d", $route); foreach ($callbacks as $callback) { if (empty($callback["\x73\x68\157\x77\137\x69\156\x5f\151\156\x64\x65\170"])) { continue; } $data["\x6d\145\x74\x68\157\144\x73"] = array_merge($data["\155\145\164\150\x6f\x64\163"], array_keys($callback["\155\145\x74\150\x6f\144\x73"])); $endpoint_data = array("\x6d\145\164\150\157\x64\163" => array_keys($callback["\155\145\x74\x68\x6f\144\x73"])); if (isset($callback["\141\162\147\163"])) { $endpoint_data["\x61\x72\x67\x73"] = array(); foreach ($callback["\x61\162\147\x73"] as $key => $opts) { $arg_data = array("\162\x65\161\165\151\162\145\144" => !empty($opts["\x72\145\x71\x75\151\162\x65\x64"])); if (isset($opts["\144\x65\x66\x61\x75\x6c\x74"])) { $arg_data["\144\x65\146\x61\165\154\164"] = $opts["\x64\145\x66\x61\165\154\164"]; } if (isset($opts["\x65\x6e\165\155"])) { $arg_data["\145\156\x75\155"] = $opts["\x65\x6e\x75\x6d"]; } if (isset($opts["\144\145\x73\x63\x72\151\160\x74\151\x6f\156"])) { $arg_data["\144\145\x73\x63\162\151\x70\164\x69\x6f\156"] = $opts["\144\145\163\143\x72\x69\160\164\151\x6f\156"]; } $endpoint_data["\141\162\x67\x73"][$key] = $arg_data; } } $data["\x65\x6e\x64\x70\157\x69\x6e\x74\x73"][] = $endpoint_data; if (strpos($route, "\173") === false) { $data["\x5f\154\x69\x6e\x6b\x73"] = array("\163\x65\154\146" => rest_url($route)); } } if (empty($data["\x6d\145\164\150\157\x64\163"])) { return null; } return $data; } protected function set_status($code) { status_header($code); } public function send_header($key, $value) { $value = preg_replace("\57\134\163\53\x2f", "\40", $value); header(sprintf("\x25\163\x3a\40\45\x73", $key, $value)); } public function send_headers($headers) { foreach ($headers as $key => $value) { $this->send_header($key, $value); } } public static function get_raw_data() { global $HTTP_RAW_POST_DATA; if (!isset($HTTP_RAW_POST_DATA)) { $HTTP_RAW_POST_DATA = file_get_contents("\160\150\160\72\57\57\x69\x6e\x70\165\164"); } return $HTTP_RAW_POST_DATA; } public function get_headers($server) { $headers = array(); $additional = array("\103\117\x4e\124\x45\x4e\124\137\114\x45\x4e\107\124\110" => true, "\103\117\x4e\124\105\x4e\124\x5f\x4d\104\x35" => true, "\103\x4f\116\x54\105\x4e\124\137\x54\131\x50\x45" => true); foreach ($server as $key => $value) { if (strpos($key, "\110\x54\x54\x50\x5f") === 0) { $headers[substr($key, 5)] = $value; } elseif (isset($additional[$key])) { $headers[$key] = $value; } } return $headers; } }

Function Calls

None

Variables

None

Stats

MD5 68e6bbda79b27efdc0f79485419bce07
Eval Count 0
Decode Time 186 ms