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 +20 -49 4.35.2 View file →
@@ -5,13 +5,13 @@
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' ),
9 + $this->get_route( WP_REST_Server::READABLE, 'route_status', [ $this, 'permission_callback_manage' ] ),
10 10 ) );
11 11
12 12 register_rest_route( $namespace, '/plugin', array(
13 - $this->get_route( WP_REST_Server::EDITABLE, 'route_fixit' ),
13 + $this->get_route( WP_REST_Server::EDITABLE, 'route_fixit', [ $this, 'permission_callback_manage' ] ),
14 14 'args' => [
15 15 'name' => array(
16 16 'description' => 'Name',
17 17 'type' => 'string',
@@ -23,64 +23,32 @@
23 23 ],
24 24 ) );
25 25
26 26 register_rest_route( $namespace, '/plugin/delete', array(
27 - $this->get_route( WP_REST_Server::EDITABLE, 'route_delete' ),
27 + $this->get_route( WP_REST_Server::EDITABLE, 'route_delete', [ $this, 'permission_callback_manage' ] ),
28 28 ) );
29 29
30 30 register_rest_route( $namespace, '/plugin/test', array(
31 - $this->get_route( WP_REST_Server::ALLMETHODS, 'route_test' ),
31 + $this->get_route( WP_REST_Server::ALLMETHODS, 'route_test', [ $this, 'permission_callback_manage' ] ),
32 32 ) );
33 33
34 - register_rest_route( $namespace, '/plugin/post', array(
35 - $this->get_route( WP_REST_Server::READABLE, 'route_match_post' ),
34 + register_rest_route( $namespace, '/plugin/data', array(
35 + $this->get_route( WP_REST_Server::EDITABLE, 'route_database', [ $this, 'permission_callback_manage' ] ),
36 36 'args' => [
37 - 'text' => [
38 - 'description' => 'Text to match',
37 + 'upgrade' => [
38 + 'description' => 'Upgrade parameter',
39 39 'type' => 'string',
40 + 'enum' => array(
41 + 'stop',
42 + 'skip',
43 + ),
40 44 ],
41 45 ],
42 46 ) );
43 -
44 - register_rest_route( $namespace, '/plugin/database', array(
45 - $this->get_route( WP_REST_Server::EDITABLE, 'route_database' ),
46 - 'args' => array(
47 - 'description' => 'Upgrade parameter',
48 - 'type' => 'enum',
49 - 'enum' => array(
50 - 'stop',
51 - 'skip',
52 - ),
53 - ),
54 - ) );
55 47 }
56 48
57 - public function route_match_post( WP_REST_Request $request ) {
58 - $params = $request->get_params();
59 - $search = isset( $params['text'] ) ? $params['text'] : false;
60 - $results = [];
61 -
62 - if ( $search ) {
63 - global $wpdb;
64 -
65 - $posts = $wpdb->get_results(
66 - $wpdb->prepare(
67 - "SELECT ID,post_title,post_name FROM $wpdb->posts WHERE post_status='publish' AND (post_title LIKE %s OR post_name LIKE %s) " .
68 - "AND post_type NOT IN ('nav_menu_item','wp_block','oembed_cache')",
69 - '%' . $wpdb->esc_like( $search ) . '%', '%' . $wpdb->esc_like( $search ) . '%'
70 - )
71 - );
72 -
73 - foreach ( (array) $posts as $post ) {
74 - $results[] = [
75 - 'title' => $post->post_title,
76 - 'slug' => $post->post_name,
77 - 'url' => get_permalink( $post->ID ),
78 - ];
79 - }
80 - }
81 -
82 - return $results;
49 + public function permission_callback_manage( WP_REST_Request $request ) {
50 + return Redirection_Capabilities::has_access( Redirection_Capabilities::CAP_SUPPORT_MANAGE );
83 51 }
84 52
85 53 public function route_status( WP_REST_Request $request ) {
86 54 include_once dirname( REDIRECTION_FILE ) . '/models/fixer.php';
@@ -112,9 +80,9 @@
112 80 }
113 81
114 82 public function route_delete() {
115 83 if ( is_multisite() ) {
116 - 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' );
117 85 }
118 86
119 87 $plugin = Redirection_Admin::init();
120 88 $plugin->plugin_uninstall();
@@ -119,10 +87,13 @@
119 87 $plugin = Redirection_Admin::init();
120 88 $plugin->plugin_uninstall();
121 89
122 90 $current = get_option( 'active_plugins' );
123 - array_splice( $current, array_search( basename( dirname( REDIRECTION_FILE ) ) . '/' . basename( REDIRECTION_FILE ), $current ), 1 );
124 - 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 + }
125 96
126 97 return array( 'location' => admin_url() . 'plugins.php' );
127 98 }
128 99