WordPress中自带的处理AJAX请求的HOOK
2019独角兽企业重金招聘Python工程师标准>>>
在Wordpress系统的后台,通过Chrome浏览器查看WordPress的AJAX请求。经过几次的点击,可以WP起到AJAX请求的文件主要就是wp-admin/admin-ajax.php文件。
admin-ajax.php详细的代码如下:
<?php
/*** WordPress Ajax Process Execution** @package WordPress* @subpackage Administration** @link https://codex.wordpress.org/AJAX_in_Plugins*//*** Executing Ajax process.** @since 2.1.0*/
define( 'DOING_AJAX', true );
if ( ! defined( 'WP_ADMIN' ) ) {define( 'WP_ADMIN', true );
}/** Load WordPress Bootstrap */
require_once( dirname( dirname( __FILE__ ) ) . '/wp-load.php' );/** Allow for cross-domain requests (from the front end). */
send_origin_headers();// Require an action parameter
if ( empty( $_REQUEST['action'] ) )die( '0' );/** Load WordPress Administration APIs */
require_once( ABSPATH . 'wp-admin/includes/admin.php' );/** Load Ajax Handlers for WordPress Core */
require_once( ABSPATH . 'wp-admin/includes/ajax-actions.php' );@header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
@header( 'X-Robots-Tag: noindex' );send_nosniff_header();
nocache_headers();/** This action is documented in wp-admin/admin.php */
do_action( 'admin_init' );$core_actions_get = array('fetch-list', 'ajax-tag-search', 'wp-compression-test', 'imgedit-preview', 'oembed-cache','autocomplete-user', 'dashboard-widgets', 'logged-in',
);$core_actions_post = array('oembed-cache', 'image-editor', 'delete-comment', 'delete-tag', 'delete-link','delete-meta', 'delete-post', 'trash-post', 'untrash-post', 'delete-page', 'dim-comment','add-link-category', 'add-tag', 'get-tagcloud', 'get-comments', 'replyto-comment','edit-comment', 'add-menu-item', 'add-meta', 'add-user', 'closed-postboxes','hidden-columns', 'update-welcome-panel', 'menu-get-metabox', 'wp-link-ajax','menu-locations-save', 'menu-quick-search', 'meta-box-order', 'get-permalink','sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order','save-widget', 'delete-inactive-widgets', 'set-post-thumbnail', 'date_format', 'time_format','wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment','query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor','send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs','save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail','parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', 'press-this-save-post','press-this-add-category', 'crop-image', 'generate-password', 'save-wporg-username', 'delete-plugin','search-plugins', 'search-install-plugins', 'activate-plugin', 'update-theme', 'delete-theme','install-theme', 'get-post-thumbnail-html',
);// Deprecated
$core_actions_post[] = 'wp-fullscreen-save-post';// Register core Ajax calls.
if ( ! empty( $_GET['action'] ) && in_array( $_GET['action'], $core_actions_get ) )add_action( 'wp_ajax_' . $_GET['action'], 'wp_ajax_' . str_replace( '-', '_', $_GET['action'] ), 1 );if ( ! empty( $_POST['action'] ) && in_array( $_POST['action'], $core_actions_post ) )add_action( 'wp_ajax_' . $_POST['action'], 'wp_ajax_' . str_replace( '-', '_', $_POST['action'] ), 1 );add_action( 'wp_ajax_nopriv_heartbeat', 'wp_ajax_nopriv_heartbeat', 1 );if ( is_user_logged_in() ) {/*** Fires authenticated Ajax actions for logged-in users.** The dynamic portion of the hook name, `$_REQUEST['action']`,* refers to the name of the Ajax action callback being fired.** @since 2.1.0*/do_action( 'wp_ajax_' . $_REQUEST['action'] );
} else {/*** Fires non-authenticated Ajax actions for logged-out users.** The dynamic portion of the hook name, `$_REQUEST['action']`,* refers to the name of the Ajax action callback being fired.** @since 2.8.0*/do_action( 'wp_ajax_nopriv_' . $_REQUEST['action'] );
}
// Default status
die( '0' );
这上面显示出WordPress自带的AJAX函数hook: wp_ajax_和wp_ajax_nopriv_
转载于:https://my.oschina.net/feanlau/blog/911338
WordPress中自带的处理AJAX请求的HOOK相关推荐
- 在ios中无法获取ajax返回数据类型,在iOS10系统中微信后退无法发起ajax请求的问题解决办法...
在iOS10系统中微信后退无法发起ajax请求的问题解决办法 发布时间:2020-08-20 12:18:08 来源:脚本之家 阅读:102 作者:春去秋来情不归 在IOS10的系统中,在微信客户端中 ...
- a标签用ajax请求传参,Django中如何实现传参的Ajax请求
带参数的Ajax请求 通过Ajax实现下面的功能: 在实现这个功能之前需要掌握的点: 1.在学习jQuery时,我们知道: 获取input标签中输入的值:$("#num1").va ...
- ajax请求数据成功但是success中拿不到数据。
首先来说现象 ajax请求在controller中打断点,发现一切正常,也会正常返回,但是,在success中却收不到数据,再加上error返回,发现返回数据在error中. 这是由于ajax请求中的 ...
- ajax请求type种类,ajax配置项中的type与method
1. jQuery中ajax配置项中的使用type与method的区别 本质上两个配置项是没有区别的,区别在于两者出现的时间不同,type对于目前jQuery的版本全部兼容,也就是说 $.ajax({ ...
- ajaxsetup获取ajax的url_$.ajaxSetup在ajax请求中的使用
转载:https://blog.csdn.net/beitian_123/article/details/100601872 1. 背景 在工作中常用到ajax请求进行前后台交互,有时候一个页面中多处 ...
- ajax请求如何判断超时,ajax请求超时判断(转载)
ajax请求时有个参数可以借鉴一下 var ajaxTimeOut = $.ajax({ url:'', //请求的URL timeout : 1000, //超时时间设置,单位毫秒 type : ' ...
- Vuejs发送Ajax请求
一.概况 ①vuejs中没有内置任何ajax请求方法 ②在vue1.0版本,使用的插件 vue resource 来发送请求,支持promise ③在vue2.0版本,使用社区的一个第三方库 axio ...
- 关于wordpress中更换CKEditor编辑器
wordpress中自带的编辑器实在是功能太简,连插入表格都没有,使用插件的方式太过于麻烦,干脆就直接更换编辑器了,在网上找了一些方法,下文引自http://down.chinaz.com/try/2 ...
- 利用JS面向对象+模块化封装集AJAX请求、基本数据校验、URL参数截取等功能于一身的通用工具模块
以下为封装好的工具类代码,使用方法将在后边介绍. /*** Created by xiaoqiang on 2017/11/09.*/ 'use strict'; import $ from 'jqu ...
最新文章
- webstorm打开新项目提示设置、是否在新窗口打开提示
- 列子御风 大道至简 心诚天人合一
- 浏览器和服务器 对http请求(post get) url长度限制
- 个人所得税计算,计算器.
- 电脑编程python老是出现错误_python常见的编程错误
- 数据处理踩过的坑(不断更新):
- SDNU 1300.转圈游戏(快速幂)
- des java c_这个des加密,到底是用的哪种类型?
- Centos7的 git: 未找到命令解决方法
- 【数据结构----笔记2】查找算法之【哈希查找或散列查找】
- 出海,这可能会是国产浏览器产品的唯一出路
- Django学习系列之ModelForm
- 西游记不单单讲的是故事(2) ------ 摘自 吴闲云的《煮酒探西游》
- Python 列表,for循环,元组的使用【修改、添加、删除、排序、切片】w
- 写一篇最好懂的HTTPS讲解
- android5.0 root工具,ROOT大师:Android 5.0 ROOT并没那么难
- 2017今日头条校招前端面试题(一面)
- 带参宏定义和带参函数的区别
- 货币金融学-期末复习
- 【python与数据分析】Matplotlib数据可视化