Skip to content

Instantly share code, notes, and snippets.

@hwkdev
Last active October 9, 2024 00:28
Show Gist options
  • Save hwkdev/388574a6e0eea3fa6220be565b0150a0 to your computer and use it in GitHub Desktop.
Save hwkdev/388574a6e0eea3fa6220be565b0150a0 to your computer and use it in GitHub Desktop.

Revisions

  1. hwkdev revised this gist Apr 22, 2018. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions wp-fast-ajax-shortinit-advanced.php
    Original file line number Diff line number Diff line change
    @@ -285,7 +285,8 @@
    do_action( 'wp_loaded' );
    }

    // Ajax Actions Hooks
    // Ajax Requirements & Actions
    // -----------------------------------------------------------------------
    if(!$options['theme'])
    require(get_stylesheet_directory() . $ajax_actions);

    @@ -317,7 +318,9 @@

    if(empty($_REQUEST['action']))
    wp_die('0', 400);


    // Ajax Requirements & Actions
    // -----------------------------------------------------------------------
    require(ABSPATH . WPINC . '/theme.php');
    require(get_stylesheet_directory() . $ajax_actions);

  2. hwkdev revised this gist Apr 22, 2018. 1 changed file with 9 additions and 5 deletions.
    14 changes: 9 additions & 5 deletions wp-fast-ajax-shortinit-advanced.php
    Original file line number Diff line number Diff line change
    @@ -136,18 +136,17 @@
    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 Functions
    // 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' );
    @@ -309,16 +308,21 @@
    }

    }else{

    // Ajax Check
    // -----------------------------------------------------------------------
    @header('X-Robots-Tag: noindex');
    send_nosniff_header();
    nocache_headers();

    if(empty($_REQUEST['action']))
    wp_die('0', 400);

    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);

  3. hwkdev revised this gist Apr 22, 2018. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions wp-fast-ajax-shortinit-advanced.php
    Original file line number Diff line number Diff line change
    @@ -309,6 +309,12 @@
    }

    }else{
    @header('X-Robots-Tag: noindex');
    send_nosniff_header();
    nocache_headers();

    if(empty($_REQUEST['action']))
    wp_die('0', 400);

    require(ABSPATH . WPINC . '/theme.php');
    require(get_stylesheet_directory() . $ajax_actions);
  4. hwkdev revised this gist Apr 22, 2018. 1 changed file with 8 additions and 7 deletions.
    15 changes: 8 additions & 7 deletions wp-fast-ajax-shortinit-advanced.php
    Original file line number Diff line number Diff line change
    @@ -251,7 +251,6 @@
    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();
    @@ -272,13 +271,15 @@
    $GLOBALS['wp']->init();
    do_action( 'init' );
    }

    if ( is_multisite() ) {
    if ( true !== ( $file = ms_site_check() ) ) {
    require( $file );
    die();

    if($options['multisite']){
    if ( is_multisite() ) {
    if ( true !== ( $file = ms_site_check() ) ) {
    require( $file );
    die();
    }
    unset($file);
    }
    unset($file);
    }

    if($options['wp_loaded']){
  5. hwkdev created this gist Apr 22, 2018.
    322 changes: 322 additions & 0 deletions wp-fast-ajax-shortinit-advanced.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,322 @@
    <?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 Functions
    // -----------------------------------------------------------------------
    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 ( is_multisite() ) {
    if ( true !== ( $file = ms_site_check() ) ) {
    require( $file );
    die();
    }
    unset($file);
    }

    if($options['wp_loaded']){
    do_action( 'wp_loaded' );
    }

    // Ajax Actions Hooks
    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{

    require(ABSPATH . WPINC . '/theme.php');
    require(get_stylesheet_directory() . $ajax_actions);

    if(!has_action('wp_ajax_' . $_REQUEST['action']))
    wp_die('0', 400);

    do_action('wp_ajax_' . $_REQUEST['action']);

    }

    wp_die('0');