Changeset 1688498
- Timestamp:
- 06/30/2017 07:42:31 PM (9 years ago)
- Location:
- admin-ajax-php-no-thank-you/trunk
- Files:
-
- 6 added
- 5 edited
-
_plugin.php (modified) (1 diff)
-
composer.json (modified) (1 diff)
-
functions.php (added)
-
index.php (modified) (1 diff)
-
lib/Admin_Ajax/Admin.php (added)
-
lib/Admin_Ajax/No_Thank_You.php (modified) (6 diffs)
-
readme.txt (modified) (1 diff)
-
views (added)
-
views/admin (added)
-
views/admin/options-general-enabled.php (added)
-
views/admin/options-general.php (added)
Legend:
- Unmodified
- Added
- Removed
-
admin-ajax-php-no-thank-you/trunk/_plugin.php
r1688343 r1688498 7 7 Text Domain: 8 8 Domain Path: /lang 9 Version: 0. 2.09 Version: 0.3.0 10 10 Author URI: https://rack.and.pinecone.website/ 11 11 */ -
admin-ajax-php-no-thank-you/trunk/composer.json
r1688343 r1688498 3 3 "type": "wordpress-plugin", 4 4 "license": "GPL-2.0+", 5 "authors": [ { 6 "name": "Eric Eaglstun", 7 "email": "postpostmodern@gmail.com" 8 } ], 5 "authors": [ 6 { 7 "name": "Eric Eaglstun", 8 "email": "postpostmodern@gmail.com" 9 } 10 ], 9 11 "autoload": { 10 "psr-4": { "Admin_Ajax\\": "lib/Admin_Ajax" } 12 "files": [ 13 "functions.php" 14 ], 15 "psr-4": { 16 "Admin_Ajax\\": "lib/Admin_Ajax" 17 } 11 18 }, 12 19 "require": { 20 "php": ">=5.3", 13 21 "composer/installers": "~1.0" 14 22 } -
admin-ajax-php-no-thank-you/trunk/index.php
r1688343 r1688498 4 4 5 5 /** 6 * PSR-46 * PSR-4 7 7 * @todo detect if composer autoload is being used 8 * @param string8 * @param string 9 9 */ 10 function autoload( $class ){ 11 if( strpos($class, __NAMESPACE__) !== 0 ) 12 return; 13 14 $file = __DIR__ .'/lib/'. str_replace('\\', '/', $class) . '.php'; 15 if( file_exists($file) ) 16 require $file; 17 10 function autoload($class) 11 { 12 if (strpos($class, __NAMESPACE__) !== 0) { 13 return; 14 } 15 16 $file = __DIR__ .'/lib/'. str_replace('\\', '/', $class) . '.php'; 17 if (file_exists($file)) { 18 require $file; 19 } 18 20 } 19 21 spl_autoload_register( __NAMESPACE__.'\autoload' ); 20 22 23 require_once __DIR__.'/functions.php'; 24 21 25 new No_Thank_You; 22 26 23 24 25 26 27 if (is_admin()) { 28 new Admin; 29 } -
admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/No_Thank_You.php
r1688343 r1688498 3 3 namespace Admin_Ajax; 4 4 5 class No_Thank_You{ 6 public function __construct(){ 5 class No_Thank_You 6 { 7 protected static $settings; 8 9 /** 10 * 11 */ 12 public function __construct() 13 { 14 self::settings_load(); 15 7 16 add_filter( 'admin_url', array($this, 'rewrite_ajax_admin_url'), 10, 3 ); 8 17 add_action( 'rest_api_init', array($this, 'rest_api_init') ); … … 10 19 add_filter( 'query_vars', array($this, 'rewrite_ajax_query_vars'), 10, 1 ); 11 20 add_filter( 'root_rewrite_rules', array($this, 'rewrite_ajax_root_rewrite_rules'), 10, 1 ); 21 } 22 23 /** 24 * 25 * @return array 26 */ 27 public static function settings_get() 28 { 29 return self::$settings; 30 } 31 32 /** 33 * 34 */ 35 public static function settings_load() 36 { 37 $defaults = array( 38 'default' => '', 39 'enabled' => array(), 40 'endpoint' => array( 41 'rewrite' => 'ajax', 42 'rest-api' => 'wp/v2/admin-ajax' 43 ) 44 ); 45 46 $settings = get_option( 'admin_ajax_no_thank_you', array() ); 47 48 self::$settings = array_merge( $defaults, $settings ); 12 49 } 13 50 … … 31 68 public function rewrite_ajax_admin_url($url, $path, $blog_id) 32 69 { 33 if ($path == 'admin-ajax.php') {34 $url = get_site_url( $blog_id, '/ajax/' );70 if ($path != 'admin-ajax.php') { 71 return $url; 35 72 } 36 73 74 $rewrite = trim( self::$settings['endpoint']['rewrite'] ); 75 if ($rewrite && in_array('rewrite', self::$settings['enabled'])) { 76 $url = get_home_url( $blog_id, sprintf('/%s/', $rewrite) ); 77 } 78 37 79 return $url; 38 80 } … … 53 95 54 96 /** 55 * attatched to `root_rewrite_rules` to register rewrite rule for /ajax/ 97 * attatched to `root_rewrite_rules` to register rewrite rule for /ajax/ or custom 56 98 * @param array 57 99 * @return array … … 59 101 public function rewrite_ajax_root_rewrite_rules($rules) 60 102 { 61 $rules['ajax/?$'] = 'index.php?&admin_ajax_no_thank_you=1'; 103 $rewrite = trim( self::$settings['endpoint']['rewrite'], '/' ); 104 105 if ($rewrite && in_array('rewrite', self::$settings['enabled'])) { 106 $rules[$rewrite.'/?$'] = 'index.php?&admin_ajax_no_thank_you=1'; 107 } 62 108 63 109 return $rules; … … 87 133 ) ); 88 134 } 89 90 135 } -
admin-ajax-php-no-thank-you/trunk/readme.txt
r1688343 r1688498 14 14 == Installation == 15 15 1. Place /admin-ajax-dot-php-no-thank-you/ directory in /wp-content/plugins/ 16 1. Flush the permalink structure by saving the options at Settings > Permalinks16 1. Enable the rewrite or REST API endpoints at Settings > admin-ajax.php Settings [wp-admin/options-general.php?page=admin-ajax.php-no-thank-you] 17 17 1. Any place that calls `admin_url( 'admin-ajax.php' )` from PHP or `ajaxurl` from JavaScript will automatically use `/ajax/` instead of `/wp-admin/admin-ajax.php` 18 18 1. `/wp-json/wp/v2/admin-ajax` in the REST API is also available for receiving requests. 19 19 20 20 == Changelog == 21 = 0.3.0 = 22 * initial admin settings 23 21 24 = 0.2.0 = 22 25 * Move to class & autoload
Note: See TracChangeset
for help on using the changeset viewer.