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 = ''; 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. * 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 mixed $item Object used to create response.
* @param \WP_REST_Request $request Request object. * @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. * Return suffix for item action hooks.
* *
* @param mixed $item Object used to create response.
* @return string * @return string
*/ */
protected function get_hook_suffix( $item ) { protected function get_hook_suffix() {
return $this->singular; $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. * Return suffix for item action hooks.
* *
* @param mixed $item Object used to create response.
* @return string * @return string
*/ */
protected function get_hook_suffix( $item ) { protected function get_hook_suffix() {
return $this->post_type . '_object'; return $this->post_type . '_object';
} }
} }

View File

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

View File

@ -32,15 +32,6 @@ class CustomerDownloads extends AbstractController {
*/ */
protected $resource_type = 'customers'; 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. * Register the routes for customers.
*/ */

View File

@ -34,15 +34,6 @@ class Customers extends AbstractController {
*/ */
protected $resource_type = 'customers'; 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. * Register the routes for customers.
*/ */

View File

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

View File

@ -25,15 +25,6 @@ class Continents extends DataController {
*/ */
protected $rest_base = 'data/continents'; 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. * Register routes.
* *
@ -234,7 +225,7 @@ class Continents extends DataController {
public function get_item_schema() { public function get_item_schema() {
$schema = array( $schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#', '$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_continents', 'title' => 'continent',
'type' => 'object', 'type' => 'object',
'properties' => array( 'properties' => array(
'code' => array( 'code' => array(

View File

@ -25,15 +25,6 @@ class Countries extends DataController {
*/ */
protected $rest_base = 'data/countries'; 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. * Register routes.
* *
@ -183,7 +174,7 @@ class Countries extends DataController {
public function get_item_schema() { public function get_item_schema() {
$schema = array( $schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#', '$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_countries', 'title' => 'country',
'type' => 'object', 'type' => 'object',
'properties' => array( 'properties' => array(
'code' => array( 'code' => array(

View File

@ -25,15 +25,6 @@ class Currencies extends DataController {
*/ */
protected $rest_base = 'data/currencies'; 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. * Register routes.
*/ */
@ -189,7 +180,7 @@ class Currencies extends DataController {
public function get_item_schema() { public function get_item_schema() {
$schema = array( $schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#', '$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_currencies', 'title' => 'currency',
'type' => 'object', 'type' => 'object',
'properties' => array( 'properties' => array(
'code' => array( 'code' => array(

View File

@ -25,15 +25,6 @@ class DownloadIPs extends DataController {
*/ */
protected $rest_base = 'data/download-ips'; 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. * Register routes.
* *
@ -141,7 +132,7 @@ class DownloadIPs extends DataController {
public function get_item_schema() { public function get_item_schema() {
$schema = array( $schema = array(
'$schema' => 'http://json-schema.org/draft-04/schema#', '$schema' => 'http://json-schema.org/draft-04/schema#',
'title' => 'data_download_ips', 'title' => 'download_ip',
'type' => 'object', 'type' => 'object',
'properties' => array( 'properties' => array(
'user_ip_address' => array( 'user_ip_address' => array(

View File

@ -32,15 +32,6 @@ class OrderNotes extends AbstractController {
*/ */
protected $post_type = 'shop_order'; 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. * Register the routes for order notes.
*/ */

View File

@ -33,15 +33,6 @@ class PaymentGateways extends AbstractController {
*/ */
protected $resource_type = 'payment_gateways'; 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> * Register the route for /payment_gateways and /payment_gateways/<id>
*/ */

View File

@ -37,15 +37,6 @@ class ProductAttributes extends AbstractController {
*/ */
protected $attribute = ''; 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. * Register the routes for product attributes.
*/ */

View File

@ -30,15 +30,6 @@ class ProductCategories extends AbstractTermsContoller {
*/ */
protected $taxonomy = 'product_cat'; 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. * 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'; 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. * Register the routes for product reviews.
*/ */

View File

@ -30,15 +30,6 @@ class ProductShippingClasses extends AbstractTermsContoller {
*/ */
protected $taxonomy = 'product_shipping_class'; 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. * 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'; 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. * 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'; 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. * Register the routes for products.
*/ */

View File

@ -41,15 +41,6 @@ class Products extends AbstractObjectsController {
*/ */
protected $hierarchical = true; 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. * Get the Product's schema, conforming to JSON Schema.
* *

View File

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

View File

@ -33,15 +33,6 @@ class SettingsOptions extends AbstractController {
*/ */
protected $rest_base = 'settings/(?P<group_id>[\w-]+)'; 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. * Register routes.
* *

View File

@ -30,15 +30,6 @@ class ShippingMethods extends AbstractController {
*/ */
protected $resource_type = 'shipping_methods'; 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> * Register the route for /shipping_methods and /shipping_methods/<method>
*/ */

View File

@ -16,15 +16,6 @@ defined( 'ABSPATH' ) || exit;
*/ */
class ShippingZoneLocations extends AbstractShippingZonesController { 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. * Register the routes for Shipping Zone Locations.
*/ */

View File

@ -19,15 +19,6 @@ use \WooCommerce\RestApi\Controllers\Version4\Utilities\SettingsTrait;
class ShippingZoneMethods extends AbstractShippingZonesController { class ShippingZoneMethods extends AbstractShippingZonesController {
use SettingsTrait; 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. * Register the routes for Shipping Zone Methods.
*/ */

View File

@ -16,15 +16,6 @@ defined( 'ABSPATH' ) || exit;
*/ */
class ShippingZones extends AbstractShippingZonesController { 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. * Register the routes for Shipping Zones.
*/ */

View File

@ -30,15 +30,6 @@ class SystemStatus extends AbstractController {
*/ */
protected $resource_type = 'system_status'; 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 * Register the route for /system_status
*/ */

View File

@ -30,15 +30,6 @@ class SystemStatusTools extends AbstractController {
*/ */
protected $resource_type = 'system_status'; 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/*. * Register the routes for /system_status/tools/*.
*/ */

View File

@ -30,15 +30,6 @@ class TaxClasses extends AbstractController {
*/ */
protected $resource_type = 'settings'; 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. * Register the routes for tax classes.
*/ */

View File

@ -30,15 +30,6 @@ class Taxes extends AbstractController {
*/ */
protected $resource_type = 'settings'; 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. * Register the routes for taxes.
*/ */

View File

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