Plugin Directory

Changeset 1688498


Ignore:
Timestamp:
06/30/2017 07:42:31 PM (9 years ago)
Author:
postpostmodern
Message:

version 0.3.0

Location:
admin-ajax-php-no-thank-you/trunk
Files:
6 added
5 edited

Legend:

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

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

    r1688343 r1688498  
    33    "type": "wordpress-plugin",
    44    "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    ],
    911    "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        }
    1118    },
    1219    "require": {
     20        "php": ">=5.3",
    1321        "composer/installers": "~1.0"
    1422    }
  • admin-ajax-php-no-thank-you/trunk/index.php

    r1688343 r1688498  
    44
    55/**
    6 *   PSR-4
     6*   PSR-4
    77*   @todo detect if composer autoload is being used
    8 *   @param string
     8*   @param string
    99*/
    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 
     10function 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    }
    1820}
    1921spl_autoload_register( __NAMESPACE__.'\autoload' );
    2022
     23require_once __DIR__.'/functions.php';
     24
    2125new No_Thank_You;
    2226
    23 
    24 
    25 
    26 
     27if (is_admin()) {
     28    new Admin;
     29}
  • admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/No_Thank_You.php

    r1688343 r1688498  
    33namespace Admin_Ajax;
    44
    5 class No_Thank_You{
    6     public function __construct(){
     5class No_Thank_You
     6{
     7    protected static $settings;
     8
     9    /**
     10    *
     11    */
     12    public function __construct()
     13    {
     14        self::settings_load();
     15       
    716        add_filter( 'admin_url', array($this, 'rewrite_ajax_admin_url'), 10, 3 );
    817        add_action( 'rest_api_init', array($this, 'rest_api_init') );
     
    1019        add_filter( 'query_vars', array($this, 'rewrite_ajax_query_vars'), 10, 1 );
    1120        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 );
    1249    }
    1350
     
    3168    public function rewrite_ajax_admin_url($url, $path, $blog_id)
    3269    {
    33         if ($path == 'admin-ajax.php') {
    34             $url = get_site_url( $blog_id, '/ajax/' );
     70        if ($path != 'admin-ajax.php') {
     71            return $url;
    3572        }
    3673
     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           
    3779        return $url;
    3880    }
     
    5395
    5496    /**
    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
    5698    *   @param array
    5799    *   @return array
     
    59101    public function rewrite_ajax_root_rewrite_rules($rules)
    60102    {
    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        }
    62108
    63109        return $rules;
     
    87133        ) );
    88134    }
    89    
    90135}
  • admin-ajax-php-no-thank-you/trunk/readme.txt

    r1688343 r1688498  
    1414== Installation ==
    15151. 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 > Permalinks
     161. 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]
    17171. 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`
    18181. `/wp-json/wp/v2/admin-ajax` in the REST API is also available for receiving requests.
    1919
    2020== Changelog ==
     21= 0.3.0 =
     22* initial admin settings
     23
    2124= 0.2.0 =
    2225* Move to class & autoload
Note: See TracChangeset for help on using the changeset viewer.