| 1 |
<?php |
| 2 |
|
| 3 |
namespace Yoast\WP\SEO\Routes; |
| 4 |
|
| 5 |
use Yoast\WP\SEO\Actions\Configuration\Configuration_Workout_Action; |
| 6 |
use Yoast\WP\SEO\Conditionals\No_Conditionals; |
| 7 |
use Yoast\WP\SEO\Main; |
| 8 |
|
| 9 |
/** |
| 10 |
* Configuration_Workout_Route class. |
| 11 |
*/ |
| 12 |
class Configuration_Workout_Route implements Route_Interface { |
| 13 |
|
| 14 |
use No_Conditionals; |
| 15 |
|
| 16 |
/** |
| 17 |
* Represents a site representation route. |
| 18 |
* |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
const SITE_REPRESENTATION_ROUTE = '/site_representation'; |
| 22 |
|
| 23 |
/** |
| 24 |
* Represents a social profiles route. |
| 25 |
* |
| 26 |
* @var string |
| 27 |
*/ |
| 28 |
const SOCIAL_PROFILES_ROUTE = '/social_profiles'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Represents a route to enable/disable tracking. |
| 32 |
* |
| 33 |
* @var string |
| 34 |
*/ |
| 35 |
const ENABLE_TRACKING_ROUTE = '/enable_tracking'; |
| 36 |
|
| 37 |
/** |
| 38 |
* The configuration workout action. |
| 39 |
* |
| 40 |
* @var Configuration_Workout_Action; |
| 41 |
*/ |
| 42 |
private $configuration_workout_action; |
| 43 |
|
| 44 |
/** |
| 45 |
* Configuration_Workout_Route constructor. |
| 46 |
* |
| 47 |
* @param Configuration_Workout_Action $configuration_workout_action The configuration workout action. |
| 48 |
*/ |
| 49 |
public function __construct( |
| 50 |
Configuration_Workout_Action $configuration_workout_action |
| 51 |
) { |
| 52 |
$this->configuration_workout_action = $configuration_workout_action; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Registers routes with WordPress. |
| 57 |
* |
| 58 |
* @return void |
| 59 |
*/ |
| 60 |
public function register_routes() { |
| 61 |
$site_representation_route = [ |
| 62 |
'methods' => 'POST', |
| 63 |
'callback' => [ $this, 'set_site_representation' ], |
| 64 |
'permission_callback' => [ $this, 'can_manage_options' ], |
| 65 |
'args' => [ |
| 66 |
'company_or_person' => [ |
| 67 |
'type' => 'string', |
| 68 |
'enum' => [ |
| 69 |
'company', |
| 70 |
'person', |
| 71 |
], |
| 72 |
'required' => true, |
| 73 |
], |
| 74 |
'company_name' => [ |
| 75 |
'type' => 'string', |
| 76 |
], |
| 77 |
'company_logo' => [ |
| 78 |
'type' => 'string', |
| 79 |
], |
| 80 |
'company_logo_id' => [ |
| 81 |
'type' => 'integer', |
| 82 |
], |
| 83 |
'person_logo' => [ |
| 84 |
'type' => 'string', |
| 85 |
], |
| 86 |
'person_logo_id' => [ |
| 87 |
'type' => 'integer', |
| 88 |
], |
| 89 |
'company_or_person_user_id' => [ |
| 90 |
'type' => 'integer', |
| 91 |
], |
| 92 |
'description' => [ |
| 93 |
'type' => 'string', |
| 94 |
], |
| 95 |
], |
| 96 |
]; |
| 97 |
|
| 98 |
\register_rest_route( Main::API_V1_NAMESPACE, Workouts_Route::WORKOUTS_ROUTE . self::SITE_REPRESENTATION_ROUTE, $site_representation_route ); |
| 99 |
|
| 100 |
$social_profiles_route = [ |
| 101 |
'methods' => 'POST', |
| 102 |
'callback' => [ $this, 'set_social_profiles' ], |
| 103 |
'permission_callback' => [ $this, 'can_manage_options' ], |
| 104 |
'args' => [ |
| 105 |
'facebook_site' => [ |
| 106 |
'type' => 'string', |
| 107 |
], |
| 108 |
'twitter_site' => [ |
| 109 |
'type' => 'string', |
| 110 |
], |
| 111 |
'instagram_url' => [ |
| 112 |
'type' => 'string', |
| 113 |
], |
| 114 |
'linkedin_url' => [ |
| 115 |
'type' => 'string', |
| 116 |
], |
| 117 |
'myspace_url' => [ |
| 118 |
'type' => 'string', |
| 119 |
], |
| 120 |
'pinterest_url' => [ |
| 121 |
'type' => 'string', |
| 122 |
], |
| 123 |
'youtube_url' => [ |
| 124 |
'type' => 'string', |
| 125 |
], |
| 126 |
'wikipedia_url' => [ |
| 127 |
'type' => 'string', |
| 128 |
], |
| 129 |
], |
| 130 |
]; |
| 131 |
|
| 132 |
\register_rest_route( Main::API_V1_NAMESPACE, Workouts_Route::WORKOUTS_ROUTE . self::SOCIAL_PROFILES_ROUTE, $social_profiles_route ); |
| 133 |
|
| 134 |
$enable_tracking_route = [ |
| 135 |
'methods' => 'POST', |
| 136 |
'callback' => [ $this, 'set_enable_tracking' ], |
| 137 |
'permission_callback' => [ $this, 'can_manage_options' ], |
| 138 |
'args' => [ |
| 139 |
'tracking' => [ |
| 140 |
'type' => 'boolean', |
| 141 |
'required' => true, |
| 142 |
], |
| 143 |
], |
| 144 |
]; |
| 145 |
|
| 146 |
\register_rest_route( Main::API_V1_NAMESPACE, Workouts_Route::WORKOUTS_ROUTE . self::ENABLE_TRACKING_ROUTE, $enable_tracking_route ); |
| 147 |
} |
| 148 |
|
| 149 |
/** |
| 150 |
* Sets the site representation values. |
| 151 |
* |
| 152 |
* @param \WP_REST_Request $request The request. |
| 153 |
* |
| 154 |
* @return \WP_REST_Response |
| 155 |
*/ |
| 156 |
public function set_site_representation( \WP_REST_Request $request ) { |
| 157 |
$data = $this |
| 158 |
->configuration_workout_action |
| 159 |
->set_site_representation( $request->get_json_params() ); |
| 160 |
|
| 161 |
return new \WP_REST_Response( $data, $data->status ); |
| 162 |
} |
| 163 |
|
| 164 |
/** |
| 165 |
* Sets the social profiles values. |
| 166 |
* |
| 167 |
* @param \WP_REST_Request $request The request. |
| 168 |
* |
| 169 |
* @return \WP_REST_Response |
| 170 |
*/ |
| 171 |
public function set_social_profiles( \WP_REST_Request $request ) { |
| 172 |
$data = $this |
| 173 |
->configuration_workout_action |
| 174 |
->set_social_profiles( $request->get_json_params() ); |
| 175 |
|
| 176 |
return new \WP_REST_Response( $data, $data->status ); |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Enables or disables tracking. |
| 181 |
* |
| 182 |
* @param \WP_REST_Request $request The request. |
| 183 |
* |
| 184 |
* @return \WP_REST_Response |
| 185 |
*/ |
| 186 |
public function set_enable_tracking( \WP_REST_Request $request ) { |
| 187 |
$data = $this |
| 188 |
->configuration_workout_action |
| 189 |
->set_enable_tracking( $request->get_json_params() ); |
| 190 |
|
| 191 |
return new \WP_REST_Response( $data, $data->status ); |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Checks if the current user has the right capability. |
| 196 |
* |
| 197 |
* @return bool |
| 198 |
*/ |
| 199 |
public function can_manage_options() { |
| 200 |
return \current_user_can( 'wpseo_manage_options' ); |
| 201 |
} |
| 202 |
} |
| 203 |
|