Plugin Directory

Changeset 1690123


Ignore:
Timestamp:
07/03/2017 10:22:59 PM (9 years ago)
Author:
postpostmodern
Message:

v 0.5.0

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

Legend:

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

    r1688551 r1690123  
    22/*
    33Plugin Name:    admin-ajax.php, no thank you!
     4Author:         pinecone-dot-website, postpostmodern
     5Author URI:     https://rack.and.pinecone.website/
     6Description:    Changes the wp-admin/admin-ajax.php endpoint to /ajax/
     7Domain Path:    /lang
    48Plugin URI:     https://github.com/pinecone-dot-website/admin-ajax-dot-php-no-thank-you
    5 Description:    Changes the wp-admin/admin-ajax.php endpoint to /ajax/
    6 Author:         pinecone-dot-website, postpostmodern
    79Text Domain:   
    8 Domain Path:    /lang
    9 Version:        0.4.0
    10 Author URI:     https://rack.and.pinecone.website/
     10Version:        0.5.0
    1111*/
    1212
  • admin-ajax-php-no-thank-you/trunk/composer.json

    r1688498 r1690123  
    1414        ],
    1515        "psr-4": {
    16             "Admin_Ajax\\": "lib/Admin_Ajax"
     16            "Admin_Ajax\\": "lib/Admin_Ajax/"
    1717        }
    1818    },
  • admin-ajax-php-no-thank-you/trunk/functions.php

    r1688535 r1690123  
    3535    return $data['Version'];
    3636}
     37
     38/**
     39*
     40*/
     41function wp_ajax_test()
     42{
     43    $response = array(
     44        'post' => $_POST
     45    );
     46
     47    wp_send_json( $response );
     48}
     49add_action( 'wp_ajax_admin-ajax-test', __NAMESPACE__.'\wp_ajax_test' );
     50//add_action( 'wp_ajax_nopriv_admin-ajax-test', __NAMESPACE__.'\wp_ajax_test' );
  • admin-ajax-php-no-thank-you/trunk/index.php

    r1688526 r1690123  
    33namespace Admin_Ajax;
    44
    5 /**
    6 *   PSR-4
    7 *   @todo detect if composer autoload is being used
    8 *   @param string
    9 */
    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     }
     5if (!function_exists('Admin_Ajax\version')) {
     6    require __DIR__.'/autoload.php';
    207}
    21 spl_autoload_register( __NAMESPACE__.'\autoload' );
    22 
    23 require_once __DIR__.'/functions.php';
    24 
     8   
    259new No_Thank_You;
    2610
     
    2812    new Admin;
    2913}
    30 
    31 add_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

    r1688551 r1690123  
    5151    public function description($args)
    5252    {
     53        echo sprintf( '<pre>%s</pre>', version() );
    5354    }
    5455
  • admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/No_Thank_You.php

    r1688551 r1690123  
    103103        }
    104104       
    105         if( !empty($parsed['query']) ){
     105        if (!empty($parsed['query'])) {
    106106            parse_str( $parsed['query'], $query_vars );
    107107            $url = add_query_arg( $query_vars, $url );
     
    159159    public function rest_api_init()
    160160    {
    161         register_rest_route( 'wp/v2', '/admin-ajax', array(
     161        $endpoint = array_filter( explode('/', self::$settings['endpoint']['rest-api']) );
     162        if (count($endpoint) < 3) {
     163            return;
     164        }
     165
     166        $namespace = implode( '/', array_slice($endpoint, 0, 2) );
     167        $route = implode( '/', array_slice($endpoint, 2) );
     168       
     169        register_rest_route( $namespace, $route, array(
    162170            'methods' => 'GET, POST',
    163171            'callback' => array($this, 'require_admin_ajax'),
  • admin-ajax-php-no-thank-you/trunk/public/admin/options-general.js

    r1688526 r1690123  
    2222                    'rand': rand
    2323                },
     24                'error': function (data) {
     25                    ajax_test_error()
     26                },
    2427                'method': 'post',
    2528                'success': function (data) {
    2629                    if (typeof data.post == 'object' && data.post.rand == rand) {
    27                         $debugger.append('response correct!\n\n');
     30                        ajax_test_success();
    2831                    } else {
    29                         $debugger.append('something is wrong!\n\n');
     32                        ajax_test_error();
    3033                    }
    3134                },
     
    3639        $this.html($link);
    3740    });
     41
     42    function ajax_test_error() {
     43        $debugger.append('something is wrong!\n\n');
     44    }
     45
     46    function ajax_test_success() {
     47        $debugger.append('response correct!\n\n');
     48    }
    3849})(jQuery);
  • admin-ajax-php-no-thank-you/trunk/views/admin/options-general-enabled.php

    r1688526 r1690123  
    1515            <td>
    1616                <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/">
     17                <input type="text" value="<?php echo esc_attr($settings['endpoint']['rewrite']); ?>" name="admin_ajax_no_thank_you[endpoint][rewrite]" placeholder="ajax">
    1818            </td>
    1919            <td data-url="<?php echo esc_attr($endpoints['rewrite']); ?>"></td>
     
    2525            <td>
    2626                <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">
     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">
    2828            </td>
    2929            <td data-url="<?php echo esc_attr($endpoints['rest']); ?>"></td>
Note: See TracChangeset for help on using the changeset viewer.