Plugin Directory

Changeset 1688343


Ignore:
Timestamp:
06/30/2017 02:22:24 PM (9 years ago)
Author:
postpostmodern
Message:

update to 0.2.0

Location:
admin-ajax-php-no-thank-you/trunk
Files:
4 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • admin-ajax-php-no-thank-you/trunk/_plugin.php

    r1687353 r1688343  
    77Text Domain:   
    88Domain Path:    /lang
    9 Version:        0.0.3
     9Version:        0.2.0
    1010Author URI:     https://rack.and.pinecone.website/
    1111*/
  • admin-ajax-php-no-thank-you/trunk/composer.json

    r1687353 r1688343  
    88    } ],
    99    "autoload": {
    10         "psr-4": { "Admin_Ajax_No_Thank_You\\": "lib/Admin_Ajax_No_Thank_You/" }
     10        "psr-4": { "Admin_Ajax\\": "lib/Admin_Ajax" }
    1111    },
    1212    "require": {
  • admin-ajax-php-no-thank-you/trunk/index.php

    r1687353 r1688343  
    11<?php
    22
    3 namespace Admin_Ajax_No_Thank_You;
     3namespace Admin_Ajax;
    44
    55/**
    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
    129*/
    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     }
     10function autoload( $class ){
     11    if( strpos($class, __NAMESPACE__) !== 0 )
     12        return;
    1813
    19     return $url;
     14    $file = __DIR__ .'/lib/'. str_replace('\\', '/', $class) . '.php';
     15    if( file_exists($file) )
     16        require $file;
     17
    2018}
    21 add_filter( 'admin_url', __NAMESPACE__.'\rewrite_ajax_admin_url', 10, 3 );
     19spl_autoload_register( __NAMESPACE__.'\autoload' );
    2220
    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     }
     21new No_Thank_You;
    3422
    35     return $wp_query;
    36 }
    37 add_filter( 'pre_get_posts', __NAMESPACE__.'\rewrite_ajax_pre_get_posts', 1, 1 );
    3823
    39 /**
    40 *   attached to `query_vars` filter to register `admin_ajax_no_thank_you`
    41 *   @param array
    42 *   @return array
    43 */
    44 function rewrite_ajax_query_vars($qv)
    45 {
    46     array_push( $qv, 'admin_ajax_no_thank_you' );
    4724
    48     return $qv;
    49 }
    50 add_filter( 'query_vars', __NAMESPACE__.'\rewrite_ajax_query_vars', 10, 1 );
    5125
    52 /**
    53 *   attatched to `root_rewrite_rules` to register rewrite rule for /ajax/
    54 *   @param array
    55 *   @return array
    56 */
    57 function rewrite_ajax_root_rewrite_rules($rules)
    58 {
    59     $rules['ajax/?$'] = 'index.php?&admin_ajax_no_thank_you=1';
    6026
    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  
    33Donate link: https://cash.me/$EricEaglstun
    44Tags: admin-ajax.php, ajax, javascript
    5 Requires at least: 3.9
     5Requires at least: 4.0
    66Tested up to: 4.8
    77Stable tag: trunk
     
    99== Description ==
    1010Changes the wp-admin/admin-ajax.php endpoint to /ajax/
     11Adds an endpoint to the REST API at `/wp-json/wp/v2/admin-ajax` that behaves exactly as wp-admin/admin-ajax.php
    1112- requires PHP 5.3
    1213
     
    14151. Place /admin-ajax-dot-php-no-thank-you/ directory in /wp-content/plugins/
    15161. Flush the permalink structure by saving the options at Settings > Permalinks
     171. 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`
     181. `/wp-json/wp/v2/admin-ajax` in the REST API is also available for receiving requests.
    1619
    1720== Changelog ==
     21= 0.2.0 =
     22* Move to class & autoload
     23
     24= 0.1.0 =
     25* Rest API endpoint added
     26
    1827= .0.0.3 =
    1928* Prep for WP plugin directory
Note: See TracChangeset for help on using the changeset viewer.