Changeset 3168966
- Timestamp:
- 10/15/2024 02:34:08 AM (18 months ago)
- Location:
- pageapp/trunk
- Files:
-
- 4 edited
-
inc/jsonlib.php (modified) (2 diffs)
-
pageapp-json.php (modified) (1 diff)
-
pageapp.php (modified) (10 diffs)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
pageapp/trunk/inc/jsonlib.php
r2480315 r3168966 3 3 class JsonLib { 4 4 static $json = false; 5 static $apikey = null;5 static $apikeys = null; 6 6 static $path = null; 7 7 8 8 function __construct($path, $apikey = null) { 9 self::$apikey = $apikey;9 self::$apikeys = $apikey ? (is_array($apikey) ? $apikey : array($apikey)) : array(); 10 10 self::add_hooks($path); 11 11 } … … 42 42 } 43 43 } elseif ($function->isProtected()) { 44 $apikey = self::assert_param('apikey'); 45 if ($apikey == self::$apikey) { 44 if (in_array(self::assert_param('apikey'), self::$apikeys)) { 46 45 return $json->$method(); 47 46 } else { -
pageapp/trunk/pageapp-json.php
r2982921 r3168966 3 3 class PageAppJson extends JsonLib { 4 4 function __construct() { 5 parent::__construct('pageapp/v1', get_option('pageapp_apikey'));5 parent::__construct('pageapp/v1', PageApp::api_keys()); 6 6 } 7 7 -
pageapp/trunk/pageapp.php
r3150723 r3168966 4 4 Plugin URI: https://wordpress.org/plugins/pageapp/ 5 5 Description: Extensions to Wordpress wp-json for the PageApp API and mobile framework 6 Version: 1.4. 26 Version: 1.4.3 7 7 Author: PageApp 8 8 Author URI: https://www.pageapp.com … … 59 59 add_filter('login_url', array(static::class, 'redirect_to'), 10, 3); 60 60 add_filter('lostpassword_redirect', array(static::class, 'lostpassword_redirect')); 61 add_filter('rest_pre_dispatch', array(static::class, 'rest_pre_dispatch'), 10, 3); 61 62 } 62 63 public static function init() { … … 66 67 67 68 $main = new SettingsLib(array( 69 array('id'=>'pageapp_apioptions', 'type'=>'title', 'title'=>'WP JSON Meta'), 68 70 array('id'=>'pageapp_relevanssi', 'type'=>'boolean', 'title'=>'Enable Relevanssi'), 69 71 array('id'=>'pageapp_whitelist', 'type'=>'boolean', 'title'=>'Whitelist Post Meta'), … … 71 73 array('id'=>'pageapp_categories', 'type'=>'boolean', 'title'=>'Include Category Details'), 72 74 array('id'=>'pageapp_customposts', 'type'=>'boolean', 'title'=>'Include Custom Post Types'), 73 array('id'=>'pageapp_authentication', 'type'=>'boolean', 'title'=>'Enable Authentication API (Depricated)'), 74 array('id'=>'pageapp_maxresults', 'type'=>'integer', 'title'=>'Max Results', 'default'=>100, 'description'=>'Maximum results returned over wp-json API'), 75 array('id'=>'pageapp_apikey', 'type'=>'string', 'title'=>'API Key', 'default'=>md5(wp_salt().time()), 'description'=>'API key for public PageApp functions'), 75 array('id'=>'pageapp_apisettings', 'type'=>'title', 'title'=>'API Settings'), 76 array('id'=>'pageapp_restkey', 'type'=>'boolean', 'title'=>'WP JSON Key', 'description'=>'Require apikey on WP JSON API'), 77 array('id'=>'pageapp_apikey', 'type'=>'text', 'title'=>'API Keys', 'default'=>md5(wp_salt().time()), 'description'=>'One per line'), 78 array('id'=>'pageapp_maxresults', 'type'=>'integer', 'title'=>'Max Results', 'default'=>100, 'description'=>'Maximum results returned over WP JSON API'), 79 array('id'=>'pageapp_authentication', 'type'=>'boolean', 'title'=>'Enable Authentication API', 'description'=>'(Deprecated in favour of WP OAuth Server plugin)'), 80 array('id'=>'pageapp_registration', 'type'=>'title', 'title'=>'User Registration'), 76 81 array('id'=>'pageapp_username', 'type'=>'boolean', 'title'=>'Hide username field in registration form'), 77 82 array('id'=>'pageapp_password', 'type'=>'boolean', 'title'=>'Enable password field in registration form'), … … 127 132 self::$ValueCache = new ValueCache(__FILE__, 'pa'); 128 133 } 134 public static function admin_init() { 135 self::register_cssjs(); 136 } 137 public static function register_cssjs() { 138 wp_register_style('pageapp-admin-style', self::plugin().'/css/admin.css'); 139 wp_register_script('pageapp-admin-script', self::plugin().'/js/admin.js'); 140 } 141 public static function include_cssjs() { 142 if (isset($_GET['page']) && strpos($_GET['page'], self::$prefix) === 0) { 143 wp_enqueue_script('jquery'); 144 wp_enqueue_script('jquery-ui-dialog'); 145 wp_enqueue_script('jquery-ui-sortable'); 146 //wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); 147 wp_enqueue_style('pageapp-admin-style'); 148 wp_enqueue_script('pageapp-admin-script'); 149 } 150 } 151 152 /* Helper Functions */ 153 public static function sanitize_options($input) { 154 return $input; 155 } 156 public static function api_keys() { 157 $keys = get_option('pageapp_apikey'); 158 $parts = preg_split('/[\s,]+/', $keys); 159 return array_filter($parts); 160 } 129 161 130 162 /* Registration hooks */ … … 234 266 } 235 267 236 /* OtherFunctions */268 /* Rest/WP-JSON Functions */ 237 269 public static function rest_collection_params($params, $post_type) { 238 270 if (isset($params['per_page'])) { … … 393 425 } 394 426 } 395 public static function admin_init() {396 self::register_cssjs();397 }398 427 public static function register_options() { 399 428 //Whitelist Meta … … 404 433 return $value > 0 ? $value : self::$maxdefault; 405 434 } 406 public static function sanitize_options($input) { 407 return $input; 408 } 409 public static function register_cssjs() { 410 wp_register_style('pageapp-admin-style', self::plugin().'/css/admin.css'); 411 wp_register_script('pageapp-admin-script', self::plugin().'/js/admin.js'); 412 } 413 public static function include_cssjs() { 414 if (isset($_GET['page']) && strpos($_GET['page'], self::$prefix) === 0) { 415 wp_enqueue_script('jquery'); 416 wp_enqueue_script('jquery-ui-dialog'); 417 wp_enqueue_script('jquery-ui-sortable'); 418 //wp_enqueue_style('jquery-style', '//ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/themes/smoothness/jquery-ui.css'); 419 wp_enqueue_style('pageapp-admin-style'); 420 wp_enqueue_script('pageapp-admin-script'); 421 } 422 } 435 public static function rest_pre_dispatch($result, $server, $request) { 436 if (strpos($request->get_route(), '/wp/v2/') === 0 && get_option('pageapp_restkey') == '1') { 437 if (!isset($_REQUEST['apikey']) || empty($_REQUEST['apikey'])) { 438 return new WP_Error('missing_api_key', 'The apikey is missing from the request.', array('status' => 403)); 439 } else if (!in_array($_REQUEST['apikey'], self::api_keys())) { 440 return new WP_Error('invalid_api_key', 'The apikey is invalid.', array('status' => 403)); 441 } 442 } 443 return $result; 444 } 445 446 /* Post Meta Admin Functions */ 423 447 public static function admin_menu() { 424 448 add_submenu_page(self::$prefix, 'Post Meta', 'Post Meta', 'manage_options', self::$prefix.'-meta', array(self::class, 'post_meta')); … … 512 536 <?php 513 537 } 538 539 /* Relevanssi Functions */ 514 540 public static function relevanssi_installed() { 515 541 return function_exists('relevanssi_do_query'); … … 570 596 return $resp; 571 597 } 598 599 /* Cache Functions */ 572 600 public static function cache_xml($url) { 573 601 self::require_http(); -
pageapp/trunk/readme.txt
r3150723 r3168966 4 4 Requires at least: 3.0 5 5 Tested up to: 6.5.4 6 Stable tag: 1.4. 26 Stable tag: 1.4.3 7 7 License: © 2024 Thireen32 Pty Ltd 8 8 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=K6VKWB3HZB2T2&item_name=Donation%20to%20jameslow%2ecom¤cy_code=USD&bn=PP%2dDonationsBF&charset=UTF%2d8 … … 28 28 29 29 == Changelog == 30 31 = 1.4.3 = 32 * Add optional API key authentication for WP JSON API 30 33 31 34 = 1.4.2 =
Note: See TracChangeset
for help on using the changeset viewer.