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-plugin.php +56 -19 4.05.2 View file →
@@ -5,50 +5,84 @@
5 5 */
6 6 class Redirection_Api_Plugin extends Redirection_Api_Route {
7 7 public function __construct( $namespace ) {
8 8 register_rest_route( $namespace, '/plugin', array(
9 - $this->get_route( WP_REST_Server::READABLE, 'route_status' ),
10 - $this->get_route( WP_REST_Server::EDITABLE, 'route_fixit' ),
9 + $this->get_route( WP_REST_Server::READABLE, 'route_status', [ $this, 'permission_callback_manage' ] ),
11 10 ) );
12 11
12 + register_rest_route( $namespace, '/plugin', array(
13 + $this->get_route( WP_REST_Server::EDITABLE, 'route_fixit', [ $this, 'permission_callback_manage' ] ),
14 + 'args' => [
15 + 'name' => array(
16 + 'description' => 'Name',
17 + 'type' => 'string',
18 + ),
19 + 'value' => array(
20 + 'description' => 'Value',
21 + 'type' => 'string',
22 + ),
23 + ],
24 + ) );
25 +
13 26 register_rest_route( $namespace, '/plugin/delete', array(
14 - $this->get_route( WP_REST_Server::EDITABLE, 'route_delete' ),
27 + $this->get_route( WP_REST_Server::EDITABLE, 'route_delete', [ $this, 'permission_callback_manage' ] ),
15 28 ) );
16 29
17 30 register_rest_route( $namespace, '/plugin/test', array(
18 - $this->get_route( WP_REST_Server::ALLMETHODS, 'route_test' ),
31 + $this->get_route( WP_REST_Server::ALLMETHODS, 'route_test', [ $this, 'permission_callback_manage' ] ),
19 32 ) );
20 33
21 - register_rest_route( $namespace, '/plugin/database', array(
22 - $this->get_route( WP_REST_Server::EDITABLE, 'route_database' ),
23 - 'args' => array(
24 - 'description' => 'Upgrade parameter',
25 - 'type' => 'enum',
26 - 'enum' => array(
27 - 'stop',
28 - 'skip',
29 - ),
30 - ),
34 + register_rest_route( $namespace, '/plugin/data', array(
35 + $this->get_route( WP_REST_Server::EDITABLE, 'route_database', [ $this, 'permission_callback_manage' ] ),
36 + 'args' => [
37 + 'upgrade' => [
38 + 'description' => 'Upgrade parameter',
39 + 'type' => 'string',
40 + 'enum' => array(
41 + 'stop',
42 + 'skip',
43 + ),
44 + ],
45 + ],
31 46 ) );
32 47 }
33 48
49 + public function permission_callback_manage( WP_REST_Request $request ) {
50 + return Redirection_Capabilities::has_access( Redirection_Capabilities::CAP_SUPPORT_MANAGE );
51 + }
52 +
34 53 public function route_status( WP_REST_Request $request ) {
35 54 include_once dirname( REDIRECTION_FILE ) . '/models/fixer.php';
36 55
37 56 $fixer = new Red_Fixer();
38 - return $fixer->get_status();
57 + return $fixer->get_json();
39 58 }
40 59
41 60 public function route_fixit( WP_REST_Request $request ) {
42 61 include_once dirname( REDIRECTION_FILE ) . '/models/fixer.php';
43 62
63 + $params = $request->get_params();
44 64 $fixer = new Red_Fixer();
45 - return $fixer->fix( $fixer->get_status() );
65 +
66 + if ( isset( $params['name'] ) && isset( $params['value'] ) ) {
67 + global $wpdb;
68 +
69 + $fixer->save_debug( $params['name'], $params['value'] );
70 +
71 + $groups = intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ), 10 );
72 + if ( $groups === 0 ) {
73 + Red_Group::create( 'new group', 1 );
74 + }
75 + } else {
76 + $fixer->fix( $fixer->get_status() );
77 + }
78 +
79 + return $fixer->get_json();
46 80 }
47 81
48 82 public function route_delete() {
49 83 if ( is_multisite() ) {
50 - return $this->getError( 'Multisite installations must delete the plugin from the network admin', __LINE__ );
84 + return new WP_Error( 'redirect_delete_multi', 'Multisite installations must delete the plugin from the network admin' );
51 85 }
52 86
53 87 $plugin = Redirection_Admin::init();
54 88 $plugin->plugin_uninstall();
@@ -53,10 +87,13 @@
53 87 $plugin = Redirection_Admin::init();
54 88 $plugin->plugin_uninstall();
55 89
56 90 $current = get_option( 'active_plugins' );
57 - array_splice( $current, array_search( basename( dirname( REDIRECTION_FILE ) ) . '/' . basename( REDIRECTION_FILE ), $current ), 1 );
58 - update_option( 'active_plugins', $current );
91 + $plugin_position = array_search( basename( dirname( REDIRECTION_FILE ) ) . '/' . basename( REDIRECTION_FILE ), $current );
92 + if ( $plugin_position !== false ) {
93 + array_splice( $current, $plugin_position, 1 );
94 + update_option( 'active_plugins', $current );
95 + }
59 96
60 97 return array( 'location' => admin_url() . 'plugins.php' );
61 98 }
62 99