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