Changeset 2030952
- Timestamp:
- 02/15/2019 12:29:45 AM (7 years ago)
- Location:
- wp-dashboard/trunk
- Files:
-
- 6 edited
-
api/class-wpdashboard-api-base.php (modified) (5 diffs)
-
api/class-wpdashboard-plugin-routes.php (modified) (4 diffs)
-
includes/class-wpdashboard.php (modified) (3 diffs)
-
index.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
webhooks/class-wpdashboard-webhooks.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-dashboard/trunk/api/class-wpdashboard-api-base.php
r2021642 r2030952 1 1 <?php 2 2 3 /** 4 * The base of the API portion. 5 * 6 * Sets up the base needs for the WP Dashboard 7 * API. Can be used elsewhere too. 8 * 9 * @package Wpdashboard 10 * @subpackage Wpdashboard/api 11 * @author WP Dashboard <brianldj@gmail.com> 12 */ 3 class WpDashboard_Api_Base extends WP_REST_Controller { 13 4 14 class WpDashboard_Api_Base { 15 16 /** 17 * The ID of this plugin. 18 * 19 * @since 1.0.0 20 * @access private 21 * @var string $plugin_name The ID of this plugin. 22 */ 23 private $plugin_name; 5 /** 6 * The ID of this plugin. 7 * 8 * @since 2.0.0 9 * @access private 10 * @var string $plugin_name The ID of this plugin. 11 */ 12 protected $plugin_name; 24 13 25 14 /** 26 15 * The version of this plugin. 27 16 * 28 * @since 1.0.017 * @since 2.0.0 29 18 * @access private 30 19 * @var string $version The current version of this plugin. 31 20 */ 32 pr ivate$version;21 protected $version; 33 22 34 23 /** 35 * A GuzzleHTTP client used to communicate with WPDashboard.io.24 * Initialize the class and set its properties. 36 25 * 37 * @since 1.0.038 * @ access private39 * @ var string $request_type The current request made to the API.26 * @since 2.0.0 27 * @param string $plugin_name The name of this plugin. 28 * @param string $version The version of this plugin. 40 29 */ 41 p rivate $client;30 public function __construct( $plugin_name, $version ) { 42 31 43 /** 44 * Initialize the class and set its properties. 45 * 46 * @since 1.0.0 47 * @param string $plugin_name The name of this plugin. 48 * @param string $version The version of this plugin. 49 */ 50 public function __construct( $plugin_name, $version ) { 51 52 $this->plugin_name = $plugin_name; 53 $this->version = $version; 54 $this->client = new WP_Http(); 55 56 } 57 58 public function init() { 32 $this->plugin_name = $plugin_name; 33 $this->version = $version; 59 34 60 35 } … … 63 38 * Get Option from WordPress. 64 39 * 65 * @since 1.0.040 * @since 2.0.0 66 41 * 67 42 * @param $name … … 75 50 * Update Option from WordPress. 76 51 * 77 * @since 1.0.052 * @since 2.0.0 78 53 * 79 54 * @param $name … … 89 64 * Delete Option from WordPress. 90 65 * 91 * @since 1.0.10666 * @since 2.0.0 92 67 * 93 68 * @param $name … … 98 73 } 99 74 75 /** 76 * Required 77 * 78 * Include the required files, 79 * only if the route is activated 80 * though, otherwise... errors... 81 * 82 * @since 2.0.0 83 * 84 * @return void 85 */ 86 public function required() { 87 include_once(ABSPATH . 'wp-admin/includes/file.php'); 88 include_once(ABSPATH . 'wp-admin/includes/plugin.php'); 89 include_once(ABSPATH . 'wp-includes/plugin.php'); 90 include_once(ABSPATH . 'wp-admin/includes/theme.php'); 91 include_once(ABSPATH . 'wp-admin/includes/misc.php'); 92 include_once(ABSPATH . 'wp-admin/includes/template.php'); 93 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'); 94 include_once(ABSPATH . 'wp-admin/includes/plugin-install.php'); 95 include_once(ABSPATH . 'wp-admin/includes/update.php'); 96 require_once 'lib/class-wp-upgrade-skin.php'; 97 } 100 98 101 99 /** 102 * Generate Random String.100 * Check Permission 103 101 * 104 * @since 1.0.0 102 * Checks to see if the API Key that is given 103 * matches what we have stored. 105 104 * 106 * @param $data 107 * @return string 105 * @param WP_REST_Request $request Full data about the request. 106 * 107 * @return bool|WP_Error 108 108 */ 109 p rotected function __generate_random_string($data) {110 assert(strlen($data) == 16);111 112 $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100113 $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10114 115 return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));109 public function permission_check( $request ) { 110 if(null !== $request->get_param('api_key')) { 111 if($request->get_param('api_key') == $this->get_option('api_key')) { 112 return true; 113 } 114 } 115 return new WP_Error('unauthenticated', 'You are not authenticated to do this.'); 116 116 } 117 117 118 /** 119 * Coming Soon 120 * 121 * Let's whoever is trying to use the 122 * API know that this function 123 * is coming in a later version. 124 * 125 * @since 2.0.0 126 * 127 * @param $feature string The Feature that is missing. 128 * @param $version float The estimated version that the feature will show up in. 129 * 130 * @return WP_Error 131 */ 132 public function coming_soon($feature, $version) { 133 return new WP_Error(404, 'The feature, ' . $feature . ', is coming, hopefully in version ' . $version . ', but we will see.'); 134 } 135 136 /** 137 * Stupid 138 * 139 * Okay, let's face it, if you 140 * are using end up seeing the 141 * result of this function... 142 * you probably deserve it... 143 * 144 * @since 2.0.0 145 * 146 * @param $huh string The stupid thing the end user is attempting to accomplish... 147 * 148 * @return WP_Error 149 */ 150 public function stupid($huh) { 151 return new WP_Error('wpd_69', '.... you want to... ' . $huh . '... okay, yeah, that is not going to happen??'); 152 } 118 153 } -
wp-dashboard/trunk/api/class-wpdashboard-plugin-routes.php
r2022347 r2030952 1 1 <?php 2 2 3 class WpDashboard_Plugin_Routes extends WP_REST_Controller { 4 5 /** 6 * The ID of this plugin. 7 * 8 * @since 2.0.0 9 * @access private 10 * @var string $plugin_name The ID of this plugin. 11 */ 12 private $plugin_name; 13 14 /** 15 * The version of this plugin. 16 * 17 * @since 2.0.0 18 * @access private 19 * @var string $version The current version of this plugin. 20 */ 21 private $version; 22 23 /** 24 * Initialize the class and set its properties. 25 * 26 * @since 2.0.0 27 * @param string $plugin_name The name of this plugin. 28 * @param string $version The version of this plugin. 29 */ 30 public function __construct( $plugin_name, $version ) { 31 32 $this->plugin_name = $plugin_name; 33 $this->version = $version; 34 35 } 36 37 /** 38 * Get Option from WordPress. 39 * 40 * @since 2.0.0 41 * 42 * @param $name 43 * @return mixed 44 */ 45 public function get_option($name) { 46 return get_option($this->plugin_name . '_' . $name); 47 } 48 49 /** 50 * Update Option from WordPress. 51 * 52 * @since 2.0.0 53 * 54 * @param $name 55 * @param $value 56 * @param $autoload 57 * @return mixed 58 */ 59 public function update_option($name, $value, $autoload) { 60 return update_option($this->plugin_name . '_' . $name, $value, $autoload); 61 } 62 63 /** 64 * Delete Option from WordPress. 65 * 66 * @since 2.0.0 67 * 68 * @param $name 69 * @return mixed 70 */ 71 public function delete_option($name) { 72 return delete_option($this->plugin_name . '_' . $name); 73 } 3 class WpDashboard_Plugin_Routes extends WpDashboard_Api_Base { 74 4 75 5 /** … … 228 158 * Activate Plugin 229 159 * 230 * Deactivates the plugin on160 * Activates the plugin on 231 161 * the site. 232 162 * … … 365 295 } 366 296 367 368 /**369 * Required370 *371 * Include the required files,372 * only if the route is activated373 * though, otherwise... errors...374 *375 * @since 2.0.0376 *377 * @return void378 */379 public function required() {380 include_once(ABSPATH . 'wp-admin/includes/file.php');381 include_once(ABSPATH . 'wp-admin/includes/plugin.php');382 include_once(ABSPATH . 'wp-includes/plugin.php');383 include_once(ABSPATH . 'wp-admin/includes/theme.php');384 include_once(ABSPATH . 'wp-admin/includes/misc.php');385 include_once(ABSPATH . 'wp-admin/includes/template.php');386 include_once(ABSPATH . 'wp-admin/includes/class-wp-upgrader.php');387 include_once(ABSPATH . 'wp-admin/includes/plugin-install.php');388 require_once 'lib/class-wp-upgrade-skin.php';389 }390 391 /**392 * Check Permission393 *394 * Checks to see if the API Key that is given395 * matches what we have stored.396 *397 * @param WP_REST_Request $request Full data about the request.398 *399 * @return bool|WP_Error400 */401 public function permission_check( $request ) {402 if(null !== $request->get_param('api_key')) {403 if($request->get_param('api_key') == $this->get_option('api_key')) {404 return true;405 }406 }407 return new WP_Error('unauthenticated', 'You are not authenticated to do this.');408 }409 410 297 /** 411 298 * Check Plugin Installed … … 429 316 return false; 430 317 } 431 432 /**433 * Prepare the item for create or update operation434 *435 * @param WP_REST_Request $request Request object436 * @return WP_Error|object $prepared_item437 */438 protected function prepare_item_for_database( $request ) {439 return array();440 }441 442 /**443 * Prepare the item for the REST response444 *445 * @param mixed $item WordPress representation of the item.446 * @param WP_REST_Request $request Request object.447 * @return mixed448 */449 public function prepare_item_for_response( $item, $request ) {450 return array();451 }452 453 /**454 * Get the query params for collections455 *456 * @return array457 */458 public function get_collection_params() {459 return array(460 'page' => array(461 'description' => 'Current page of the collection.',462 'type' => 'integer',463 'default' => 1,464 'sanitize_callback' => 'absint',465 ),466 'per_page' => array(467 'description' => 'Maximum number of items to be returned in result set.',468 'type' => 'integer',469 'default' => 10,470 'sanitize_callback' => 'absint',471 ),472 'search' => array(473 'description' => 'Limit results to those matching a string.',474 'type' => 'string',475 'sanitize_callback' => 'sanitize_text_field',476 ),477 );478 }479 318 } -
wp-dashboard/trunk/includes/class-wpdashboard.php
r2021642 r2030952 121 121 * The classes responsible for defining all actions that occur in the api. 122 122 */ 123 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-api-base.php'; 123 124 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-plugin-routes.php'; 125 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-theme-routes.php'; 126 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-core-routes.php'; 127 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-page-routes.php'; 128 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'api/class-wpdashboard-post-routes.php'; 124 129 125 130 /** … … 133 138 */ 134 139 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wpdashboard-public.php'; 135 136 /**137 * Bring in the things required from Composer.138 */139 require_once plugin_dir_path( dirname( __FILE__ ) ) . 'vendor/autoload.php';140 140 141 141 $this->loader = new Wpdashboard_Loader(); … … 199 199 */ 200 200 private function define_api_hooks() { 201 $api = new WpDashboard_Plugin_Routes( $this->get_plugin_name(), $this->get_version() ); 202 $this->loader->add_action( 'rest_api_init', $api, 'register_routes' ); 201 202 $plugin_api = new WpDashboard_Plugin_Routes( $this->get_plugin_name(), $this->get_version() ); 203 $this->loader->add_action( 'rest_api_init', $plugin_api, 'register_routes' ); 204 205 $theme_api = new WpDashboard_Theme_Routes( $this->get_plugin_name(), $this->get_version() ); 206 $this->loader->add_action( 'rest_api_init', $theme_api, 'register_routes' ); 207 208 $core_api = new WpDashboard_Core_Routes( $this->get_plugin_name(), $this->get_version() ); 209 $this->loader->add_action( 'rest_api_init', $core_api, 'register_routes' ); 210 211 $page_api = new WpDashboard_Page_Routes( $this->get_plugin_name(), $this->get_version() ); 212 $this->loader->add_action( 'rest_api_init', $page_api, 'register_routes' ); 213 214 $post_api = new WpDashboard_Post_Routes( $this->get_plugin_name(), $this->get_version() ); 215 $this->loader->add_action( 'rest_api_init', $post_api, 'register_routes' ); 216 203 217 $webhook_api = new Wpdashboard_WebHooks( $this->get_plugin_name(), $this->get_version() ); 204 218 $webhook_api->init(); 219 205 220 } 206 221 -
wp-dashboard/trunk/index.php
r1809618 r2030952 1 <?php // Silence is golden 1 <?php 2 // Silence is golden :3 -
wp-dashboard/trunk/readme.txt
r2020673 r2030952 3 3 Donate link: https://wpdashboard.io 4 4 Tags: wpdashboard, wp, dashboard, manage, updates, plugins, wpdash, dash 5 Requires at least: 3.0.16 Tested up to: 4.9.15 Requires at least: 4.0.0 6 Tested up to: 5.0.3 7 7 Requires PHP: 5.6 8 8 Stable tag: 1.1.18 … … 58 58 59 59 = 2.0.0 = 60 * Complete re-work of the information gathering! 61 * Moved to Webhook version, no more pounding servers/sites for information! 62 * Information is now updated in real-time on the dashboard 63 * Old version is still in place for those sites NOT upgraded, so no worries! 64 * Gathering more information, and re-working how the plugin's backend works! 65 * Starting implementation of the REST API extension, instead of using our own 66 * Starting implementation of the ability to pack up a site and move it 60 * Moved to a Webhook version; no more pounding servers/sites for information! 61 * Gathering more information and re-working how the plugin's backend works! 62 * Implementation of the REST API extension, instead of using our own 67 63 * Bug fixes for PHP 5.6 68 64 -
wp-dashboard/trunk/webhooks/class-wpdashboard-webhooks.php
r2022347 r2030952 83 83 84 84 // private $url = 'https://my.wpdashboard.io/api/v2/site/'; 85 // private $url = 'http://wpdashboard.io.test/api/site/'; 86 private $url = 'https://beta.wpdashboard.io/api/site/'; 85 private $url = 'http://wpdashboard.io.test/api/site/'; 87 86 88 87 /**
Note: See TracChangeset
for help on using the changeset viewer.