Changeset 1688526
- Timestamp:
- 06/30/2017 09:50:16 PM (9 years ago)
- Location:
- admin-ajax-php-no-thank-you/trunk
- Files:
-
- 3 added
- 8 edited
-
_plugin.php (modified) (1 diff)
-
functions.php (modified) (1 diff)
-
index.php (modified) (1 diff)
-
lib/Admin_Ajax/Admin.php (modified) (5 diffs)
-
lib/Admin_Ajax/No_Thank_You.php (modified) (5 diffs)
-
public (added)
-
public/admin (added)
-
public/admin/options-general.js (added)
-
readme.txt (modified) (1 diff)
-
views/admin/options-general-enabled.php (modified) (3 diffs)
-
views/admin/options-general.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
admin-ajax-php-no-thank-you/trunk/_plugin.php
r1688498 r1688526 7 7 Text Domain: 8 8 Domain Path: /lang 9 Version: 0.3. 09 Version: 0.3.5 10 10 Author URI: https://rack.and.pinecone.website/ 11 11 */ -
admin-ajax-php-no-thank-you/trunk/functions.php
r1688498 r1688526 23 23 return $html; 24 24 } 25 26 /** 27 * 28 * @return string 29 */ 30 function 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 28 28 new Admin; 29 29 } 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
r1688498 r1688526 9 9 add_action( 'admin_menu', array($this, 'admin_menu') ); 10 10 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') );14 11 } 15 12 16 13 /** 17 * setup page for dbugsettings14 * setup page and settings 18 15 * add link to settings page under 'Settings' admin sidebar 19 * update settings from $_POST20 16 * attached to `admin_menu` action 21 17 */ … … 32 28 add_settings_section( 33 29 'admin_ajax_no_thank_you_settings_section', 34 ' Hello',30 '', // subhead 35 31 array($this,'description'), 36 32 'admin_ajax_no_thank_you' … … 44 40 'admin_ajax_no_thank_you_settings_section' 45 41 ); 42 43 register_setting( 'admin_ajax_no_thank_you', 'admin_ajax_no_thank_you', array($this,'save_setting') ); 46 44 } 47 45 … … 74 72 public function render_enabled() 75 73 { 76 $settings = No_Thank_You:: settings_get();74 $settings = No_Thank_You::get_settings(); 77 75 78 76 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 ), 79 81 'settings' => $settings 80 82 ) ); … … 86 88 public function render_main() 87 89 { 90 wp_enqueue_script( 'taxonomy-taxi', plugins_url('public/admin/options-general.js', dirname(__DIR__)), array(), version(), 'all' ); 88 91 echo render( 'admin/options-general' ); 89 92 } -
admin-ajax-php-no-thank-you/trunk/lib/Admin_Ajax/No_Thank_You.php
r1688498 r1688526 7 7 protected static $settings; 8 8 9 /**10 *11 */12 9 public function __construct() 13 10 { 14 self:: settings_load();11 self::load_settings(); 15 12 16 13 add_filter( 'admin_url', array($this, 'rewrite_ajax_admin_url'), 10, 3 ); … … 25 22 * @return array 26 23 */ 27 public static function settings_get()24 public static function get_settings() 28 25 { 29 26 return self::$settings; … … 32 29 /** 33 30 * 31 * @return string 34 32 */ 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() 36 57 { 37 58 $defaults = array( … … 60 81 /** 61 82 * attached to `admin_url` filter 62 * replace /wp-admin/admin-ajax.php with /ajax/83 * replace /wp-admin/admin-ajax.php with rewrite 63 84 * @param string 64 85 * @param string … … 71 92 return $url; 72 93 } 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 ); 77 99 } 78 100 -
admin-ajax-php-no-thank-you/trunk/readme.txt
r1688498 r1688526 14 14 == Installation == 15 15 1. Place /admin-ajax-dot-php-no-thank-you/ directory in /wp-content/plugins/ 16 1. Enable the rewrite or REST API endpoints a t 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`16 1. 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] 17 1. 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` 18 18 1. `/wp-json/wp/v2/admin-ajax` in the REST API is also available for receiving requests. 19 19 20 20 == Changelog == 21 = 0.3.5 = 22 * fix rest api nonce / authentication, debugger on admin page 23 21 24 = 0.3.0 = 22 25 * initial admin settings -
admin-ajax-php-no-thank-you/trunk/views/admin/options-general-enabled.php
r1688498 r1688526 4 4 <th>Enabled</th> 5 5 <th>Default</th> 6 <th></th> 6 7 <th></th> 7 8 </tr> … … 12 13 <td><input type="checkbox" <?php checked( in_array('rewrite', $settings['enabled']) ); ?>name="admin_ajax_no_thank_you[enabled][]" value="rewrite"/></td> 13 14 <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> 15 20 </tr> 16 21 … … 18 23 <td><input type="checkbox" <?php checked( in_array('rest-api', $settings['enabled']) ); ?>name="admin_ajax_no_thank_you[enabled][]" value="rest-api"/></td> 19 24 <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> 21 30 </tr> 22 31 </tbody> 23 32 </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 9 9 </form> 10 10 </div> 11 12 <style> 13 form a{ 14 cursor: pointer; 15 } 16 </style>
Note: See TracChangeset
for help on using the changeset viewer.