Changeset 2021642
- Timestamp:
- 01/30/2019 05:56:12 AM (7 years ago)
- Location:
- wp-dashboard/trunk
- Files:
-
- 3 added
- 5 edited
-
api/class-wpdashboard-api-base.php (modified) (1 diff)
-
api/class-wpdashboard-plugin-routes-template.php (added)
-
api/class-wpdashboard-plugin-routes.php (added)
-
api/lib/class-wpdashboard-plugins.php (modified) (15 diffs)
-
includes/class-wpdashboard.php (modified) (2 diffs)
-
webhooks/class-wpdashboard-webhooks.php (modified) (4 diffs)
-
webhooks/lib/class-wpdashboard-plugins.php (modified) (1 diff)
-
webhooks/lib/class-wpdashboard-posts.php (added)
Legend:
- Unmodified
- Added
- Removed
-
wp-dashboard/trunk/api/class-wpdashboard-api-base.php
r1824830 r2021642 57 57 58 58 public function init() { 59 // Silence is Golden 59 60 60 } 61 61 -
wp-dashboard/trunk/api/lib/class-wpdashboard-plugins.php
r1824829 r2021642 26 26 require_once 'class-wp-upgrade-skin.php'; 27 27 28 class WpDashboard_Api_Plugins extends WpDashboard_Api_Base { 28 class WpDashboard_Api_Plugins extends WP_REST_Controller 29 { 29 30 30 31 /** … … 35 36 public function __construct($plugin_name, $version) 36 37 { 37 38 parent::__construct($plugin_name, $version); 38 $this::register_routes(); 39 39 } 40 40 … … 43 43 * @return array 44 44 */ 45 public function get_all_plugins(WP_REST_Request $request) { 45 public function get_all_plugins(WP_REST_Request $request) 46 { 46 47 $plugins = get_plugins(); 47 48 return $plugins; … … 52 53 * @return array|WP_Error 53 54 */ 54 public function install_plugin(WP_REST_Request $request) { 55 $plugin = $request->get_param('plugin'); 56 if($this->check_plugin_installed($plugin)) { 55 public function install_plugin(WP_REST_Request $request) 56 { 57 $plugin = $request->get_param('plugin'); 58 if ($this->check_plugin_installed($plugin)) { 57 59 $error = new WP_Error('plugin_already_installed', 'The plugin is already installed on the site.', ['plugin' => $plugin]); 58 60 return $error; 59 61 } 60 62 $plugin_slug = explode('/', $plugin)[0]; 61 $api = plugins_api( 'plugin_information', array(63 $api = plugins_api('plugin_information', array( 62 64 'slug' => $plugin_slug, 63 65 'fields' => array( … … 75 77 'donate_link' => false, 76 78 ), 77 ) );78 if (is_wp_error($api)) {79 )); 80 if (is_wp_error($api)) { 79 81 $error = new WP_Error('plugin_not_found', 'The plugin was not found in the WordPress repository.', ['plugin' => $plugin]); 80 82 return $error; 81 83 } 82 84 $skin = new WPDashboardUpdateSkin(); 83 $upgrader = new Plugin_Upgrader( $skin);85 $upgrader = new Plugin_Upgrader($skin); 84 86 $install = $upgrader->install($api->download_link); 85 if ($install) {86 return [87 if ($install) { 88 return [ 87 89 'plugin' => $plugin, 88 90 'installed' => true … … 98 100 * @return array|bool|string|WP_Error 99 101 */ 100 public function update_plugin(WP_REST_Request $request) { 102 public function update_plugin(WP_REST_Request $request) 103 { 101 104 $skin = new WPDashboardUpdateSkin(); 102 $current = get_site_transient( 'update_plugins');103 $upgrader = new Plugin_Upgrader( $skin);105 $current = get_site_transient('update_plugins'); 106 $upgrader = new Plugin_Upgrader($skin); 104 107 $file = null; 105 108 $info = null; 106 foreach ($current->response AS $f => $i) {107 if ($f == $request->get_param('plugin')) {109 foreach ($current->response AS $f => $i) { 110 if ($f == $request->get_param('plugin')) { 108 111 $file = $f; 109 112 $info = $i; … … 112 115 } 113 116 $update = $this->do_plugin_upgrade($upgrader, $file, $info); 114 if ($update) {115 return [$file => $skin->result, 'update_info' => $update];117 if ($update) { 118 return [$file => $skin->result, 'update_info' => $update]; 116 119 } else { 117 120 return $skin->result; … … 123 126 * @return array|null|WP_Error 124 127 */ 125 public function activate_plugin(WP_REST_Request $request) { 126 $plugin = $request->get_param('plugin'); 127 if(!$this->check_plugin_status($plugin)) { 128 public function activate_plugin(WP_REST_Request $request) 129 { 130 $plugin = $request->get_param('plugin'); 131 if (!$this->check_plugin_status($plugin)) { 128 132 $activate = activate_plugin($plugin); 129 if ( is_wp_error( $activate )) {133 if (is_wp_error($activate)) { 130 134 return $activate; 131 135 } else { … … 145 149 * @return array|WP_Error 146 150 */ 147 public function deactivate_plugin(WP_REST_Request $request) { 148 $plugin = $request->get_param('plugin'); 149 if($this->check_plugin_status($plugin)) { 151 public function deactivate_plugin(WP_REST_Request $request) 152 { 153 $plugin = $request->get_param('plugin'); 154 if ($this->check_plugin_status($plugin)) { 150 155 deactivate_plugins($plugin); 151 156 return [ … … 163 168 * @return array|bool|null|WP_Error 164 169 */ 165 public function delete_plugin(WP_REST_Request $request) { 166 $plugin = $request->get_param('plugin'); 167 if($this->check_plugin_status($plugin)) { 170 public function delete_plugin(WP_REST_Request $request) 171 { 172 $plugin = $request->get_param('plugin'); 173 if ($this->check_plugin_status($plugin)) { 168 174 $error = new WP_Error('plugin_is_active', 'Your plugin is active, you must deactivate it before deleting it.', ['plugin' => $plugin]); 169 175 return $error; … … 171 177 $uninstall = uninstall_plugin($plugin); 172 178 $delete = delete_plugins([$plugin]); 173 if ( is_wp_error( $delete )) {179 if (is_wp_error($delete)) { 174 180 return $delete; 175 181 } else { … … 185 191 * @return bool 186 192 */ 187 protected function check_plugin_status($plugin) { 193 protected function check_plugin_status($plugin) 194 { 188 195 return is_plugin_active($plugin); 189 196 } … … 193 200 * @return bool 194 201 */ 195 protected function check_plugin_installed($check) { 202 protected function check_plugin_installed($check) 203 { 196 204 $plugins = get_plugins(); 197 foreach ($plugins AS $f => $i) {198 if ($f == $check) {205 foreach ($plugins AS $f => $i) { 206 if ($f == $check) { 199 207 return true; 200 208 } … … 209 217 * @return null 210 218 */ 211 protected function do_plugin_upgrade($upgrader, $file, $info) { 212 if($upgrader == null || $file == null || $info == null) { 219 protected function do_plugin_upgrade($upgrader, $file, $info) 220 { 221 if ($upgrader == null || $file == null || $info == null) { 213 222 return null; 214 223 } else { … … 226 235 } 227 236 } 228 229 237 } -
wp-dashboard/trunk/includes/class-wpdashboard.php
r2020673 r2021642 119 119 120 120 /** 121 * The class responsible for defining all actions that occur in the api.122 */ 123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard- api.php';121 * The classes responsible for defining all actions that occur in the api. 122 */ 123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-plugin-routes.php'; 124 124 125 125 /** … … 199 199 */ 200 200 private function define_api_hooks() { 201 202 $plugin_api = new Wpdashboard_Api( $this->get_plugin_name(), $this->get_version() ); 203 204 $this->loader->add_action( 'parse_request', $plugin_api, 'detect_api_request' ); 205 206 $this->loader->add_action( 'parse_request', $plugin_api, 'detect_redirects' ); 207 201 $api = new WpDashboard_Plugin_Routes( $this->get_plugin_name(), $this->get_version() ); 202 $this->loader->add_action( 'rest_api_init', $api, 'register_routes' ); 208 203 $webhook_api = new Wpdashboard_WebHooks( $this->get_plugin_name(), $this->get_version() ); 209 210 204 $webhook_api->init(); 211 212 205 } 213 206 -
wp-dashboard/trunk/webhooks/class-wpdashboard-webhooks.php
r2020684 r2021642 25 25 */ 26 26 require_once 'lib/class-wpdashboard-plugins.php'; 27 require_once 'lib/class-wpdashboard-posts.php'; 27 28 require_once 'lib/class-wpdashboard-themes.php'; 28 29 require_once 'lib/class-wpdashboard-users.php'; … … 34 35 use Wpdashboard_Themes; 35 36 use Wpdashboard_Users; 37 use Wpdashboard_Posts; 36 38 use Wpdashboard_Wordpress; 37 39 … … 80 82 */ 81 83 82 // private $url = 'https://my.wpdashboard.io/api/site/'; 83 private $url = 'https://beta.wpdashboard.io/api/site/'; 84 // private $url = 'http://wpdashboard.io.test/api/site/'; 84 // private $url = 'https://my.wpdashboard.io/api/v2/site/'; 85 private $url = 'http://wpdashboard.io.test/api/site/'; 85 86 86 87 /** … … 114 115 $this->initUsers(); 115 116 $this->initWordpress(); 117 $this->initPosts(); 116 118 } 117 119 -
wp-dashboard/trunk/webhooks/lib/class-wpdashboard-plugins.php
r2020673 r2021642 124 124 */ 125 125 public function plugin_updated($upgrader, $hook) { 126 if($hook['type'] == 'plugin' ) {126 if($hook['type'] == 'plugin' && $hook['action'] != 'install') { 127 127 foreach($hook['plugins'] AS $p) { 128 128 $plugin = get_plugin_data(ABSPATH . 'wp-content/plugins/' . $p);
Note: See TracChangeset
for help on using the changeset viewer.