Plugin Directory

Changeset 1688526


Ignore:
Timestamp:
06/30/2017 09:50:16 PM (9 years ago)
Author:
postpostmodern
Message:

version 0.3.5

Location:
admin-ajax-php-no-thank-you/trunk
Files:
3 added
8 edited

Legend:

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

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

    r1688498 r1688526  
    2323    return $html;
    2424}
     25
     26/**
     27*
     28*   @return string
     29*/
     30function version()
     31{
     32    $data = get_plugin_data( __DIR__.'/_plugin.php' );
     33    return $data['Version'];
     34}
  • admin-ajax-php-no-thank-you/trunk/index.php

    r1688498 r1688526  
    2828    new Admin;
    2929}
     30
     31add_action( 'wp_ajax_admin-ajax-test', function () {
     32    $response = array(
     33        'post' => $_POST
     34    );
     35
     36    wp_send_json( $response );
     37} );
  • admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/Admin.php

    r1688498 r1688526  
    99        add_action( 'admin_menu', array($this, 'admin_menu') );
    1010        add_filter( 'plugin_action_links_admin-ajax-dot-php-no-thank-you/_plugin.php', array($this, 'plugin_action_links') );
    11 
    12        
    13         register_setting( 'admin_ajax_no_thank_you', 'admin_ajax_no_thank_you', array($this,'save_setting') );
    1411    }
    1512
    1613    /**
    17     *   setup page for dbug settings
     14    *   setup page and settings
    1815    *   add link to settings page under 'Settings' admin sidebar
    19     *   update settings from $_POST
    2016    *   attached to `admin_menu` action
    2117    */
     
    3228        add_settings_section(
    3329            'admin_ajax_no_thank_you_settings_section',
    34             'Hello',
     30            '',    // subhead
    3531            array($this,'description'),
    3632            'admin_ajax_no_thank_you'
     
    4440            'admin_ajax_no_thank_you_settings_section'
    4541        );
     42
     43        register_setting( 'admin_ajax_no_thank_you', 'admin_ajax_no_thank_you', array($this,'save_setting') );
    4644    }
    4745
     
    7472    public function render_enabled()
    7573    {
    76         $settings = No_Thank_You::settings_get();
     74        $settings = No_Thank_You::get_settings();
    7775       
    7876        echo render( 'admin/options-general-enabled', array(
     77            'endpoints' => array(
     78                'rest' => No_Thank_You::get_endpoint_rest(),
     79                'rewrite' => No_Thank_You::get_endpoint_rewrite()
     80            ),
    7981            'settings' => $settings
    8082        ) );
     
    8688    public function render_main()
    8789    {
     90        wp_enqueue_script( 'taxonomy-taxi', plugins_url('public/admin/options-general.js', dirname(__DIR__)), array(), version(), 'all' );
    8891        echo render( 'admin/options-general' );
    8992    }
  • admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/No_Thank_You.php

    r1688498 r1688526  
    77    protected static $settings;
    88
    9     /**
    10     *
    11     */
    129    public function __construct()
    1310    {
    14         self::settings_load();
     11        self::load_settings();
    1512       
    1613        add_filter( 'admin_url', array($this, 'rewrite_ajax_admin_url'), 10, 3 );
     
    2522    *   @return array
    2623    */
    27     public static function settings_get()
     24    public static function get_settings()
    2825    {
    2926        return self::$settings;
     
    3229    /**
    3330    *
     31    *   @return string
    3432    */
    35     public static function settings_load()
     33    public static function get_endpoint_rest($blog_id = null)
     34    {
     35        $url = get_rest_url( $blog_id, self::$settings['endpoint']['rest-api'] );
     36        $url = add_query_arg( array(
     37            '_wpnonce' => wp_create_nonce( 'wp_rest' )
     38        ), $url );
     39
     40        return $url;
     41    }
     42
     43    /**
     44    *
     45    *   @return string
     46    */
     47    public static function get_endpoint_rewrite($blog_id = null)
     48    {
     49        $rewrite = trim( self::$settings['endpoint']['rewrite'] );
     50        return get_home_url( $blog_id, sprintf('/%s/', $rewrite) );
     51    }
     52
     53    /**
     54    *
     55    */
     56    public static function load_settings()
    3657    {
    3758        $defaults = array(
     
    6081    /**
    6182    *   attached to `admin_url` filter
    62     *   replace /wp-admin/admin-ajax.php with /ajax/
     83    *   replace /wp-admin/admin-ajax.php with rewrite
    6384    *   @param string
    6485    *   @param string
     
    7192            return $url;
    7293        }
    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) );
     94       
     95        if ((self::$settings['default'] == 'rest-api') && in_array('rest-api', self::$settings['enabled'])) {
     96            $url = self::get_endpoint_rest( $blog_id );
     97        } elseif ((self::$settings['default'] == 'rewrite') && in_array('rewrite', self::$settings['enabled'])) {
     98            $url = self::get_endpoint_rewrite( $blog_id );
    7799        }
    78100           
  • admin-ajax-php-no-thank-you/trunk/readme.txt

    r1688498 r1688526  
    1414== Installation ==
    15151. Place /admin-ajax-dot-php-no-thank-you/ directory in /wp-content/plugins/
    16 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 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`
     161. Enable the rewrite or REST API endpoints and select a default, at Settings > admin-ajax.php Settings [wp-admin/options-general.php?page=admin-ajax.php-no-thank-you]
     171. Any place that calls `admin_url( 'admin-ajax.php' )` from PHP or `ajaxurl` from JavaScript will automatically use the new default endpoint 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.5 =
     22* fix rest api nonce / authentication, debugger on admin page
     23
    2124= 0.3.0 =
    2225* initial admin settings
  • admin-ajax-php-no-thank-you/trunk/views/admin/options-general-enabled.php

    r1688498 r1688526  
    44            <th>Enabled</th>
    55            <th>Default</th>
     6            <th></th>
    67            <th></th>
    78        </tr>
     
    1213            <td><input type="checkbox" <?php checked( in_array('rewrite', $settings['enabled']) ); ?>name="admin_ajax_no_thank_you[enabled][]" value="rewrite"/></td>
    1314            <td><input type="radio" <?php checked( $settings['default'] == 'rewrite' ); ?> name="admin_ajax_no_thank_you[default]" value="rewrite"/></td>
    14             <td><input type="text" value="<?php echo esc_attr($settings['endpoint']['rewrite']); ?>" name="admin_ajax_no_thank_you[endpoint][rewrite]" placeholder="/ajax/"</td>
     15            <td>
     16                <label>Rewrite endpoint</label>
     17                <input type="text" value="<?php echo esc_attr($settings['endpoint']['rewrite']); ?>" name="admin_ajax_no_thank_you[endpoint][rewrite]" placeholder="/ajax/">
     18            </td>
     19            <td data-url="<?php echo esc_attr($endpoints['rewrite']); ?>"></td>
    1520        </tr>
    1621
     
    1823            <td><input type="checkbox" <?php checked( in_array('rest-api', $settings['enabled']) ); ?>name="admin_ajax_no_thank_you[enabled][]" value="rest-api"/></td>
    1924            <td><input type="radio" <?php checked( $settings['default'] == 'rest-api' ); ?> name="admin_ajax_no_thank_you[default]" value="rest-api"/></td>
    20             <td><input type="text" value="<?php echo esc_attr($settings['endpoint']['rest-api']); ?>" name="admin_ajax_no_thank_you[endpoint][rest-api]" placeholder="/wp/v2/admin-ajax"</td>
     25            <td>
     26                <label>REST API endpoint</label>
     27                <input type="text" value="<?php echo esc_attr($settings['endpoint']['rest-api']); ?>" name="admin_ajax_no_thank_you[endpoint][rest-api]" placeholder="/wp/v2/admin-ajax">
     28            </td>
     29            <td data-url="<?php echo esc_attr($endpoints['rest']); ?>"></td>
    2130        </tr>
    2231    </tbody>
    2332</table>
     33
     34<h3>Debug output:</h3>
     35<pre id="debugger"></pre>
  • admin-ajax-php-no-thank-you/trunk/views/admin/options-general.php

    r1688498 r1688526  
    99    </form>
    1010</div>
     11
     12<style>
     13    form a{
     14        cursor: pointer;
     15    }
     16</style>
Note: See TracChangeset for help on using the changeset viewer.