Skip to content

Commit

Permalink
fix: standardize REST API namespace usage
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiulodro committed Mar 9, 2020
1 parent 3a3d7e3 commit 44d15b2
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 78 deletions.
2 changes: 1 addition & 1 deletion includes/api/class-plugins-controller.php
Expand Up @@ -25,7 +25,7 @@ class Plugins_Controller extends WP_REST_Controller {
*
* @var string
*/
protected $namespace = '/newspack/v1';
protected $namespace = NEWSPACK_API_NAMESPACE;

/**
* Endpoint resource.
Expand Down
2 changes: 1 addition & 1 deletion includes/api/class-wizards-controller.php
Expand Up @@ -23,7 +23,7 @@ class Wizards_Controller extends WP_REST_Controller {
*
* @var string
*/
protected $namespace = '/newspack/v1';
protected $namespace = NEWSPACK_API_NAMESPACE;

/**
* Endpoint resource.
Expand Down
4 changes: 2 additions & 2 deletions includes/class-profile.php
Expand Up @@ -83,7 +83,7 @@ public static function newspack_update_option( $key, $value ) {
public function register_api_endpoints() {
// Get profile data.
register_rest_route(
'newspack/v1/',
NEWSPACK_API_NAMESPACE,
'/profile/',
[
'methods' => WP_REST_Server::READABLE,
Expand All @@ -94,7 +94,7 @@ public function register_api_endpoints() {

// Update profile data.
register_rest_route(
'newspack/v1/',
NEWSPACK_API_NAMESPACE,
'/profile/',
[
'methods' => WP_REST_Server::EDITABLE,
Expand Down
2 changes: 2 additions & 0 deletions includes/util.php
Expand Up @@ -9,6 +9,8 @@

defined( 'ABSPATH' ) || exit;

define( 'NEWSPACK_API_NAMESPACE', 'newspack/v1' );

/**
* Clean variables using sanitize_text_field. Arrays are cleaned recursively.
* Non-scalar values are ignored.
Expand Down
32 changes: 16 additions & 16 deletions includes/wizards/class-advertising-wizard.php
Expand Up @@ -104,8 +104,8 @@ public function register_api_endpoints() {

// Get all Newspack advertising data.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_advertising' ],
Expand All @@ -115,8 +115,8 @@ public function register_api_endpoints() {

// Update header code.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/service/(?P<service>[\a-z]+)/network_code',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/service/(?P<service>[\a-z]+)/network_code',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_network_code' ],
Expand All @@ -134,8 +134,8 @@ public function register_api_endpoints() {

// Enable one service.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/service/(?P<service>[\a-z]+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/service/(?P<service>[\a-z]+)',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_enable_service' ],
Expand All @@ -150,8 +150,8 @@ public function register_api_endpoints() {

// Disable one service.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/service/(?P<service>[\a-z]+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/service/(?P<service>[\a-z]+)',
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'api_disable_service' ],
Expand All @@ -166,8 +166,8 @@ public function register_api_endpoints() {

// Update placement.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/placement/(?P<placement>[\a-z]+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/placement/(?P<placement>[\a-z]+)',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_placement' ],
Expand All @@ -182,8 +182,8 @@ public function register_api_endpoints() {

// Disable placement.
register_rest_route(
'newspack/v1/wizard/',
'/advertising/placement/(?P<placement>[\a-z]+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/placement/(?P<placement>[\a-z]+)',
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'api_disable_placement' ],
Expand All @@ -198,8 +198,8 @@ public function register_api_endpoints() {

// Save a ad unit.
\register_rest_route(
'newspack/v1/wizard/',
'/advertising/ad_unit/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/ad_unit/(?P<id>\d+)',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_adunit' ],
Expand Down Expand Up @@ -227,8 +227,8 @@ public function register_api_endpoints() {

// Delete a ad unit.
\register_rest_route(
'newspack/v1/wizard/',
'/advertising/ad_unit/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/advertising/ad_unit/(?P<id>\d+)',
[
'methods' => 'DELETE',
'callback' => [ $this, 'api_delete_adunit' ],
Expand Down
20 changes: 10 additions & 10 deletions includes/wizards/class-engagement-wizard.php
Expand Up @@ -72,17 +72,17 @@ public function get_length() {
*/
public function register_api_endpoints() {
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'engagement',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/engagement',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_engagement_settings' ],
'permission_callback' => [ $this, 'api_permissions_check' ],
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'popup/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/popup/(?P<id>\d+)',
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'api_delete_popup' ],
Expand All @@ -95,8 +95,8 @@ public function register_api_endpoints() {
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'sitewide-popup/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/sitewide-popup/(?P<id>\d+)',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_set_sitewide_popup' ],
Expand All @@ -109,8 +109,8 @@ public function register_api_endpoints() {
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'sitewide-popup/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/sitewide-popup/(?P<id>\d+)',
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'api_unset_sitewide_popup' ],
Expand All @@ -123,8 +123,8 @@ public function register_api_endpoints() {
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'popup-categories/(?P<id>\d+)',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/popup-categories/(?P<id>\d+)',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_set_popup_categories' ],
Expand Down
12 changes: 6 additions & 6 deletions includes/wizards/class-health-check-wizard.php
Expand Up @@ -73,17 +73,17 @@ public function get_length() {
*/
public function register_api_endpoints() {
register_rest_route(
'newspack/v1/wizard/',
$this->slug,
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug,
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_health_data' ],
'permission_callback' => [ $this, 'api_permissions_check' ],
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'repair/(?P<configuration>[\a-z]+)/',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/repair/(?P<configuration>[\a-z]+)/',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_repair_configuration' ],
Expand All @@ -96,8 +96,8 @@ public function register_api_endpoints() {
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'unsupported_plugins',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/unsupported_plugins',
[
'methods' => \WP_REST_Server::DELETABLE,
'callback' => [ $this, 'api_delete_unsupported_plugins' ],
Expand Down
8 changes: 4 additions & 4 deletions includes/wizards/class-payment-wizard.php
Expand Up @@ -53,8 +53,8 @@ public function register_api_endpoints() {

// Get data about Stripe customer/subscription.
register_rest_route(
'newspack/v1/wizard/',
'/newspack-payment-wizard/',
NEWSPACK_API_NAMESPACE,
'/wizard/newspack-payment-wizard/',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_stripe_data' ],
Expand All @@ -64,8 +64,8 @@ public function register_api_endpoints() {

// Create a Stripe checkout session, return information needed to redirect to it.
register_rest_route(
'newspack/v1/wizard/',
'/newspack-payment-wizard/checkout',
NEWSPACK_API_NAMESPACE,
'/wizard/newspack-payment-wizard/checkout',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_stripe_checkout_id' ],
Expand Down
8 changes: 4 additions & 4 deletions includes/wizards/class-performance-wizard.php
Expand Up @@ -70,17 +70,17 @@ public function get_length() {
*/
public function register_api_endpoints() {
register_rest_route(
'newspack/v1/wizard/',
'/performance/',
NEWSPACK_API_NAMESPACE,
'/wizard/performance/',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_settings' ],
'permission_callback' => [ $this, 'api_permissions_check' ],
]
);
register_rest_route(
'newspack/v1/wizard/',
'/performance/',
NEWSPACK_API_NAMESPACE,
'/wizard/performance/',
[
'methods' => \WP_REST_Server::CREATABLE,
'callback' => [ $this, 'api_update_settings' ],
Expand Down
20 changes: 10 additions & 10 deletions includes/wizards/class-reader-revenue-wizard.php
Expand Up @@ -74,8 +74,8 @@ public function register_api_endpoints() {

// Get all data required to render the Wizard.
\register_rest_route(
'newspack/v1/wizard/',
$this->slug,
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug,
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_fetch' ],
Expand All @@ -85,8 +85,8 @@ public function register_api_endpoints() {

// Save location info.
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'/location/',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/location/',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_location' ],
Expand Down Expand Up @@ -121,8 +121,8 @@ public function register_api_endpoints() {

// Save Stripe info.
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'/stripe/',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/stripe/',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_stripe_settings' ],
Expand Down Expand Up @@ -152,8 +152,8 @@ public function register_api_endpoints() {

// Save a subscription.
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'/donations/',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . '/donations/',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_donation_settings' ],
Expand Down Expand Up @@ -182,8 +182,8 @@ public function register_api_endpoints() {
);

register_rest_route(
'newspack/v1/wizard/newspack-donations-wizard/',
'/donation/',
NEWSPACK_API_NAMESPACE,
'/wizard/newspack-donations-wizard/donation/',
[
'methods' => 'GET',
'callback' => [ $this, 'api_get_donation_settings' ],
Expand Down
8 changes: 4 additions & 4 deletions includes/wizards/class-seo-wizard.php
Expand Up @@ -72,17 +72,17 @@ public function get_length() {
*/
public function register_api_endpoints() {
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'settings',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . 'settings',
[
'methods' => \WP_REST_Server::READABLE,
'callback' => [ $this, 'api_get_seo_settings' ],
'permission_callback' => [ $this, 'api_permissions_check' ],
]
);
register_rest_route(
'newspack/v1/wizard/' . $this->slug,
'settings',
NEWSPACK_API_NAMESPACE,
'/wizard/' . $this->slug . 'settings',
[
'methods' => \WP_REST_Server::EDITABLE,
'callback' => [ $this, 'api_update_seo_settings' ],
Expand Down

0 comments on commit 44d15b2

Please sign in to comment.