Changeset 2022347
- Timestamp:
- 01/31/2019 01:03:01 AM (7 years ago)
- Location:
- wp-dashboard/trunk
- Files:
-
- 3 edited
-
api/class-wpdashboard-plugin-routes.php (modified) (4 diffs)
-
webhooks/class-wpdashboard-webhooks.php (modified) (1 diff)
-
webhooks/lib/class-wpdashboard-plugins.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wp-dashboard/trunk/api/class-wpdashboard-plugin-routes.php
r2021642 r2022347 86 86 $namespace = $this->plugin_name . '/v' . $version; 87 87 $base = 'plugin'; 88 register_rest_route( $namespace, '/' . $base . '', array( 89 array( 90 'methods' => WP_REST_Server::READABLE, 91 'callback' => array( $this, 'get_plugins' ), 92 'permission_callback' => array( $this, 'permission_check' ), 93 'args' => [ 94 95 ] 96 ), 97 ) ); 88 98 register_rest_route( $namespace, '/' . $base . '/install', array( 89 99 array( … … 106 116 ), 107 117 ) ); 118 register_rest_route( $namespace, '/' . $base . '/update', array( 119 array( 120 'methods' => WP_REST_Server::CREATABLE, 121 'callback' => array( $this, 'update_plugin' ), 122 'permission_callback' => array( $this, 'permission_check' ), 123 'args' => [ 124 125 ] 126 ), 127 ) ); 108 128 register_rest_route( $namespace, '/' . $base . '/deactivate', array( 109 129 array( … … 126 146 ), 127 147 ) ); 148 } 149 150 /** 151 * Get Plugins 152 * 153 * Get the plugins if authenticated 154 * to do so. 155 * 156 * @param WP_REST_Request $request Full data about the request. 157 * 158 * @return WP_Error|WP_REST_Response 159 */ 160 public function get_plugins( $request ) { 161 162 $this->required(); 163 $plugins = get_plugins(); 164 foreach($plugins AS $plugin => $info) { 165 $plugins[$plugin]['Active'] = is_plugin_active($plugin); 166 } 167 return new WP_REST_Response($plugins); 168 128 169 } 129 170 … … 217 258 218 259 /** 260 * Update Plugin 261 * 262 * Updates the plugin on 263 * the site. 264 * 265 * @since 2.0.0 266 * 267 * @param WP_REST_Request $request 268 * 269 * @return WP_Error|WP_REST_Response 270 */ 271 public function update_plugin($request) 272 { 273 $this->required(); 274 $skin = new WPDashboardUpdateSkin(); 275 $current = get_site_transient('update_plugins'); 276 $upgrader = new Plugin_Upgrader($skin); 277 $file = null; 278 $info = null; 279 foreach ($current->response AS $f => $i) { 280 if ($f == $request->get_param('plugin')) { 281 $file = $f; 282 $info = $i; 283 break; 284 } 285 } 286 if ($upgrader == null || $file == null || $info == null) { 287 $update = null; 288 } else { 289 $update = $upgrader->run(array( 290 'package' => $info->package, 291 'destination' => WP_PLUGIN_DIR, 292 'clear_destination' => true, 293 'clear_working' => true, 294 'hook_extra' => array( 295 'plugin' => $file, 296 'type' => 'plugin', 297 'action' => 'update', 298 ), 299 )); 300 } 301 if ($update) { 302 return new WP_REST_Response([$file => $skin->result, 'update_info' => $update]); 303 } else { 304 return $skin->result; 305 } 306 } 307 308 /** 219 309 * Deactivate Plugin 220 310 * -
wp-dashboard/trunk/webhooks/class-wpdashboard-webhooks.php
r2021642 r2022347 83 83 84 84 // private $url = 'https://my.wpdashboard.io/api/v2/site/'; 85 private $url = 'http://wpdashboard.io.test/api/site/'; 85 // private $url = 'http://wpdashboard.io.test/api/site/'; 86 private $url = 'https://beta.wpdashboard.io/api/site/'; 86 87 87 88 /** -
wp-dashboard/trunk/webhooks/lib/class-wpdashboard-plugins.php
r2021642 r2022347 41 41 add_action( 'upgrader_process_complete', [$this, 'plugin_installed'], 10, 2); 42 42 add_action( 'activated_plugin', [$this, 'plugin_activated'], 10, 2); 43 // add_action( 'set_site_transient_update_plugins', [$this, 'plugin_has_updates'], 10, 3); 44 add_filter( "pre_set_site_transient_update_plugins", [$this, 'plugin_has_updates'], 10, 2 ); 45 add_action( 'upgrader_process_complete', [$this, 'plugin_updated'], 10, 2); 43 46 add_action( 'deactivated_plugin', [$this, 'plugin_deactivated'], 10, 2); 44 add_action( 'upgrader_process_complete', [$this, 'plugin_updated'], 10, 2);45 47 add_action( 'deleted_plugin', [$this, 'plugin_deleted'], 10, 2); 46 48 } … … 93 95 94 96 /** 97 * Plugin Has Updates 98 * 99 * Fires when a plugin has updates 100 * available to it. 101 * 102 * @since 2.0.0 103 * 104 * @param $transient 105 * @param $value 106 * 107 * @return mixed 108 */ 109 public function plugin_has_updates($value, $transient) { 110 if(isset($value->response)) { 111 foreach ($value->response AS $plugin => $update) { 112 $p = get_plugin_data(ABSPATH . 'wp-content/plugins/' . $plugin); 113 $body = [ 114 'plugin' => $plugin, 115 'name' => $p['Name'], 116 'version' => $p['Version'], 117 'description' => $p['Description'], 118 'new_version' => $update->new_version, 119 ]; 120 if(isset($update->icons['2x'])) { 121 $body['icon'] = $update->icons['2x']; 122 } 123 $this->post('plugin/has-update', $body); 124 } 125 } 126 return $value; 127 } 128 129 /** 130 * Plugin Updated 131 * 132 * Fires when a plugin is updated. 133 * 134 * @since 2.0.0 135 * 136 * @param $plugin 137 * @param $network_deactivation 138 */ 139 public function plugin_updated($upgrader, $hook) { 140 if($hook['type'] == 'plugin' && $hook['action'] != 'install') { 141 if(!isset($hook['plugins'])) { 142 $plugin = get_plugin_data(ABSPATH . 'wp-content/plugins/' . $hook['plugin']); 143 $body = [ 144 'action' => $hook['action'], 145 'plugin' => $hook['plugin'], 146 'name' => $plugin['Name'], 147 'version' => $plugin['Version'], 148 'description' => $plugin['Description'], 149 ]; 150 $this->post('plugin/update', $body); 151 } else { 152 foreach ($hook['plugins'] AS $p) { 153 $plugin = get_plugin_data(ABSPATH . 'wp-content/plugins/' . $p); 154 $body = [ 155 'action' => $hook['action'], 156 'plugin' => $p, 157 'name' => $plugin['Name'], 158 'version' => $plugin['Version'], 159 'description' => $plugin['Description'], 160 ]; 161 $this->post('plugin/update', $body); 162 } 163 } 164 } 165 } 166 167 /** 95 168 * Plugin Deactivated 96 169 * … … 114 187 115 188 /** 116 * Plugin Updated117 *118 * Fires when a plugin is updated.119 *120 * @since 2.0.0121 *122 * @param $plugin123 * @param $network_deactivation124 */125 public function plugin_updated($upgrader, $hook) {126 if($hook['type'] == 'plugin' && $hook['action'] != 'install') {127 foreach($hook['plugins'] AS $p) {128 $plugin = get_plugin_data(ABSPATH . 'wp-content/plugins/' . $p);129 $body = [130 'action' => $hook['action'],131 'plugin' => $p,132 'name' => $plugin['Name'],133 'version' => $plugin['Version'],134 'description' => $plugin['Description'],135 ];136 $this->post('plugin/update', $body);137 }138 }139 }140 141 /**142 189 * Plugin Deleted 143 190 *
Note: See TracChangeset
for help on using the changeset viewer.