PluginProbe
Redirection / 5.2
Redirection v5.2
5.10.0 5.9.0 5.8.1 5.8.0 3.7.2 3.7.3 4.0 4.0.1 4.1 4.1.1 4.2 4.2.1 4.2.2 4.2.3 4.3 4.3.1 4.3.2 4.3.3 4.4 4.4.1 4.4.2 4.5 4.5.1 4.6.2 4.7.1 All 130 releases
← All changes | api/api-settings.php +87 -4 4.35.2 View file →
@@ -1,11 +1,90 @@
1 1 <?php
2 +/**
3 + * @api {get} /redirection/v1/setting Get settings
4 + * @apiName GetSettings
5 + * @apiDescription Get all settings for Redirection. This includes user-configurable settings, as well as necessary WordPress settings.
6 + * @apiGroup Settings
7 + *
8 + * @apiUse SettingItem
9 + * @apiUse 401Error
10 + * @apiUse 404Error
11 + */
2 12
13 +/**
14 + * @api {post} /redirection/v1/setting Update settings
15 + * @apiName UpdateSettings
16 + * @apiDescription Update Redirection settings. Note you can do partial updates, and only the values specified will be changed.
17 + * @apiGroup Settings
18 + *
19 + * @apiParam {Object} settings An object containing all the settings to update
20 + * @apiParamExample {json} settings:
21 + * {
22 + * "expire_redirect": 14,
23 + * "https": false
24 + * }
25 + *
26 + * @apiUse SettingItem
27 + * @apiUse 401Error
28 + * @apiUse 404Error
29 + */
30 +
31 +/**
32 + * @apiDefine SettingItem Settings
33 + * Redirection settings
34 + *
35 + * @apiSuccess {Object[]} settings An object containing all settings
36 + * @apiSuccess {String} settings.expire_redirect
37 + * @apiSuccess {String} settings.token
38 + * @apiSuccess {String} settings.monitor_post
39 + * @apiSuccess {String} settings.monitor_types
40 + * @apiSuccess {String} settings.associated_redirect
41 + * @apiSuccess {String} settings.auto_target
42 + * @apiSuccess {String} settings.expire_redirect
43 + * @apiSuccess {String} settings.expire_404
44 + * @apiSuccess {String} settings.modules
45 + * @apiSuccess {String} settings.newsletter
46 + * @apiSuccess {String} settings.redirect_cache
47 + * @apiSuccess {String} settings.ip_logging
48 + * @apiSuccess {String} settings.last_group_id
49 + * @apiSuccess {String} settings.rest_api
50 + * @apiSuccess {String} settings.https
51 + * @apiSuccess {String} settings.headers
52 + * @apiSuccess {String} settings.database
53 + * @apiSuccess {String} settings.relcoate Relocate this site to the specified domain (and path)
54 + * @apiSuccess {String="www","nowww",""} settings.preferred_domain Preferred canonical domain
55 + * @apiSuccess {String[]} settings.aliases Array of domains that will be redirected to the current WordPress site
56 + * @apiSuccess {Object[]} groups An array of groups
57 + * @apiSuccess {String} groups.label Name of the group
58 + * @apiSuccess {Integer} groups.value Group ID
59 + * @apiSuccess {String} installed The path that WordPress is installed in
60 + * @apiSuccess {Boolean} canDelete True if Redirection can be deleted, false otherwise (on multisite, for example)
61 + * @apiSuccess {String[]} post_types Array of WordPress post types
62 + *
63 + * @apiSuccessExample {json} Success-Response:
64 + * HTTP/1.1 200 OK
65 + * {
66 + * "settings": {
67 + * "expire_redirect": 7,
68 + * "https": true
69 + * },
70 + * "groups": [
71 + * { label: 'My group', value: 5 }
72 + * ],
73 + * "installed": "/var/html/wordpress",
74 + * "canDelete": true,
75 + * "post_types": [
76 + * "post",
77 + * "page"
78 + * ]
79 + * }
80 + */
81 +
3 82 class Redirection_Api_Settings extends Redirection_Api_Route {
4 83 public function __construct( $namespace ) {
5 84 register_rest_route( $namespace, '/setting', array(
6 - $this->get_route( WP_REST_Server::READABLE, 'route_settings' ),
7 - $this->get_route( WP_REST_Server::EDITABLE, 'route_save_settings' ),
85 + $this->get_route( WP_REST_Server::READABLE, 'route_settings', [ $this, 'permission_callback_manage' ] ),
86 + $this->get_route( WP_REST_Server::EDITABLE, 'route_save_settings', [ $this, 'permission_callback_manage' ] ),
8 87 ) );
9 88 }
10 89
11 90 public function route_settings( WP_REST_Request $request ) {
@@ -21,8 +100,12 @@
21 100 'post_types' => red_get_post_types(),
22 101 ];
23 102 }
24 103
104 + public function permission_callback_manage( WP_REST_Request $request ) {
105 + return Redirection_Capabilities::has_access( Redirection_Capabilities::CAP_OPTION_MANAGE ) || Redirection_Capabilities::has_access( Redirection_Capabilities::CAP_SITE_MANAGE );
106 + }
107 +
25 108 public function route_save_settings( WP_REST_Request $request ) {
26 109 $params = $request->get_params();
27 110 $result = true;
28 111
@@ -46,14 +129,14 @@
46 129
47 130 foreach ( $groups as $text => $value ) {
48 131 if ( is_array( $value ) && $depth === 0 ) {
49 132 $items[] = (object) array(
50 - 'text' => $text,
133 + 'label' => $text,
51 134 'value' => $this->groups_to_json( $value, 1 ),
52 135 );
53 136 } else {
54 137 $items[] = (object) array(
55 - 'text' => $value,
138 + 'label' => $value,
56 139 'value' => $text,
57 140 );
58 141 }
59 142 }