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 if (!defined("\101\x42\x53\120\101\124\x48")) { die; } class WC_REST_Product_Review..

Decoded Output download

<?php
 if (!defined("ABSPATH")) { die; } class WC_REST_Product_Reviews_V1_Controller extends WC_REST_Controller { protected $namespace = "wc/v1"; protected $rest_base = "products/(?P<product_id>[\d]+)/reviews"; public function register_routes() { register_rest_route($this->namespace, "/" . $this->rest_base, array("args" => array("product_id" => array("description" => __("Unique identifier for the variable product.", "woocommerce"), "type" => "integer"), "id" => array("description" => __("Unique identifier for the variation.", "woocommerce"), "type" => "integer")), array("methods" => WP_REST_Server::READABLE, "callback" => array($this, "get_items"), "permission_callback" => array($this, "get_items_permissions_check"), "args" => $this->get_collection_params()), array("methods" => WP_REST_Server::CREATABLE, "callback" => array($this, "create_item"), "permission_callback" => array($this, "create_item_permissions_check"), "args" => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array("review" => array("required" => true, "type" => "string", "description" => __("Review content.", "woocommerce")), "name" => array("required" => true, "type" => "string", "description" => __("Name of the reviewer.", "woocommerce")), "email" => array("required" => true, "type" => "string", "description" => __("Email of the reviewer.", "woocommerce"))))), "schema" => array($this, "get_public_item_schema"))); register_rest_route($this->namespace, "/" . $this->rest_base . "/(?P<id>[\d]+)", array("args" => array("product_id" => array("description" => __("Unique identifier for the variable product.", "woocommerce"), "type" => "integer"), "id" => array("description" => __("Unique identifier for the resource.", "woocommerce"), "type" => "integer")), array("methods" => WP_REST_Server::READABLE, "callback" => array($this, "get_item"), "permission_callback" => array($this, "get_item_permissions_check"), "args" => array("context" => $this->get_context_param(array("default" => "view")))), array("methods" => WP_REST_Server::EDITABLE, "callback" => array($this, "update_item"), "permission_callback" => array($this, "update_item_permissions_check"), "args" => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)), array("methods" => WP_REST_Server::DELETABLE, "callback" => array($this, "delete_item"), "permission_callback" => array($this, "delete_item_permissions_check"), "args" => array("force" => array("default" => false, "type" => "boolean", "description" => __("Whether to bypass trash and force deletion.", "woocommerce")))), "schema" => array($this, "get_public_item_schema"))); } public function get_items_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("read")) { return new WP_Error("woocommerce_rest_cannot_view", __("Sorry, you cannot list resources.", "woocommerce"), array("status" => rest_authorization_required_code())); } return true; } public function get_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("read", (int) $request["id"])) { return new WP_Error("woocommerce_rest_cannot_view", __("Sorry, you cannot view this resource.", "woocommerce"), array("status" => rest_authorization_required_code())); } return true; } public function create_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("create")) { return new WP_Error("woocommerce_rest_cannot_create", __("Sorry, you are not allowed to create resources.", "woocommerce"), array("status" => rest_authorization_required_code())); } return true; } public function update_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("edit", (int) $request["id"])) { return new WP_Error("woocommerce_rest_cannot_edit", __("Sorry, you cannot edit this resource.", "woocommerce"), array("status" => rest_authorization_required_code())); } return true; } public function delete_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("delete", (int) $request["id"])) { return new WP_Error("woocommerce_rest_cannot_delete", __("Sorry, you cannot delete this resource.", "woocommerce"), array("status" => rest_authorization_required_code())); } return true; } public function get_items($request) { $product_id = (int) $request["product_id"]; if ("product" !== get_post_type($product_id)) { return new WP_Error("woocommerce_rest_product_invalid_id", __("Invalid product ID.", "woocommerce"), array("status" => 404)); } $reviews = get_approved_comments($product_id); $data = array(); foreach ($reviews as $review_data) { $review = $this->prepare_item_for_response($review_data, $request); $review = $this->prepare_response_for_collection($review); $data[] = $review; } return rest_ensure_response($data); } public function get_item($request) { $id = (int) $request["id"]; $product_id = (int) $request["product_id"]; if ("product" !== get_post_type($product_id)) { return new WP_Error("woocommerce_rest_product_invalid_id", __("Invalid product ID.", "woocommerce"), array("status" => 404)); } $review = get_comment($id); if (empty($id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { return new WP_Error("woocommerce_rest_invalid_id", __("Invalid resource ID.", "woocommerce"), array("status" => 404)); } $delivery = $this->prepare_item_for_response($review, $request); $response = rest_ensure_response($delivery); return $response; } public function create_item($request) { $product_id = (int) $request["product_id"]; if ("product" !== get_post_type($product_id)) { return new WP_Error("woocommerce_rest_product_invalid_id", __("Invalid product ID.", "woocommerce"), array("status" => 404)); } $prepared_review = $this->prepare_item_for_database($request); $prepared_review = apply_filters("rest_pre_insert_product_review", $prepared_review, $request); $product_review_id = wp_insert_comment($prepared_review); if (!$product_review_id) { return new WP_Error("rest_product_review_failed_create", __("Creating product review failed.", "woocommerce"), array("status" => 500)); } update_comment_meta($product_review_id, "rating", !empty($request["rating"]) ? $request["rating"] : "0"); $product_review = get_comment($product_review_id); $this->update_additional_fields_for_object($product_review, $request); do_action("woocommerce_rest_insert_product_review", $product_review, $request, true); $request->set_param("context", "edit"); $response = $this->prepare_item_for_response($product_review, $request); $response = rest_ensure_response($response); $response->set_status(201); $base = str_replace("(?P<product_id>[\d]+)", $product_id, $this->rest_base); $response->header("Location", rest_url(sprintf("/%s/%s/%d", $this->namespace, $base, $product_review_id))); return $response; } public function update_item($request) { $product_review_id = (int) $request["id"]; $product_id = (int) $request["product_id"]; if ("product" !== get_post_type($product_id)) { return new WP_Error("woocommerce_rest_product_invalid_id", __("Invalid product ID.", "woocommerce"), array("status" => 404)); } $review = get_comment($product_review_id); if (empty($product_review_id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { return new WP_Error("woocommerce_rest_product_review_invalid_id", __("Invalid resource ID.", "woocommerce"), array("status" => 404)); } $prepared_review = $this->prepare_item_for_database($request); $updated = wp_update_comment($prepared_review); if (0 === $updated) { return new WP_Error("rest_product_review_failed_edit", __("Updating product review failed.", "woocommerce"), array("status" => 500)); } if (!empty($request["rating"])) { update_comment_meta($product_review_id, "rating", $request["rating"]); } $product_review = get_comment($product_review_id); $this->update_additional_fields_for_object($product_review, $request); do_action("woocommerce_rest_insert_product_review", $product_review, $request, true); $request->set_param("context", "edit"); $response = $this->prepare_item_for_response($product_review, $request); return rest_ensure_response($response); } public function delete_item($request) { $product_id = (int) $request["product_id"]; $product_review_id = (int) $request["id"]; $force = isset($request["force"]) ? (bool) $request["force"] : false; if ("product" !== get_post_type($product_id)) { return new WP_Error("woocommerce_rest_product_invalid_id", __("Invalid product ID.", "woocommerce"), array("status" => 404)); } $product_review = get_comment($product_review_id); if (empty($product_review_id) || empty($product_review->comment_ID) || empty($product_review->comment_post_ID)) { return new WP_Error("woocommerce_rest_product_review_invalid_id", __("Invalid product review ID.", "woocommerce"), array("status" => 404)); } $supports_trash = apply_filters("rest_product_review_trashable", EMPTY_TRASH_DAYS > 0, $product_review); $request->set_param("context", "edit"); $response = $this->prepare_item_for_response($product_review, $request); if ($force) { $result = wp_delete_comment($product_review_id, true); } else { if (!$supports_trash) { return new WP_Error("rest_trash_not_supported", __("The product review does not support trashing.", "woocommerce"), array("status" => 501)); } if ("trash" === $product_review->comment_approved) { return new WP_Error("rest_already_trashed", __("The comment has already been trashed.", "woocommerce"), array("status" => 410)); } $result = wp_trash_comment($product_review->comment_ID); } if (!$result) { return new WP_Error("rest_cannot_delete", __("The product review cannot be deleted.", "woocommerce"), array("status" => 500)); } do_action("rest_delete_product_review", $product_review, $response, $request); return $response; } public function prepare_item_for_response($review, $request) { $data = array("id" => (int) $review->comment_ID, "date_created" => wc_rest_prepare_date_response($review->comment_date_gmt), "review" => $review->comment_content, "rating" => (int) get_comment_meta($review->comment_ID, "rating", true), "name" => $review->comment_author, "email" => $review->comment_author_email, "verified" => wc_review_is_from_verified_owner($review->comment_ID)); $context = !empty($request["context"]) ? $request["context"] : "view"; $data = $this->add_additional_fields_to_object($data, $request); $data = $this->filter_response_by_context($data, $context); $response = rest_ensure_response($data); $response->add_links($this->prepare_links($review, $request)); return apply_filters("woocommerce_rest_prepare_product_review", $response, $review, $request); } protected function prepare_item_for_database($request) { $prepared_review = array("comment_approved" => 1, "comment_type" => "review"); if (isset($request["id"])) { $prepared_review["comment_ID"] = (int) $request["id"]; } if (isset($request["review"])) { $prepared_review["comment_content"] = $request["review"]; } if (isset($request["product_id"])) { $prepared_review["comment_post_ID"] = (int) $request["product_id"]; } if (isset($request["name"])) { $prepared_review["comment_author"] = $request["name"]; } if (isset($request["email"])) { $prepared_review["comment_author_email"] = $request["email"]; } if (isset($request["date_created"])) { $prepared_review["comment_date"] = $request["date_created"]; } if (isset($request["date_created_gmt"])) { $prepared_review["comment_date_gmt"] = $request["date_created_gmt"]; } return apply_filters("rest_preprocess_product_review", $prepared_review, $request); } protected function prepare_links($review, $request) { $product_id = (int) $request["product_id"]; $base = str_replace("(?P<product_id>[\d]+)", $product_id, $this->rest_base); $links = array("self" => array("href" => rest_url(sprintf("/%s/%s/%d", $this->namespace, $base, $review->comment_ID))), "collection" => array("href" => rest_url(sprintf("/%s/%s", $this->namespace, $base))), "up" => array("href" => rest_url(sprintf("/%s/products/%d", $this->namespace, $product_id)))); return $links; } public function get_item_schema() { $schema = array("$schema" => "http://json-schema.org/draft-04/schema#", "title" => "product_review", "type" => "object", "properties" => array("id" => array("description" => __("Unique identifier for the resource.", "woocommerce"), "type" => "integer", "context" => array("view", "edit"), "readonly" => true), "review" => array("description" => __("The content of the review.", "woocommerce"), "type" => "string", "context" => array("view", "edit")), "date_created" => array("description" => __("The date the review was created, in the site's timezone.", "woocommerce"), "type" => "date-time", "context" => array("view", "edit")), "rating" => array("description" => __("Review rating (0 to 5).", "woocommerce"), "type" => "integer", "context" => array("view", "edit")), "name" => array("description" => __("Reviewer name.", "woocommerce"), "type" => "string", "context" => array("view", "edit")), "email" => array("description" => __("Reviewer email.", "woocommerce"), "type" => "string", "context" => array("view", "edit")), "verified" => array("description" => __("Shows if the reviewer bought the product or not.", "woocommerce"), "type" => "boolean", "context" => array("view", "edit"), "readonly" => true))); return $this->add_additional_fields_schema($schema); } public function get_collection_params() { return array("context" => $this->get_context_param(array("default" => "view"))); } } ?>

Did this file decode correctly?

Original Code

<?php
 if (!defined("\101\x42\x53\120\101\124\x48")) { die; } class WC_REST_Product_Reviews_V1_Controller extends WC_REST_Controller { protected $namespace = "\x77\143\57\166\x31"; protected $rest_base = "\x70\x72\x6f\144\165\x63\x74\x73\57\50\x3f\x50\x3c\160\x72\157\144\165\x63\164\x5f\x69\144\76\133\134\144\135\53\x29\57\162\x65\x76\151\145\x77\163"; public function register_routes() { register_rest_route($this->namespace, "\57" . $this->rest_base, array("\x61\162\x67\163" => array("\160\162\x6f\144\x75\x63\164\x5f\151\x64" => array("\144\145\163\x63\x72\151\160\x74\151\x6f\156" => __("\125\156\151\161\165\145\40\151\144\145\x6e\x74\151\x66\x69\x65\162\40\146\x6f\x72\x20\164\150\x65\40\x76\x61\x72\x69\141\142\x6c\x65\40\160\162\x6f\x64\165\143\164\x2e", "\167\157\x6f\x63\x6f\x6d\x6d\x65\162\x63\145"), "\164\171\x70\145" => "\151\156\164\x65\147\x65\162"), "\x69\144" => array("\144\145\x73\x63\x72\x69\160\x74\x69\x6f\x6e" => __("\x55\156\151\161\165\x65\40\151\144\145\x6e\x74\151\146\151\145\162\x20\x66\157\x72\x20\164\x68\145\40\x76\x61\162\x69\x61\x74\x69\x6f\156\56", "\167\x6f\157\143\x6f\155\x6d\145\162\x63\145"), "\x74\171\x70\x65" => "\x69\x6e\x74\145\x67\x65\x72")), array("\x6d\x65\164\x68\x6f\x64\163" => WP_REST_Server::READABLE, "\143\x61\x6c\154\x62\141\x63\153" => array($this, "\147\x65\164\x5f\151\164\x65\x6d\x73"), "\160\x65\x72\x6d\x69\163\x73\151\157\156\137\x63\x61\154\x6c\142\x61\x63\x6b" => array($this, "\x67\x65\164\137\x69\x74\x65\x6d\x73\137\160\145\162\155\151\x73\x73\x69\157\156\163\137\143\x68\145\143\x6b"), "\x61\162\147\163" => $this->get_collection_params()), array("\x6d\x65\164\x68\157\144\163" => WP_REST_Server::CREATABLE, "\143\141\x6c\154\x62\x61\x63\x6b" => array($this, "\x63\x72\x65\x61\x74\145\137\x69\164\x65\x6d"), "\160\145\x72\155\151\x73\x73\x69\157\x6e\137\143\141\154\154\x62\141\143\153" => array($this, "\143\162\145\141\164\x65\137\x69\x74\x65\x6d\x5f\160\x65\162\155\x69\163\x73\x69\157\156\163\x5f\143\x68\145\x63\153"), "\x61\162\147\163" => array_merge($this->get_endpoint_args_for_item_schema(WP_REST_Server::CREATABLE), array("\162\145\166\x69\145\x77" => array("\x72\145\x71\165\x69\162\x65\x64" => true, "\x74\171\160\145" => "\x73\164\162\151\x6e\x67", "\144\x65\163\x63\162\x69\160\164\151\157\x6e" => __("\x52\145\x76\151\x65\x77\x20\x63\x6f\x6e\x74\x65\156\x74\x2e", "\167\157\x6f\143\x6f\x6d\x6d\x65\x72\143\x65")), "\156\141\x6d\x65" => array("\x72\145\161\165\x69\x72\145\x64" => true, "\x74\171\x70\145" => "\x73\x74\162\151\156\147", "\144\x65\163\143\x72\151\160\x74\x69\157\156" => __("\x4e\x61\155\145\x20\x6f\x66\x20\164\x68\145\40\162\x65\x76\151\145\167\x65\x72\x2e", "\x77\157\x6f\x63\157\155\x6d\145\x72\143\145")), "\145\x6d\141\151\x6c" => array("\162\145\161\x75\x69\x72\145\x64" => true, "\164\x79\x70\145" => "\163\x74\x72\x69\156\147", "\144\x65\163\x63\x72\x69\160\164\151\x6f\x6e" => __("\x45\x6d\x61\151\x6c\40\157\146\x20\164\150\x65\x20\x72\x65\166\x69\x65\167\x65\162\56", "\x77\x6f\157\x63\x6f\155\x6d\145\162\143\145"))))), "\163\143\150\145\155\x61" => array($this, "\147\x65\164\137\160\165\x62\154\x69\143\x5f\x69\164\145\x6d\x5f\x73\x63\x68\x65\155\141"))); register_rest_route($this->namespace, "\x2f" . $this->rest_base . "\57\x28\x3f\x50\x3c\151\x64\76\x5b\x5c\x64\135\x2b\x29", array("\141\x72\147\163" => array("\160\162\157\x64\165\x63\x74\x5f\x69\x64" => array("\x64\x65\163\143\x72\x69\160\x74\151\157\x6e" => __("\x55\156\151\161\x75\x65\40\151\x64\x65\156\x74\x69\x66\151\x65\162\x20\x66\157\x72\40\x74\150\x65\x20\166\x61\162\151\141\142\154\x65\40\160\x72\157\x64\x75\143\164\56", "\167\x6f\157\143\157\x6d\x6d\145\162\x63\x65"), "\164\171\160\x65" => "\x69\x6e\164\x65\x67\145\162"), "\151\144" => array("\144\145\x73\x63\x72\151\160\164\151\x6f\x6e" => __("\x55\x6e\x69\x71\x75\145\40\151\x64\145\156\164\151\x66\151\145\x72\x20\x66\157\162\x20\164\x68\145\x20\x72\145\163\157\165\x72\143\145\x2e", "\167\157\x6f\x63\157\155\x6d\x65\162\143\145"), "\x74\171\160\145" => "\x69\x6e\164\x65\147\145\x72")), array("\155\x65\164\x68\x6f\144\x73" => WP_REST_Server::READABLE, "\x63\141\154\x6c\x62\141\143\x6b" => array($this, "\x67\145\164\x5f\151\x74\145\x6d"), "\x70\145\162\x6d\151\163\x73\151\157\x6e\137\143\x61\x6c\x6c\142\x61\143\x6b" => array($this, "\147\145\164\137\151\164\x65\x6d\137\160\x65\162\155\151\163\x73\151\157\156\x73\137\143\150\145\143\x6b"), "\141\x72\x67\x73" => array("\x63\x6f\x6e\164\145\170\164" => $this->get_context_param(array("\144\145\146\141\165\154\164" => "\166\151\145\167")))), array("\155\145\x74\x68\157\144\x73" => WP_REST_Server::EDITABLE, "\143\141\x6c\x6c\142\x61\x63\x6b" => array($this, "\165\x70\144\x61\x74\145\x5f\151\164\145\x6d"), "\160\x65\x72\155\151\163\x73\x69\157\156\x5f\x63\x61\154\154\x62\x61\143\x6b" => array($this, "\165\160\x64\x61\x74\x65\137\151\164\145\x6d\137\x70\x65\x72\155\151\163\x73\151\x6f\x6e\x73\x5f\143\150\145\x63\x6b"), "\141\162\147\163" => $this->get_endpoint_args_for_item_schema(WP_REST_Server::EDITABLE)), array("\x6d\145\x74\150\x6f\144\163" => WP_REST_Server::DELETABLE, "\x63\141\154\x6c\142\x61\x63\x6b" => array($this, "\144\x65\x6c\145\164\x65\x5f\x69\x74\145\x6d"), "\160\145\162\x6d\x69\x73\163\x69\157\x6e\x5f\143\141\154\x6c\x62\141\x63\x6b" => array($this, "\144\x65\x6c\x65\x74\x65\x5f\x69\x74\145\x6d\x5f\160\x65\162\x6d\151\163\163\151\x6f\156\x73\x5f\143\x68\x65\x63\153"), "\x61\x72\147\163" => array("\146\157\162\x63\x65" => array("\144\145\146\141\165\154\164" => false, "\164\x79\160\x65" => "\x62\157\157\x6c\x65\x61\x6e", "\x64\145\x73\143\x72\151\160\x74\151\157\156" => __("\x57\x68\145\164\x68\145\162\40\x74\157\x20\142\x79\x70\141\163\163\40\164\162\x61\x73\150\40\141\x6e\x64\x20\146\x6f\162\143\x65\40\144\x65\154\145\164\x69\x6f\x6e\x2e", "\167\x6f\157\x63\157\x6d\x6d\145\x72\x63\145")))), "\x73\143\150\145\x6d\x61" => array($this, "\147\x65\x74\x5f\x70\165\142\154\x69\x63\137\x69\164\145\155\137\163\x63\x68\x65\155\x61"))); } public function get_items_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("\x72\x65\x61\144")) { return new WP_Error("\167\157\157\143\157\155\x6d\145\162\143\x65\x5f\x72\x65\x73\164\137\143\141\x6e\156\x6f\164\137\166\151\x65\167", __("\123\x6f\x72\162\x79\x2c\40\x79\x6f\x75\40\143\141\x6e\156\x6f\x74\40\154\x69\x73\x74\x20\162\145\x73\157\165\162\x63\x65\163\56", "\x77\x6f\157\x63\157\155\x6d\x65\x72\143\x65"), array("\163\164\x61\164\x75\x73" => rest_authorization_required_code())); } return true; } public function get_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("\162\145\x61\x64", (int) $request["\151\x64"])) { return new WP_Error("\x77\x6f\x6f\143\157\155\x6d\145\x72\143\x65\137\x72\145\163\x74\137\143\x61\x6e\x6e\x6f\x74\137\x76\x69\145\167", __("\x53\x6f\162\162\171\x2c\x20\171\x6f\165\x20\x63\x61\156\156\x6f\x74\40\x76\x69\145\x77\40\164\x68\151\163\40\x72\145\x73\x6f\x75\162\x63\145\56", "\x77\x6f\157\143\x6f\x6d\155\145\162\x63\x65"), array("\x73\164\x61\x74\x75\163" => rest_authorization_required_code())); } return true; } public function create_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("\143\x72\x65\x61\x74\145")) { return new WP_Error("\x77\157\x6f\x63\x6f\155\155\x65\x72\x63\x65\137\x72\145\163\164\x5f\x63\x61\x6e\156\x6f\164\x5f\x63\162\x65\x61\164\x65", __("\x53\x6f\x72\162\171\x2c\x20\x79\x6f\165\40\x61\162\x65\40\156\157\x74\40\x61\154\x6c\x6f\167\x65\x64\x20\164\157\x20\x63\x72\145\141\x74\145\x20\162\145\x73\x6f\165\x72\143\x65\x73\56", "\x77\157\157\x63\157\155\x6d\x65\x72\x63\x65"), array("\x73\164\141\x74\165\163" => rest_authorization_required_code())); } return true; } public function update_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("\x65\x64\151\164", (int) $request["\151\144"])) { return new WP_Error("\x77\157\x6f\143\157\x6d\155\145\x72\x63\145\x5f\x72\x65\163\x74\137\x63\x61\156\156\157\164\x5f\145\144\151\x74", __("\123\157\162\x72\x79\x2c\40\x79\x6f\165\x20\x63\141\156\156\x6f\164\x20\x65\x64\x69\164\x20\164\150\x69\x73\x20\x72\x65\163\157\x75\x72\x63\x65\56", "\167\157\x6f\143\157\155\155\x65\x72\143\145"), array("\x73\164\x61\164\165\163" => rest_authorization_required_code())); } return true; } public function delete_item_permissions_check($request) { if (!wc_rest_check_product_reviews_permissions("\144\x65\154\x65\x74\145", (int) $request["\x69\x64"])) { return new WP_Error("\x77\x6f\157\143\x6f\155\x6d\x65\x72\143\x65\137\x72\145\163\164\137\x63\141\x6e\156\x6f\x74\x5f\x64\145\154\x65\x74\145", __("\123\x6f\x72\162\x79\54\x20\x79\157\165\x20\143\x61\x6e\x6e\x6f\164\x20\144\x65\154\x65\x74\x65\x20\164\150\151\x73\40\162\x65\x73\x6f\x75\x72\143\145\x2e", "\167\x6f\157\x63\x6f\x6d\155\x65\x72\143\145"), array("\x73\x74\141\x74\x75\163" => rest_authorization_required_code())); } return true; } public function get_items($request) { $product_id = (int) $request["\160\x72\157\144\x75\x63\164\x5f\x69\x64"]; if ("\160\162\x6f\x64\x75\143\x74" !== get_post_type($product_id)) { return new WP_Error("\167\157\157\143\157\x6d\x6d\145\x72\x63\x65\137\x72\145\x73\164\137\160\162\157\144\x75\x63\x74\137\151\156\166\x61\154\x69\x64\x5f\151\x64", __("\x49\156\166\141\x6c\151\x64\x20\x70\162\157\144\165\x63\x74\40\111\x44\56", "\x77\x6f\157\143\157\x6d\x6d\145\162\x63\145"), array("\163\x74\141\x74\165\x73" => 404)); } $reviews = get_approved_comments($product_id); $data = array(); foreach ($reviews as $review_data) { $review = $this->prepare_item_for_response($review_data, $request); $review = $this->prepare_response_for_collection($review); $data[] = $review; } return rest_ensure_response($data); } public function get_item($request) { $id = (int) $request["\x69\x64"]; $product_id = (int) $request["\160\x72\x6f\x64\165\143\x74\x5f\151\144"]; if ("\x70\x72\x6f\144\x75\143\164" !== get_post_type($product_id)) { return new WP_Error("\x77\x6f\x6f\x63\x6f\155\x6d\145\x72\x63\145\x5f\x72\145\x73\164\137\x70\162\x6f\144\165\143\164\137\x69\156\x76\x61\154\x69\x64\x5f\151\x64", __("\111\x6e\166\141\154\151\144\40\x70\x72\157\144\x75\143\x74\x20\x49\104\x2e", "\167\x6f\x6f\143\x6f\x6d\x6d\145\x72\143\145"), array("\x73\164\x61\x74\x75\x73" => 404)); } $review = get_comment($id); if (empty($id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { return new WP_Error("\167\157\157\x63\157\x6d\155\x65\x72\x63\x65\x5f\162\x65\x73\x74\137\151\156\x76\x61\154\151\144\x5f\151\144", __("\x49\156\166\141\x6c\x69\144\x20\162\x65\163\x6f\165\x72\143\x65\40\111\x44\56", "\x77\157\x6f\x63\157\x6d\x6d\145\162\143\x65"), array("\163\164\x61\164\165\163" => 404)); } $delivery = $this->prepare_item_for_response($review, $request); $response = rest_ensure_response($delivery); return $response; } public function create_item($request) { $product_id = (int) $request["\x70\x72\x6f\144\165\x63\x74\137\x69\x64"]; if ("\160\x72\157\144\x75\143\x74" !== get_post_type($product_id)) { return new WP_Error("\167\157\x6f\143\157\x6d\x6d\x65\x72\x63\x65\x5f\x72\x65\163\x74\x5f\x70\x72\157\x64\x75\x63\164\137\151\x6e\x76\141\x6c\151\x64\137\151\144", __("\x49\156\166\x61\x6c\x69\x64\40\160\x72\157\x64\x75\x63\x74\40\111\104\x2e", "\x77\x6f\x6f\143\157\x6d\x6d\x65\162\x63\x65"), array("\163\x74\x61\x74\165\x73" => 404)); } $prepared_review = $this->prepare_item_for_database($request); $prepared_review = apply_filters("\x72\145\x73\x74\137\160\162\x65\137\151\x6e\163\x65\162\x74\137\160\x72\x6f\144\x75\x63\x74\137\x72\x65\166\151\x65\x77", $prepared_review, $request); $product_review_id = wp_insert_comment($prepared_review); if (!$product_review_id) { return new WP_Error("\x72\x65\x73\164\x5f\x70\162\x6f\x64\x75\143\164\137\162\145\x76\151\x65\167\x5f\146\x61\151\x6c\x65\144\137\x63\x72\145\141\164\x65", __("\103\x72\x65\x61\x74\x69\156\x67\x20\x70\x72\x6f\x64\165\x63\x74\x20\x72\x65\166\151\145\x77\40\x66\141\x69\x6c\x65\x64\56", "\x77\x6f\x6f\143\157\x6d\x6d\145\x72\143\145"), array("\x73\164\141\164\x75\x73" => 500)); } update_comment_meta($product_review_id, "\162\141\x74\x69\156\x67", !empty($request["\x72\x61\164\151\156\x67"]) ? $request["\162\141\164\151\x6e\147"] : "\60"); $product_review = get_comment($product_review_id); $this->update_additional_fields_for_object($product_review, $request); do_action("\x77\x6f\x6f\x63\x6f\155\x6d\145\162\x63\145\137\x72\145\163\x74\137\151\x6e\163\x65\162\164\x5f\160\162\157\x64\165\x63\x74\137\x72\145\x76\151\145\x77", $product_review, $request, true); $request->set_param("\x63\x6f\156\x74\145\x78\x74", "\x65\144\151\x74"); $response = $this->prepare_item_for_response($product_review, $request); $response = rest_ensure_response($response); $response->set_status(201); $base = str_replace("\x28\77\x50\74\160\162\157\x64\165\143\164\137\151\x64\x3e\x5b\134\144\135\53\51", $product_id, $this->rest_base); $response->header("\x4c\157\143\x61\164\x69\157\156", rest_url(sprintf("\57\45\x73\x2f\x25\163\x2f\x25\x64", $this->namespace, $base, $product_review_id))); return $response; } public function update_item($request) { $product_review_id = (int) $request["\x69\144"]; $product_id = (int) $request["\x70\x72\x6f\144\165\143\164\x5f\151\x64"]; if ("\160\x72\157\x64\165\x63\164" !== get_post_type($product_id)) { return new WP_Error("\167\157\157\143\x6f\155\155\145\162\143\x65\x5f\x72\145\163\x74\x5f\160\x72\157\x64\x75\x63\x74\137\x69\x6e\166\141\154\x69\144\137\151\144", __("\111\x6e\x76\141\x6c\x69\x64\40\160\162\x6f\144\165\143\x74\40\111\x44\56", "\167\157\x6f\143\157\155\155\x65\x72\143\x65"), array("\163\x74\141\x74\165\x73" => 404)); } $review = get_comment($product_review_id); if (empty($product_review_id) || empty($review) || intval($review->comment_post_ID) !== $product_id) { return new WP_Error("\167\x6f\157\x63\157\x6d\x6d\x65\x72\143\145\x5f\162\145\163\164\x5f\160\x72\157\x64\165\x63\164\137\x72\145\x76\x69\x65\x77\137\x69\x6e\x76\x61\154\151\144\x5f\x69\x64", __("\111\156\166\141\154\151\144\40\162\x65\x73\157\165\x72\x63\145\x20\111\x44\56", "\x77\157\157\x63\157\x6d\155\145\x72\143\145"), array("\x73\x74\x61\x74\165\163" => 404)); } $prepared_review = $this->prepare_item_for_database($request); $updated = wp_update_comment($prepared_review); if (0 === $updated) { return new WP_Error("\x72\145\163\164\137\x70\x72\x6f\144\x75\143\164\x5f\162\x65\166\x69\145\167\137\146\141\151\x6c\145\x64\137\x65\x64\x69\x74", __("\125\160\x64\x61\x74\x69\x6e\147\40\x70\162\x6f\x64\x75\x63\x74\x20\162\x65\x76\x69\x65\x77\x20\x66\x61\x69\x6c\145\144\x2e", "\x77\157\x6f\143\x6f\x6d\155\145\x72\x63\145"), array("\x73\164\x61\164\x75\163" => 500)); } if (!empty($request["\162\x61\x74\151\156\147"])) { update_comment_meta($product_review_id, "\162\x61\164\151\156\x67", $request["\162\x61\x74\x69\x6e\x67"]); } $product_review = get_comment($product_review_id); $this->update_additional_fields_for_object($product_review, $request); do_action("\167\x6f\157\x63\x6f\x6d\155\x65\162\143\145\x5f\162\145\x73\x74\x5f\x69\x6e\x73\145\x72\164\x5f\x70\x72\x6f\144\165\143\164\137\162\x65\166\151\x65\167", $product_review, $request, true); $request->set_param("\143\x6f\156\x74\x65\170\x74", "\x65\x64\x69\164"); $response = $this->prepare_item_for_response($product_review, $request); return rest_ensure_response($response); } public function delete_item($request) { $product_id = (int) $request["\x70\x72\157\x64\165\x63\x74\137\x69\x64"]; $product_review_id = (int) $request["\x69\x64"]; $force = isset($request["\x66\x6f\162\143\x65"]) ? (bool) $request["\x66\x6f\162\143\x65"] : false; if ("\x70\162\157\144\x75\143\164" !== get_post_type($product_id)) { return new WP_Error("\x77\x6f\x6f\143\157\155\x6d\x65\x72\143\x65\137\162\x65\x73\164\137\x70\x72\x6f\x64\x75\x63\164\137\x69\156\x76\141\x6c\x69\144\x5f\x69\x64", __("\x49\x6e\x76\x61\154\151\x64\40\160\162\157\x64\x75\x63\164\40\111\104\56", "\x77\157\x6f\143\157\x6d\155\145\162\x63\x65"), array("\x73\x74\141\164\165\x73" => 404)); } $product_review = get_comment($product_review_id); if (empty($product_review_id) || empty($product_review->comment_ID) || empty($product_review->comment_post_ID)) { return new WP_Error("\167\x6f\157\x63\x6f\155\155\x65\x72\x63\x65\x5f\162\145\163\164\x5f\160\x72\x6f\x64\x75\143\x74\x5f\x72\x65\x76\x69\x65\x77\x5f\x69\156\x76\x61\154\151\x64\137\x69\144", __("\111\x6e\x76\x61\x6c\151\x64\x20\x70\x72\x6f\144\165\x63\164\40\x72\x65\166\x69\x65\x77\x20\111\x44\56", "\167\x6f\157\x63\x6f\155\155\x65\x72\143\145"), array("\163\164\x61\x74\x75\x73" => 404)); } $supports_trash = apply_filters("\162\145\x73\164\137\x70\162\157\x64\x75\x63\164\x5f\162\x65\166\151\145\167\x5f\164\x72\x61\163\150\x61\x62\154\145", EMPTY_TRASH_DAYS > 0, $product_review); $request->set_param("\143\x6f\156\x74\x65\170\164", "\x65\144\x69\164"); $response = $this->prepare_item_for_response($product_review, $request); if ($force) { $result = wp_delete_comment($product_review_id, true); } else { if (!$supports_trash) { return new WP_Error("\x72\x65\x73\x74\137\164\x72\x61\163\150\x5f\156\x6f\x74\x5f\163\x75\x70\x70\x6f\x72\x74\145\x64", __("\124\x68\145\40\x70\162\157\144\165\143\x74\40\x72\145\x76\151\145\167\40\144\157\145\x73\x20\x6e\157\x74\x20\x73\165\160\x70\x6f\162\x74\40\164\162\x61\x73\150\151\156\x67\x2e", "\167\157\157\x63\157\x6d\155\x65\162\x63\145"), array("\x73\x74\141\164\165\163" => 501)); } if ("\x74\162\x61\163\x68" === $product_review->comment_approved) { return new WP_Error("\162\145\163\164\137\x61\x6c\162\145\141\x64\x79\137\164\x72\141\163\x68\x65\144", __("\x54\150\145\40\x63\157\155\155\145\x6e\x74\x20\x68\x61\x73\x20\141\x6c\162\x65\141\144\171\40\x62\x65\x65\x6e\40\164\162\141\x73\x68\x65\x64\x2e", "\x77\x6f\157\x63\x6f\x6d\155\145\162\x63\x65"), array("\x73\x74\x61\164\165\163" => 410)); } $result = wp_trash_comment($product_review->comment_ID); } if (!$result) { return new WP_Error("\162\145\x73\164\x5f\143\x61\x6e\156\157\x74\x5f\x64\145\154\145\x74\x65", __("\x54\x68\x65\40\160\162\x6f\144\165\x63\164\x20\x72\x65\x76\151\x65\167\40\x63\x61\x6e\156\x6f\x74\40\142\x65\40\x64\x65\x6c\x65\164\x65\144\x2e", "\x77\x6f\x6f\x63\x6f\155\x6d\x65\162\x63\145"), array("\x73\164\x61\x74\165\163" => 500)); } do_action("\x72\x65\x73\164\x5f\144\145\x6c\145\164\x65\x5f\160\x72\x6f\144\x75\x63\164\x5f\162\145\166\x69\x65\167", $product_review, $response, $request); return $response; } public function prepare_item_for_response($review, $request) { $data = array("\x69\x64" => (int) $review->comment_ID, "\144\x61\x74\145\137\x63\162\145\x61\164\x65\144" => wc_rest_prepare_date_response($review->comment_date_gmt), "\x72\x65\x76\x69\x65\167" => $review->comment_content, "\x72\x61\x74\151\x6e\x67" => (int) get_comment_meta($review->comment_ID, "\162\141\164\151\156\147", true), "\156\141\155\x65" => $review->comment_author, "\145\155\x61\151\154" => $review->comment_author_email, "\166\145\x72\151\x66\x69\x65\144" => wc_review_is_from_verified_owner($review->comment_ID)); $context = !empty($request["\143\x6f\156\164\145\170\164"]) ? $request["\x63\x6f\x6e\164\x65\170\x74"] : "\x76\151\145\167"; $data = $this->add_additional_fields_to_object($data, $request); $data = $this->filter_response_by_context($data, $context); $response = rest_ensure_response($data); $response->add_links($this->prepare_links($review, $request)); return apply_filters("\167\157\x6f\x63\x6f\x6d\x6d\x65\162\143\145\137\x72\145\x73\x74\137\160\162\x65\160\x61\x72\x65\137\160\x72\157\144\x75\143\164\x5f\162\x65\x76\151\x65\167", $response, $review, $request); } protected function prepare_item_for_database($request) { $prepared_review = array("\143\157\155\155\x65\x6e\164\137\141\x70\160\162\x6f\x76\145\x64" => 1, "\x63\157\155\x6d\x65\x6e\164\x5f\164\x79\160\x65" => "\x72\x65\x76\151\145\x77"); if (isset($request["\x69\x64"])) { $prepared_review["\x63\157\155\x6d\x65\x6e\164\x5f\x49\x44"] = (int) $request["\x69\x64"]; } if (isset($request["\162\145\x76\151\x65\x77"])) { $prepared_review["\143\157\155\x6d\145\x6e\164\x5f\143\157\x6e\x74\145\156\164"] = $request["\162\x65\x76\x69\x65\x77"]; } if (isset($request["\160\162\x6f\x64\165\x63\164\137\x69\144"])) { $prepared_review["\x63\x6f\155\x6d\x65\x6e\x74\x5f\x70\157\x73\x74\137\111\x44"] = (int) $request["\x70\x72\157\144\165\143\164\137\151\144"]; } if (isset($request["\x6e\141\155\145"])) { $prepared_review["\143\x6f\x6d\x6d\x65\x6e\x74\x5f\x61\x75\x74\150\x6f\162"] = $request["\156\x61\155\145"]; } if (isset($request["\x65\155\141\151\154"])) { $prepared_review["\143\x6f\155\155\x65\156\164\137\141\x75\164\x68\157\x72\x5f\145\155\141\x69\154"] = $request["\145\x6d\x61\x69\154"]; } if (isset($request["\144\141\164\x65\x5f\143\x72\145\x61\164\145\x64"])) { $prepared_review["\x63\157\x6d\x6d\x65\x6e\164\137\144\141\x74\x65"] = $request["\x64\141\164\x65\137\x63\x72\145\x61\164\x65\144"]; } if (isset($request["\x64\141\x74\145\x5f\x63\162\145\141\164\x65\144\137\147\155\x74"])) { $prepared_review["\143\157\x6d\x6d\x65\156\164\137\144\141\164\145\x5f\147\x6d\164"] = $request["\x64\x61\164\x65\x5f\x63\x72\x65\141\x74\145\144\x5f\147\x6d\x74"]; } return apply_filters("\x72\145\163\x74\x5f\160\x72\145\160\162\x6f\143\145\163\163\137\160\162\x6f\144\x75\x63\164\x5f\x72\x65\166\151\x65\x77", $prepared_review, $request); } protected function prepare_links($review, $request) { $product_id = (int) $request["\160\x72\157\x64\x75\143\164\137\151\144"]; $base = str_replace("\x28\77\x50\x3c\160\x72\157\144\165\143\x74\x5f\x69\x64\x3e\x5b\x5c\144\135\53\x29", $product_id, $this->rest_base); $links = array("\163\x65\154\146" => array("\150\x72\x65\146" => rest_url(sprintf("\x2f\x25\163\57\x25\163\57\45\144", $this->namespace, $base, $review->comment_ID))), "\x63\157\x6c\x6c\145\x63\x74\x69\x6f\x6e" => array("\150\x72\x65\146" => rest_url(sprintf("\x2f\x25\163\x2f\x25\163", $this->namespace, $base))), "\165\160" => array("\x68\x72\145\x66" => rest_url(sprintf("\57\x25\x73\x2f\160\x72\157\x64\165\143\x74\163\57\45\x64", $this->namespace, $product_id)))); return $links; } public function get_item_schema() { $schema = array("\44\163\143\150\x65\x6d\x61" => "\x68\164\164\160\72\x2f\57\152\x73\157\x6e\55\163\143\150\145\x6d\x61\56\157\162\147\57\144\x72\x61\146\164\55\60\x34\57\163\x63\150\x65\155\141\43", "\164\x69\164\154\145" => "\x70\x72\x6f\144\x75\143\x74\x5f\x72\145\166\x69\145\x77", "\x74\171\160\145" => "\157\x62\152\x65\x63\164", "\x70\162\x6f\160\145\162\x74\x69\x65\163" => array("\x69\144" => array("\144\x65\x73\143\x72\x69\160\164\151\157\x6e" => __("\125\156\x69\161\x75\x65\x20\x69\x64\x65\x6e\x74\151\146\151\145\x72\40\146\157\162\40\164\x68\x65\40\x72\145\163\157\x75\162\x63\145\x2e", "\167\157\157\x63\157\155\x6d\x65\162\x63\x65"), "\x74\171\x70\x65" => "\x69\x6e\164\145\x67\x65\x72", "\143\157\156\164\145\170\x74" => array("\x76\x69\x65\167", "\145\x64\151\164"), "\x72\145\x61\144\157\156\x6c\171" => true), "\162\145\166\151\145\167" => array("\x64\x65\163\x63\x72\x69\160\x74\x69\x6f\156" => __("\x54\150\x65\40\x63\x6f\156\x74\x65\x6e\164\x20\157\146\40\164\x68\145\x20\x72\145\166\151\145\167\x2e", "\x77\157\157\143\x6f\x6d\x6d\145\x72\x63\x65"), "\164\x79\160\x65" => "\163\x74\x72\x69\156\147", "\143\157\156\164\x65\x78\164" => array("\166\x69\x65\167", "\145\x64\151\x74")), "\144\x61\164\145\x5f\143\162\145\141\x74\145\144" => array("\x64\x65\x73\143\x72\151\x70\164\x69\x6f\156" => __("\x54\x68\x65\x20\144\141\x74\x65\x20\x74\x68\145\x20\162\x65\166\x69\145\167\40\167\141\163\40\143\162\145\141\164\x65\144\54\40\x69\156\x20\x74\x68\x65\x20\163\151\164\x65\47\163\x20\164\151\x6d\x65\x7a\157\156\x65\56", "\x77\x6f\x6f\143\157\x6d\155\145\x72\143\x65"), "\x74\x79\160\145" => "\144\x61\164\145\x2d\164\x69\155\x65", "\143\x6f\x6e\x74\145\x78\x74" => array("\166\x69\145\167", "\145\x64\151\164")), "\162\x61\x74\x69\156\x67" => array("\x64\x65\163\143\162\x69\x70\x74\151\157\156" => __("\122\x65\x76\x69\145\167\40\x72\141\164\x69\x6e\147\40\50\60\x20\x74\157\x20\65\x29\56", "\167\x6f\157\143\x6f\155\155\x65\162\143\x65"), "\164\171\x70\145" => "\x69\156\164\145\x67\x65\x72", "\143\157\156\164\145\170\164" => array("\166\x69\x65\167", "\145\x64\x69\164")), "\156\141\x6d\145" => array("\144\145\x73\x63\x72\151\x70\x74\151\157\x6e" => __("\x52\145\166\151\x65\x77\x65\162\40\x6e\141\155\x65\x2e", "\x77\x6f\157\x63\x6f\155\x6d\145\162\143\145"), "\164\171\x70\145" => "\x73\164\x72\x69\156\147", "\x63\x6f\x6e\x74\x65\x78\164" => array("\166\x69\145\x77", "\x65\144\x69\164")), "\x65\x6d\141\151\x6c" => array("\144\x65\x73\143\x72\x69\x70\164\x69\x6f\156" => __("\122\x65\166\x69\145\x77\145\x72\40\x65\x6d\141\x69\x6c\x2e", "\x77\157\157\x63\157\155\x6d\x65\x72\143\145"), "\x74\x79\160\x65" => "\163\x74\x72\x69\x6e\147", "\x63\157\x6e\164\x65\170\x74" => array("\x76\151\145\167", "\x65\144\151\164")), "\x76\145\162\151\x66\x69\145\x64" => array("\x64\x65\x73\x63\x72\151\x70\x74\x69\x6f\156" => __("\123\x68\157\167\163\40\x69\x66\40\x74\x68\x65\x20\162\x65\x76\151\x65\167\145\x72\x20\142\x6f\x75\x67\x68\164\40\x74\150\145\x20\x70\162\157\x64\165\143\x74\x20\x6f\162\x20\x6e\157\x74\56", "\x77\157\x6f\x63\157\155\155\145\x72\x63\145"), "\164\x79\160\145" => "\142\x6f\x6f\154\145\x61\156", "\143\157\156\164\145\x78\164" => array("\166\x69\145\x77", "\145\x64\x69\x74"), "\x72\145\x61\144\157\x6e\154\171" => true))); return $this->add_additional_fields_schema($schema); } public function get_collection_params() { return array("\x63\157\156\164\x65\x78\164" => $this->get_context_param(array("\x64\x65\146\141\x75\154\164" => "\166\151\x65\x77"))); } }

Function Calls

defined 1

Variables

None

Stats

MD5 64e30b0ab64aa666e8ecb7308d3e6ace
Eval Count 0
Decode Time 152 ms