Improve hook suffix

This commit is contained in:
Mike Jolley 2019-06-18 13:00:04 +01:00
parent a4e89f89ce
commit 1f6455807d
30 changed files with 11 additions and 257 deletions

View File

@ -49,15 +49,6 @@ abstract class AbstractController extends WP_REST_Controller {
*/
protected $resource_type = '';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = '';
/**
* Register route for items requests.
*
@ -294,17 +285,17 @@ abstract class AbstractController extends WP_REST_Controller {
* @param mixed $item Object used to create response.
* @param \WP_REST_Request $request Request object.
*/
return apply_filters( 'woocommerce_rest_prepare_' . $this->get_hook_suffix( $item ), $response, $item, $request );
return apply_filters( 'woocommerce_rest_prepare_' . $this->get_hook_suffix(), $response, $item, $request );
}
/**
* Return suffix for item action hooks.
*
* @param mixed $item Object used to create response.
* @return string
*/
protected function get_hook_suffix( $item ) {
return $this->singular;
protected function get_hook_suffix() {
$schema = $this->get_item_schema();
return $schema['title'];
}
/**

View File

@ -827,10 +827,9 @@ abstract class AbstractObjectsController extends AbstractController {
/**
* Return suffix for item action hooks.
*
* @param mixed $item Object used to create response.
* @return string
*/
protected function get_hook_suffix( $item ) {
protected function get_hook_suffix() {
return $this->post_type . '_object';
}
}

View File

@ -753,10 +753,9 @@ abstract class AbstractTermsContoller extends AbstractController {
/**
* Return suffix for item action hooks.
*
* @param mixed $item Object used to create response.
* @return string
*/
protected function get_hook_suffix( $item ) {
protected function get_hook_suffix() {
return $this->taxonomy;
}
}

View File

@ -32,15 +32,6 @@ class CustomerDownloads extends AbstractController {
*/
protected $resource_type = 'customers';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'customer_download';
/**
* Register the routes for customers.
*/

View File

@ -34,15 +34,6 @@ class Customers extends AbstractController {
*/
protected $resource_type = 'customers';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'customer';
/**
* Register the routes for customers.
*/

View File

@ -30,15 +30,6 @@ class Data extends AbstractController {
*/
protected $resource_type = 'settings';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'data';
/**
* Register routes.
*

View File

@ -25,15 +25,6 @@ class Continents extends DataController {
*/
protected $rest_base = 'data/continents';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'continent';
/**
* Register routes.
*
@ -234,7 +225,7 @@ class Continents extends DataController {
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_continents',
'title' => 'continent',
'type' => 'object',
'properties' => array(
'code' => array(

View File

@ -25,15 +25,6 @@ class Countries extends DataController {
*/
protected $rest_base = 'data/countries';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'country';
/**
* Register routes.
*
@ -183,7 +174,7 @@ class Countries extends DataController {
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_countries',
'title' => 'country',
'type' => 'object',
'properties' => array(
'code' => array(

View File

@ -25,15 +25,6 @@ class Currencies extends DataController {
*/
protected $rest_base = 'data/currencies';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'currency';
/**
* Register routes.
*/
@ -189,7 +180,7 @@ class Currencies extends DataController {
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_currencies',
'title' => 'currency',
'type' => 'object',
'properties' => array(
'code' => array(

View File

@ -25,15 +25,6 @@ class DownloadIPs extends DataController {
*/
protected $rest_base = 'data/download-ips';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'download_ip';
/**
* Register routes.
*
@ -141,7 +132,7 @@ class DownloadIPs extends DataController {
public function get_item_schema() {
$schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_download_ips',
'title' => 'download_ip',
'type' => 'object',
'properties' => array(
'user_ip_address' => array(

View File

@ -32,15 +32,6 @@ class OrderNotes extends AbstractController {
*/
protected $post_type = 'shop_order';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'order_note';
/**
* Register the routes for order notes.
*/

View File

@ -33,15 +33,6 @@ class PaymentGateways extends AbstractController {
*/
protected $resource_type = 'payment_gateways';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'payment_gateway';
/**
* Register the route for /payment_gateways and /payment_gateways/<id>
*/

View File

@ -37,15 +37,6 @@ class ProductAttributes extends AbstractController {
*/
protected $attribute = '';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_attribute';
/**
* Register the routes for product attributes.
*/

View File

@ -30,15 +30,6 @@ class ProductCategories extends AbstractTermsContoller {
*/
protected $taxonomy = 'product_cat';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_cat';
/**
* Get data for this object in the format of this endpoint's schema.
*

View File

@ -33,15 +33,6 @@ class ProductReviews extends AbstractController {
*/
protected $resource_type = 'product_reviews';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_reviews';
/**
* Register the routes for product reviews.
*/

View File

@ -30,15 +30,6 @@ class ProductShippingClasses extends AbstractTermsContoller {
*/
protected $taxonomy = 'product_shipping_class';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_shipping_class';
/**
* Get data for this object in the format of this endpoint's schema.
*

View File

@ -30,15 +30,6 @@ class ProductTags extends AbstractTermsContoller {
*/
protected $taxonomy = 'product_tag';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_tag';
/**
* Get data for this object in the format of this endpoint's schema.
*

View File

@ -34,15 +34,6 @@ class ProductVariations extends Products {
*/
protected $post_type = 'product_variation';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product_variation';
/**
* Register the routes for products.
*/

View File

@ -41,15 +41,6 @@ class Products extends AbstractObjectsController {
*/
protected $hierarchical = true;
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'product';
/**
* Get the Product's schema, conforming to JSON Schema.
*

View File

@ -30,15 +30,6 @@ class Settings extends AbstractController {
*/
protected $resource_type = 'settings';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'setting';
/**
* Register routes.
*

View File

@ -33,15 +33,6 @@ class SettingsOptions extends AbstractController {
*/
protected $rest_base = 'settings/(?P<group_id>[\w-]+)';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'setting_option';
/**
* Register routes.
*

View File

@ -30,15 +30,6 @@ class ShippingMethods extends AbstractController {
*/
protected $resource_type = 'shipping_methods';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'shipping_method';
/**
* Register the route for /shipping_methods and /shipping_methods/<method>
*/

View File

@ -16,15 +16,6 @@ defined( 'ABSPATH' ) || exit;
*/
class ShippingZoneLocations extends AbstractShippingZonesController {
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'shipping_zone_location';
/**
* Register the routes for Shipping Zone Locations.
*/

View File

@ -19,15 +19,6 @@ use \WooCommerce\RestApi\Controllers\Version4\Utilities\SettingsTrait;
class ShippingZoneMethods extends AbstractShippingZonesController {
use SettingsTrait;
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'shipping_zone_method';
/**
* Register the routes for Shipping Zone Methods.
*/

View File

@ -16,15 +16,6 @@ defined( 'ABSPATH' ) || exit;
*/
class ShippingZones extends AbstractShippingZonesController {
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'shipping_zone';
/**
* Register the routes for Shipping Zones.
*/

View File

@ -30,15 +30,6 @@ class SystemStatus extends AbstractController {
*/
protected $resource_type = 'system_status';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'system_status';
/**
* Register the route for /system_status
*/

View File

@ -30,15 +30,6 @@ class SystemStatusTools extends AbstractController {
*/
protected $resource_type = 'system_status';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'system_status_tool';
/**
* Register the routes for /system_status/tools/*.
*/

View File

@ -30,15 +30,6 @@ class TaxClasses extends AbstractController {
*/
protected $resource_type = 'settings';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'tax_class';
/**
* Register the routes for tax classes.
*/

View File

@ -30,15 +30,6 @@ class Taxes extends AbstractController {
*/
protected $resource_type = 'settings';
/**
* Singular name for resource type.
*
* Used in filter/action names for single resources.
*
* @var string
*/
protected $singular = 'tax';
/**
* Register the routes for taxes.
*/

View File

@ -693,10 +693,9 @@ class Webhooks extends AbstractController {
/**
* Return suffix for item action hooks.
*
* @param mixed $item Object used to create response.
* @return string
*/
protected function get_hook_suffix( $item ) {
protected function get_hook_suffix() {
return $this->post_type;
}
}