WordPress hwk Blog Accélérer le Traitement des Reqûetes Ajax WordPress grâce à Shortinit

Accélérer le Traitement des Reqûetes Ajax WordPress grâce à Shortinit

22 April 2018

Introduction & Concept

  • index.php
    • wp-blog-header.php
      • wp-load.php
        • wp-config.php
          • wp-settings.php SHORTINIT
<?php
// wp-settings.php:118
// Initialize multisite if enabled.
if ( is_multisite() ) {
require( ABSPATH . WPINC . '/class-wp-site-query.php' );
require( ABSPATH . WPINC . '/class-wp-network-query.php' );
require( ABSPATH . WPINC . '/ms-blogs.php' );
require( ABSPATH . WPINC . '/ms-settings.php' );
} elseif ( ! defined( 'MULTISITE' ) ) {
define( 'MULTISITE', false );
}
register_shutdown_function( 'shutdown_action_hook' );
// Stop most of WordPress from being loaded if we just want the basics.
if ( SHORTINIT )
return false;
// Load the L10n library.
require_once( ABSPATH . WPINC . '/l10n.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' );
//

Ajax Shortinit: Simple

Benchmark

Accélération de près de  ~80% de la requête Ajax.

Fichier de Gestion Ajax

<?php
// File: ajax.php (Root WP Install)
// Init
// ———————————————————————–
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// ———————————————————————–
require('wp-load.php');
$ajax_actions = '/includes/ajax-actions.php';
// Ajax Check
// ———————————————————————–
@header('X-Robots-Tag: noindex');
send_nosniff_header();
nocache_headers();
if(empty($_REQUEST['action']))
wp_die('0', 400);
// Ajax Requirements & Actions
// ———————————————————————–
require(ABSPATH . WPINC . '/theme.php');
require(get_stylesheet_directory() . $ajax_actions);
// Ajax Apply Hooks
// ———————————————————————–
if(!has_action('wp_ajax_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_' . $_REQUEST['action']);
wp_die('0');

Action Ajax

<?php
// File: /wp-content/themes/my_theme/includes/ajax-actions.php
add_action('wp_ajax_my_action', 'hwk_ajax_my_action');
function hwk_ajax_my_action(){
global $wpdb;
//$wpdb->get_results("SELECT * FROM …");
}

Javascript

$.ajax({
url: 'ajax.php', // WP root install file: ajax.php
data: {
action: 'my_action',
variable: 'my_variable'
},
type: 'post',
success: function(response){
console.log(response);
}
});

Liste des fonctions disponibles

SHORTINIT coupe court au chargement de WordPress. Ainsi vous n’aurez accès qu’a quelques centaines de fonctions, dont voici la liste exhaustive:

__return_empty_array
__return_empty_string
__return_false
__return_null
__return_true
__return_zero
_ajax_wp_die_handler
_canonical_charset
_cleanup_header_comment
_config_wp_home
_config_wp_siteurl
_custom_background_cb
_custom_header_background_just_in_time
_custom_logo_header_styles
_default_wp_die_handler
_delete_attachment_theme_mod
_delete_option_fresh_site
_deprecated_argument
_deprecated_constructor
_deprecated_file
_deprecated_function
_deprecated_hook
_device_can_upload
_doing_it_wrong
_get_non_cached_ids
_get_random_header_data
_hash_hmac
_http_build_query
_mb_strlen
_mb_substr
_mce_set_direction
_remove_theme_support
_scalar_wp_die_handler
_wp_call_all_hook
_wp_can_use_pcre_u
_wp_customize_changeset_filter_insert_post_data
_wp_customize_include
_wp_customize_loader_settings
_wp_customize_publish_changeset
_wp_filter_build_unique_id
_wp_json_convert_string
_wp_json_prepare_data
_wp_json_sanity_check
_wp_keep_alive_customize_changeset_dependent_auto_drafts
_wp_mysql_week
_wp_timezone_choice_usort_callback
_wp_upload_dir
_xmlrpc_wp_die_handler
absint
add_action
add_editor_style
add_filter
add_magic_quotes
add_network_option
add_option
add_query_arg
add_site_option
add_theme_support
apache_mod_loaded
apply_filters
apply_filters_deprecated
apply_filters_ref_array
background_color
background_image
bool_from_yn
build_query
cache_javascript_headers
check_theme_switched
current_action
current_filter
current_theme_supports
current_time
date_i18n
dead_db
delete_all_user_settings
delete_expired_transients
delete_network_option
delete_option
delete_site_option
delete_site_transient
delete_transient
delete_user_setting
did_action
display_header_text
do_action
do_action_deprecated
do_action_ref_array
do_enclose
do_feed
do_feed_atom
do_feed_rdf
do_feed_rss
do_feed_rss2
do_robots
doing_action
doing_filter
filter_default_option
force_ssl_admin
form_option
get_all_user_settings
get_allowed_mime_types
get_background_color
get_background_image
get_current_blog_id
get_current_network_id
get_custom_header
get_custom_header_markup
get_editor_stylesheets
get_file_data
get_header_image
get_header_image_tag
get_header_textcolor
get_header_video_settings
get_header_video_url
get_locale_stylesheet_uri
get_main_network_id
get_main_site_id
get_network_option
get_num_queries
get_option
get_random_header_image
get_raw_theme_root
get_registered_settings
get_site_option
get_site_transient
get_status_header_desc
get_stylesheet
get_stylesheet_directory
get_stylesheet_directory_uri
get_stylesheet_uri
get_tag_regex
get_temp_dir
get_template
get_template_directory
get_template_directory_uri
get_theme_mod
get_theme_mods
get_theme_root
get_theme_root_uri
get_theme_roots
get_theme_starter_content
get_theme_support
get_transient
get_uploaded_header_images
get_user_setting
get_weekstartend
global_terms_enabled
has_action
has_custom_header
has_filter
has_header_image
has_header_video
header_image
header_textcolor
iis7_supports_permalinks
is_admin
is_blog_admin
is_blog_installed
is_child_theme
is_customize_preview
is_header_video_active
is_lighttpd_before_150
is_main_network
is_main_site
is_multisite
is_network_admin
is_new_day
is_random_header_image
is_serialized
is_serialized_string
is_ssl
is_user_admin
is_wp_error
locale_stylesheet
maybe_serialize
maybe_unserialize
mbstring_binary_safe_encoding
mysql2date
mysql_to_rfc3339
nocache_headers
number_format_i18n
path_is_absolute
path_join
plugin_basename
plugin_dir_path
plugin_dir_url
register_activation_hook
register_deactivation_hook
register_default_headers
register_initial_settings
register_setting
register_theme_directory
register_uninstall_hook
remove_action
remove_all_actions
remove_all_filters
remove_editor_styles
remove_filter
remove_query_arg
remove_theme_mod
remove_theme_mods
remove_theme_support
require_if_theme_supports
require_wp_db
reset_mbstring_encoding
search_theme_directories
send_frame_options_header
send_nosniff_header
set_site_transient
set_theme_mod
set_transient
set_user_setting
shutdown_action_hook
size_format
smilies_init
status_header
switch_theme
the_custom_header_markup
the_header_image_tag
the_header_video_url
timer_start
timer_stop
unregister_default_headers
unregister_setting
update_network_option
update_option
update_site_option
validate_current_theme
validate_file
win_is_writable
wp
wp_allowed_protocols
wp_array_slice_assoc
wp_auth_check
wp_auth_check_html
wp_auth_check_load
wp_cache_add
wp_cache_add_global_groups
wp_cache_add_non_persistent_groups
wp_cache_close
wp_cache_decr
wp_cache_delete
wp_cache_flush
wp_cache_get
wp_cache_get_last_changed
wp_cache_incr
wp_cache_init
wp_cache_replace
wp_cache_reset
wp_cache_set
wp_cache_switch_to_blog
wp_check_filetype
wp_check_filetype_and_ext
wp_check_jsonp_callback
wp_check_php_mysql_versions
wp_checkdate
wp_clean_themes_cache
wp_clone
wp_convert_hr_to_bytes
wp_cookie_constants
wp_custom_css_cb
wp_customize_support_script
wp_customize_url
wp_debug_backtrace_summary
wp_debug_mode
wp_delete_file
wp_die
wp_doing_ajax
wp_doing_cron
wp_ext2type
wp_extract_urls
wp_favicon_request
wp_filter_object_list
wp_finalize_scraping_edited_file_errors
wp_find_hierarchy_loop
wp_find_hierarchy_loop_tortoise_hare
wp_fix_server_vars
wp_functionality_constants
wp_generate_uuid4
wp_get_active_and_valid_plugins
wp_get_custom_css
wp_get_custom_css_post
wp_get_ext_types
wp_get_http_headers
wp_get_image_mime
wp_get_mime_types
wp_get_mu_plugins
wp_get_nocache_headers
wp_get_original_referer
wp_get_raw_referer
wp_get_referer
wp_get_server_protocol
wp_get_theme
wp_get_themes
wp_get_upload_dir
wp_guess_url
wp_initial_constants
wp_installing
wp_is_file_mod_allowed
wp_is_ini_value_changeable
wp_is_numeric_array
wp_is_stream
wp_is_uuid
wp_is_writable
wp_json_encode
wp_list_filter
wp_list_pluck
wp_list_sort
wp_load_alloptions
wp_load_core_site_options
wp_load_translations_early
wp_magic_quotes
wp_maintenance
wp_maybe_decline_date
wp_maybe_load_widgets
wp_mkdir_p
wp_nonce_ays
wp_nonce_field
wp_nonce_url
wp_normalize_path
wp_not_installed
wp_ob_end_flush_all
wp_original_referer_field
wp_parse_args
wp_parse_id_list
wp_parse_slug_list
wp_plugin_directory_constants
wp_post_preview_js
wp_protect_special_option
wp_raise_memory_limit
wp_referer_field
wp_register_plugin_realpath
wp_remote_fopen
wp_removable_query_args
wp_scheduled_delete
wp_send_json
wp_send_json_error
wp_send_json_success
wp_set_all_user_settings
wp_set_internal_encoding
wp_set_lang_dir
wp_set_wpdb_vars
wp_site_admin_email_change_notification
wp_ssl_constants
wp_start_object_cache
wp_start_scraping_edited_file_errors
wp_suspend_cache_addition
wp_suspend_cache_invalidation
wp_templating_constants
wp_timezone_choice
wp_timezone_override_offset
wp_unique_filename
wp_unregister_globals
wp_update_custom_css_post
wp_upload_bits
wp_upload_dir
wp_user_settings
wp_using_ext_object_cache
wp_validate_boolean
wp_widgets_add_menu
xmlrpc_getpostcategory
xmlrpc_getposttitle
xmlrpc_removepostdata

Ajax Shortinit: Sur-Mesure

Benchmark

Accélération de près de  ~70% de la requête Ajax.

Fichier de Gestion Ajax

<?php
// File: ajax.php (Root WP Install)
// Init
// ———————————————————————–
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load & Requirements
// ———————————————————————–
require('wp-load.php');
$ajax_actions = '/includes/ajax-actions.php';
// l10n
// ———————————————————————–
require_once( ABSPATH . WPINC . '/l10n.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' );
// Basics
// ———————————————————————–
require( ABSPATH . WPINC . '/formatting.php' );
require( ABSPATH . WPINC . '/pluggable.php' );
require( ABSPATH . WPINC . '/meta.php' );
// User
// ———————————————————————–
require( ABSPATH . WPINC . '/user.php' );
require( ABSPATH . WPINC . '/capabilities.php' );
require( ABSPATH . WPINC . '/class-wp-user.php' );
require( ABSPATH . WPINC . '/class-wp-user-query.php' );
require( ABSPATH . WPINC . '/class-wp-roles.php' );
require( ABSPATH . WPINC . '/class-wp-role.php' );
require( ABSPATH . WPINC . '/class-wp-session-tokens.php' );
require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' );
require( ABSPATH . WPINC . '/class-wp-taxonomy.php' );
// Theme
// ———————————————————————–
require( ABSPATH . WPINC . '/theme.php' );
require( ABSPATH . WPINC . '/class-wp-theme.php' );
require( ABSPATH . WPINC . '/template.php' );
// Posts
// ———————————————————————–
require( ABSPATH . WPINC . '/class-wp-query.php' );
require( ABSPATH . WPINC . '/class-wp-rewrite.php' );
require( ABSPATH . WPINC . '/class-wp-tax-query.php' );
require( ABSPATH . WPINC . '/class-wp-meta-query.php' );
require( ABSPATH . WPINC . '/class-wp-post-type.php' );
require( ABSPATH . WPINC . '/class-wp-post.php' );
require( ABSPATH . WPINC . '/link-template.php' );
require( ABSPATH . WPINC . '/author-template.php' );
require( ABSPATH . WPINC . '/post.php' );
require( ABSPATH . WPINC . '/taxonomy.php' );
require( ABSPATH . WPINC . '/post-template.php' );
require( ABSPATH . WPINC . '/shortcodes.php' );
$GLOBALS['wp_rewrite'] = new WP_Rewrite();
// Addons
// ———————————————————————–
require( ABSPATH . WPINC . '/kses.php' );
require( ABSPATH . WPINC . '/rest-api.php' );
// User Functions
// ———————————————————————–
wp_plugin_directory_constants();
wp_cookie_constants();
// Ajax Check
// ———————————————————————–
require( ABSPATH . WPINC . '/http.php' );
send_origin_headers();
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
@header('X-Robots-Tag: noindex');
send_nosniff_header();
nocache_headers();
if(empty($_REQUEST['action']))
wp_die('0', 400);
// Ajax Actions
// ———————————————————————–
require(get_stylesheet_directory() . $ajax_actions);
// Ajax Apply Hooks
// ———————————————————————–
if(is_user_logged_in()){
if(!has_action('wp_ajax_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_' . $_REQUEST['action']);
}else{
if(!has_action( 'wp_ajax_nopriv_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_nopriv_' . $_REQUEST['action']);
}
wp_die('0');

Action Ajax

<?php
// File: /wp-content/themes/my_theme/includes/ajax-actions.php
add_action('wp_ajax_my_action', 'hwk_ajax_my_action');
add_action('wp_ajax_nopriv_my_action', 'hwk_ajax_my_action');
function hwk_ajax_my_action(){
// is_user_logged_in()
// current_user_can()
// get_userdata()
// get_users()
// get_post()
// get_posts()
// get_page_by_path()
// get_the_title()
// get_permalink()
// get_post_field()
//
}

Javascript

$.ajax({
url: 'ajax.php', // WP root install file: ajax.php
data: {
action: 'my_action',
variable: 'my_variable'
},
type: 'post',
success: function(response){
console.log(response);
}
});

Ajax Shortinit: Avancé

Benchmark

Accélération de près de  ~40% de la requête Ajax.

Fichier de Gestion Ajax

<?php
// Init
// ———————————————————————–
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// ———————————————————————–
require('wp-load.php');
$ajax_actions = '/includes/ajax-actions.php';
// Ajax Arguments
// ———————————————————————–
$fastajax = array();
if(isset($_REQUEST['fastajax']))
$fastajax = (array) $_REQUEST['fastajax'];
$options = wp_parse_args($fastajax, array(
'empty' => false,
'plugins' => false,
'mu_plugins' => false,
'theme' => false,
'init' => false,
'multisite' => false,
'locale' => false,
'globals' => false,
'wp_loaded' => false,
));
if(!$options['empty']){
// Load the L10n library.
require_once( ABSPATH . WPINC . '/l10n.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale.php' );
require_once( ABSPATH . WPINC . '/class-wp-locale-switcher.php' );
// Load most of WordPress.
require( ABSPATH . WPINC . '/class-wp-walker.php' );
require( ABSPATH . WPINC . '/class-wp-ajax-response.php' );
require( ABSPATH . WPINC . '/formatting.php' );
require( ABSPATH . WPINC . '/capabilities.php' );
require( ABSPATH . WPINC . '/class-wp-roles.php' );
require( ABSPATH . WPINC . '/class-wp-role.php' );
require( ABSPATH . WPINC . '/class-wp-user.php' );
require( ABSPATH . WPINC . '/class-wp-query.php' );
require( ABSPATH . WPINC . '/query.php' );
require( ABSPATH . WPINC . '/date.php' );
require( ABSPATH . WPINC . '/theme.php' );
require( ABSPATH . WPINC . '/class-wp-theme.php' );
require( ABSPATH . WPINC . '/template.php' );
require( ABSPATH . WPINC . '/user.php' );
require( ABSPATH . WPINC . '/class-wp-user-query.php' );
require( ABSPATH . WPINC . '/class-wp-session-tokens.php' );
require( ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php' );
require( ABSPATH . WPINC . '/meta.php' );
require( ABSPATH . WPINC . '/class-wp-meta-query.php' );
require( ABSPATH . WPINC . '/class-wp-metadata-lazyloader.php' );
require( ABSPATH . WPINC . '/general-template.php' );
require( ABSPATH . WPINC . '/link-template.php' );
require( ABSPATH . WPINC . '/author-template.php' );
require( ABSPATH . WPINC . '/post.php' );
require( ABSPATH . WPINC . '/class-walker-page.php' );
require( ABSPATH . WPINC . '/class-walker-page-dropdown.php' );
require( ABSPATH . WPINC . '/class-wp-post-type.php' );
require( ABSPATH . WPINC . '/class-wp-post.php' );
require( ABSPATH . WPINC . '/post-template.php' );
require( ABSPATH . WPINC . '/revision.php' );
require( ABSPATH . WPINC . '/post-formats.php' );
require( ABSPATH . WPINC . '/post-thumbnail-template.php' );
require( ABSPATH . WPINC . '/category.php' );
require( ABSPATH . WPINC . '/class-walker-category.php' );
require( ABSPATH . WPINC . '/class-walker-category-dropdown.php' );
require( ABSPATH . WPINC . '/category-template.php' );
require( ABSPATH . WPINC . '/comment.php' );
require( ABSPATH . WPINC . '/class-wp-comment.php' );
require( ABSPATH . WPINC . '/class-wp-comment-query.php' );
require( ABSPATH . WPINC . '/class-walker-comment.php' );
require( ABSPATH . WPINC . '/comment-template.php' );
require( ABSPATH . WPINC . '/rewrite.php' );
require( ABSPATH . WPINC . '/class-wp-rewrite.php' );
require( ABSPATH . WPINC . '/feed.php' );
require( ABSPATH . WPINC . '/bookmark.php' );
require( ABSPATH . WPINC . '/bookmark-template.php' );
require( ABSPATH . WPINC . '/kses.php' );
require( ABSPATH . WPINC . '/cron.php' );
require( ABSPATH . WPINC . '/deprecated.php' );
require( ABSPATH . WPINC . '/script-loader.php' );
require( ABSPATH . WPINC . '/taxonomy.php' );
require( ABSPATH . WPINC . '/class-wp-taxonomy.php' );
require( ABSPATH . WPINC . '/class-wp-term.php' );
require( ABSPATH . WPINC . '/class-wp-term-query.php' );
require( ABSPATH . WPINC . '/class-wp-tax-query.php' );
require( ABSPATH . WPINC . '/update.php' );
require( ABSPATH . WPINC . '/canonical.php' );
require( ABSPATH . WPINC . '/shortcodes.php' );
require( ABSPATH . WPINC . '/embed.php' );
require( ABSPATH . WPINC . '/class-wp-embed.php' );
require( ABSPATH . WPINC . '/class-oembed.php' );
require( ABSPATH . WPINC . '/class-wp-oembed-controller.php' );
require( ABSPATH . WPINC . '/media.php' );
require( ABSPATH . WPINC . '/http.php' );
require( ABSPATH . WPINC . '/class-http.php' );
require( ABSPATH . WPINC . '/class-wp-http-streams.php' );
require( ABSPATH . WPINC . '/class-wp-http-curl.php' );
require( ABSPATH . WPINC . '/class-wp-http-proxy.php' );
require( ABSPATH . WPINC . '/class-wp-http-cookie.php' );
require( ABSPATH . WPINC . '/class-wp-http-encoding.php' );
require( ABSPATH . WPINC . '/class-wp-http-response.php' );
require( ABSPATH . WPINC . '/class-wp-http-requests-response.php' );
require( ABSPATH . WPINC . '/class-wp-http-requests-hooks.php' );
require( ABSPATH . WPINC . '/widgets.php' );
require( ABSPATH . WPINC . '/class-wp-widget.php' );
require( ABSPATH . WPINC . '/class-wp-widget-factory.php' );
require( ABSPATH . WPINC . '/nav-menu.php' );
require( ABSPATH . WPINC . '/nav-menu-template.php' );
require( ABSPATH . WPINC . '/admin-bar.php' );
require( ABSPATH . WPINC . '/rest-api.php' );
require( ABSPATH . WPINC . '/rest-api/class-wp-rest-server.php' );
require( ABSPATH . WPINC . '/rest-api/class-wp-rest-response.php' );
require( ABSPATH . WPINC . '/rest-api/class-wp-rest-request.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-posts-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-attachments-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-types-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-post-statuses-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-revisions-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-taxonomies-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-terms-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-users-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-comments-controller.php' );
require( ABSPATH . WPINC . '/rest-api/endpoints/class-wp-rest-settings-controller.php' );
require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-meta-fields.php' );
require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-comment-meta-fields.php' );
require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-post-meta-fields.php' );
require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-term-meta-fields.php' );
require( ABSPATH . WPINC . '/rest-api/fields/class-wp-rest-user-meta-fields.php' );
// Ajax Check
// ———————————————————————–
send_origin_headers();
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
@header('X-Robots-Tag: noindex');
send_nosniff_header();
nocache_headers();
if(empty($_REQUEST['action']))
wp_die('0', 400);
if($options['multisite']){
if ( is_multisite() ) {
require( ABSPATH . WPINC . '/ms-functions.php' );
require( ABSPATH . WPINC . '/ms-default-filters.php' );
require( ABSPATH . WPINC . '/ms-deprecated.php' );
}
}
wp_plugin_directory_constants();
if($options['plugins']){
$GLOBALS['wp_plugin_paths'] = array();
}
// MU Plugins
if($options['mu_plugins']){
foreach ( wp_get_mu_plugins() as $mu_plugin ) {
include_once( $mu_plugin );
}
unset( $mu_plugin );
}
if($options['multisite']){
if ( is_multisite() ) {
foreach ( wp_get_active_network_plugins() as $network_plugin ) {
wp_register_plugin_realpath( $network_plugin );
include_once( $network_plugin );
}
unset( $network_plugin );
}
}
if($options['mu_plugins']){
do_action( 'muplugins_loaded' );
}
if ( is_multisite() )
ms_cookie_constants( );
wp_cookie_constants();
wp_ssl_constants();
require( ABSPATH . WPINC . '/vars.php' );
create_initial_taxonomies();
create_initial_post_types();
wp_start_scraping_edited_file_errors();
if($options['theme']){
register_theme_directory(get_theme_root());
}
if($options['plugins']){
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
include_once( $plugin );
}
unset( $plugin );
}
require( ABSPATH . WPINC . '/pluggable.php' );
require( ABSPATH . WPINC . '/pluggable-deprecated.php' );
wp_set_internal_encoding();
if ( WP_CACHE && function_exists( 'wp_cache_postload' ) )
wp_cache_postload();
if($options['plugins']){
do_action( 'plugins_loaded' );
}
wp_functionality_constants();
wp_magic_quotes();
do_action( 'sanitize_comment_cookies' );
if($options['globals']){
$GLOBALS['wp_embed'] = new WP_Embed();
$GLOBALS['wp_the_query'] = new WP_Query();
$GLOBALS['wp_query'] = $GLOBALS['wp_the_query'];
$GLOBALS['wp_rewrite'] = new WP_Rewrite();
$GLOBALS['wp'] = new WP();
$GLOBALS['wp_widget_factory'] = new WP_Widget_Factory();
$GLOBALS['wp_roles'] = new WP_Roles();
}
if($options['theme']){
do_action( 'setup_theme' );
}
wp_templating_constants();
load_default_textdomain();
if($options['locale']){
$locale = get_locale();
$locale_file = WP_LANG_DIR . "/$locale.php";
if ( ( 0 === validate_file( $locale ) ) && is_readable( $locale_file ) )
require( $locale_file );
unset( $locale_file );
$GLOBALS['wp_locale'] = new WP_Locale();
$GLOBALS['wp_locale_switcher'] = new WP_Locale_Switcher();
$GLOBALS['wp_locale_switcher']->init();
}
if($options['theme']){
if ( ! wp_installing() || 'wp-activate.php' === $pagenow ) {
if ( TEMPLATEPATH !== STYLESHEETPATH && file_exists( STYLESHEETPATH . '/functions.php' ) )
include( STYLESHEETPATH . '/functions.php' );
if ( file_exists( TEMPLATEPATH . '/functions.php' ) )
include( TEMPLATEPATH . '/functions.php' );
}
do_action( 'after_setup_theme' );
}
if($options['init']){
$GLOBALS['wp']->init();
do_action( 'init' );
}
if($options['multisite']){
if ( is_multisite() ) {
if ( true !== ( $file = ms_site_check() ) ) {
require( $file );
die();
}
unset($file);
}
}
if($options['wp_loaded']){
do_action( 'wp_loaded' );
}
// Ajax Requirements & Actions
// ———————————————————————–
if(!$options['theme'])
require(get_stylesheet_directory() . $ajax_actions);
// Ajax Apply Hooks
// ———————————————————————–
if(is_user_logged_in()){
if(!has_action('wp_ajax_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_' . $_REQUEST['action']);
}else{
if(!has_action( 'wp_ajax_nopriv_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_nopriv_' . $_REQUEST['action']);
}
}else{
// Ajax Check
// ———————————————————————–
@header('X-Robots-Tag: noindex');
send_nosniff_header();
nocache_headers();
if(empty($_REQUEST['action']))
wp_die('0', 400);
// Ajax Requirements & Actions
// ———————————————————————–
require(ABSPATH . WPINC . '/theme.php');
require(get_stylesheet_directory() . $ajax_actions);
// Ajax Apply Hooks
// ———————————————————————–
if(!has_action('wp_ajax_' . $_REQUEST['action']))
wp_die('0', 400);
do_action('wp_ajax_' . $_REQUEST['action']);
}
wp_die('0');

Javascript

$.ajax({
url: 'ajax.php', // WP root install file: ajax.php
data: {
action: 'my_action',
variable: 'my_variable',
fastajax: {
empty: false, // Load Empty Shortinit? true | false. Default: false
mu_plugins: false, // Load MU Plugins? true | false. Default: false
plugins: false, // Load Plugins? true | false. Default: false
theme: false, // Load Theme? true | false. Default: false
multisite: false, // Load Multisite Vars? true | false. Default: false
locale: false, // Load Locale Vars? true | false. Default: false
init: false, // Load WP Init? true | false. Default: false
globals: false, // Load Globals? true | false. Default: false
wp_loaded: false, // Load WP Loaded? true | false. Default: false
}
},
type: 'post',
success: function(response){
console.log(response);
}
});


Konrad Chmielewski

Evangeliste WordPress & Full Stack Developer depuis 10 années.