Changeset 1688343
- Timestamp:
- 06/30/2017 02:22:24 PM (9 years ago)
- Location:
- admin-ajax-php-no-thank-you/trunk
- Files:
-
- 4 added
- 1 deleted
- 4 edited
-
_plugin.php (modified) (1 diff)
-
composer.json (modified) (1 diff)
-
index.php (modified) (1 diff)
-
lang (added)
-
lang/index.php (added)
-
lib/Admin_Ajax (added)
-
lib/Admin_Ajax/No_Thank_You.php (added)
-
lib/Admin_Ajax_No_Thank_You (deleted)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
admin-ajax-php-no-thank-you/trunk/_plugin.php
r1687353 r1688343 7 7 Text Domain: 8 8 Domain Path: /lang 9 Version: 0. 0.39 Version: 0.2.0 10 10 Author URI: https://rack.and.pinecone.website/ 11 11 */ -
admin-ajax-php-no-thank-you/trunk/composer.json
r1687353 r1688343 8 8 } ], 9 9 "autoload": { 10 "psr-4": { "Admin_Ajax _No_Thank_You\\": "lib/Admin_Ajax_No_Thank_You/" }10 "psr-4": { "Admin_Ajax\\": "lib/Admin_Ajax" } 11 11 }, 12 12 "require": { -
admin-ajax-php-no-thank-you/trunk/index.php
r1687353 r1688343 1 1 <?php 2 2 3 namespace Admin_Ajax _No_Thank_You;3 namespace Admin_Ajax; 4 4 5 5 /** 6 * attached to `admin_url` filter 7 * replace /wp-admin/admin-ajax.php with /ajax/ 8 * @param string 9 * @param string 10 * @param int 11 * @return string 6 * PSR-4 7 * @todo detect if composer autoload is being used 8 * @param string 12 9 */ 13 function rewrite_ajax_admin_url($url, $path, $blog_id) 14 { 15 if ($path == 'admin-ajax.php') { 16 $url = get_site_url( $blog_id, '/ajax/' ); 17 } 10 function autoload( $class ){ 11 if( strpos($class, __NAMESPACE__) !== 0 ) 12 return; 18 13 19 return $url; 14 $file = __DIR__ .'/lib/'. str_replace('\\', '/', $class) . '.php'; 15 if( file_exists($file) ) 16 require $file; 17 20 18 } 21 add_filter( 'admin_url', __NAMESPACE__.'\rewrite_ajax_admin_url', 10, 3);19 spl_autoload_register( __NAMESPACE__.'\autoload' ); 22 20 23 /** 24 * attached to `pre_get_posts` for request to /ajax/ to be intercepted and include admin-ajax.php 25 * @param WP_Query 26 * @return WP_Query 27 */ 28 function rewrite_ajax_pre_get_posts($wp_query) 29 { 30 if ($wp_query->is_main_query() && $wp_query->get('admin_ajax_no_thank_you')) { 31 require ABSPATH.'/wp-admin/admin-ajax.php'; 32 exit(); 33 } 21 new No_Thank_You; 34 22 35 return $wp_query;36 }37 add_filter( 'pre_get_posts', __NAMESPACE__.'\rewrite_ajax_pre_get_posts', 1, 1 );38 23 39 /**40 * attached to `query_vars` filter to register `admin_ajax_no_thank_you`41 * @param array42 * @return array43 */44 function rewrite_ajax_query_vars($qv)45 {46 array_push( $qv, 'admin_ajax_no_thank_you' );47 24 48 return $qv;49 }50 add_filter( 'query_vars', __NAMESPACE__.'\rewrite_ajax_query_vars', 10, 1 );51 25 52 /**53 * attatched to `root_rewrite_rules` to register rewrite rule for /ajax/54 * @param array55 * @return array56 */57 function rewrite_ajax_root_rewrite_rules($rules)58 {59 $rules['ajax/?$'] = 'index.php?&admin_ajax_no_thank_you=1';60 26 61 return $rules;62 }63 add_filter( 'root_rewrite_rules', __NAMESPACE__.'\rewrite_ajax_root_rewrite_rules', 10, 1 ); -
admin-ajax-php-no-thank-you/trunk/readme.txt
r1687353 r1688343 3 3 Donate link: https://cash.me/$EricEaglstun 4 4 Tags: admin-ajax.php, ajax, javascript 5 Requires at least: 3.95 Requires at least: 4.0 6 6 Tested up to: 4.8 7 7 Stable tag: trunk … … 9 9 == Description == 10 10 Changes the wp-admin/admin-ajax.php endpoint to /ajax/ 11 Adds an endpoint to the REST API at `/wp-json/wp/v2/admin-ajax` that behaves exactly as wp-admin/admin-ajax.php 11 12 - requires PHP 5.3 12 13 … … 14 15 1. Place /admin-ajax-dot-php-no-thank-you/ directory in /wp-content/plugins/ 15 16 1. Flush the permalink structure by saving the options at Settings > Permalinks 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 1. `/wp-json/wp/v2/admin-ajax` in the REST API is also available for receiving requests. 16 19 17 20 == Changelog == 21 = 0.2.0 = 22 * Move to class & autoload 23 24 = 0.1.0 = 25 * Rest API endpoint added 26 18 27 = .0.0.3 = 19 28 * Prep for WP plugin directory
Note: See TracChangeset
for help on using the changeset viewer.