Created
June 14, 2024 00:29
-
-
Save johnstonphilip/817ca5d14f58dbe4757f492a97c8c46a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('SHORTINIT', true); | |
require 'wp-load.php'; | |
// Require the minimum to verify the current user ----------------------------------------------- | |
require_once ABSPATH . WPINC . '/default-constants.php'; | |
require_once ABSPATH . WPINC . '/class-wp-user.php'; | |
require_once ABSPATH . WPINC . '/user.php'; | |
require_once ABSPATH . WPINC . '/pluggable.php'; | |
require_once ABSPATH . WPINC . '/capabilities.php'; | |
require_once ABSPATH . WPINC . '/class-wp-roles.php'; | |
require_once ABSPATH . WPINC . '/class-wp-role.php'; | |
require_once ABSPATH . WPINC . '/l10n.php'; | |
require_once ABSPATH . WPINC . '/class-wp-session-tokens.php'; | |
require_once ABSPATH . WPINC . '/class-wp-user-meta-session-tokens.php'; | |
require_once ABSPATH . WPINC . '/rest-api.php'; | |
require_once ABSPATH . WPINC . '/kses.php'; | |
remove_action( 'init', '_wp_footnotes_kses_init' ); | |
remove_action( 'set_current_user', '_wp_footnotes_kses_init' ); | |
/** | |
* Used to guarantee unique hash cookies. | |
* | |
* @since 1.5.0 | |
*/ | |
if ( ! defined( 'COOKIEHASH' ) ) { | |
$siteurl = get_site_option( 'siteurl' ); | |
if ( $siteurl ) { | |
define( 'COOKIEHASH', md5( $siteurl ) ); | |
} else { | |
define( 'COOKIEHASH', '' ); | |
} | |
} | |
/** | |
* @since 2.0.0 | |
*/ | |
if ( ! defined( 'USER_COOKIE' ) ) { | |
define( 'USER_COOKIE', 'wordpressuser_' . COOKIEHASH ); | |
} | |
/** | |
* @since 2.0.0 | |
*/ | |
if ( ! defined( 'PASS_COOKIE' ) ) { | |
define( 'PASS_COOKIE', 'wordpresspass_' . COOKIEHASH ); | |
} | |
/** | |
* @since 2.5.0 | |
*/ | |
if ( ! defined( 'AUTH_COOKIE' ) ) { | |
define( 'AUTH_COOKIE', 'wordpress_' . COOKIEHASH ); | |
} | |
/** | |
* @since 2.6.0 | |
*/ | |
if ( ! defined( 'SECURE_AUTH_COOKIE' ) ) { | |
define( 'SECURE_AUTH_COOKIE', 'wordpress_sec_' . COOKIEHASH ); | |
} | |
/** | |
* @since 2.6.0 | |
*/ | |
if ( ! defined( 'LOGGED_IN_COOKIE' ) ) { | |
define( 'LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH ); | |
} | |
$user_id = wp_validate_auth_cookie( '', 'logged_in' ); | |
// END OF require minimum to verify the current user. ----------------------------------------------- | |
// Here you could get the current user if you don't need anything else. | |
// echo json_encode( wp_get_current_user()->data->user_nicename ); | |
// exit; | |
// Do minimum required to load plugins and themes (Note that shortcodes, blocks, and widgets won't work correctly) -------------------------------------------------- | |
global $shortcode_tags; | |
$shortcode_tags = []; | |
function filter_block_content( $text, $allowed_html = 'post', $allowed_protocols = array() ) { | |
return $text; | |
} | |
// Mock some things we don't need. | |
function add_shortcode() {}; | |
function wp_initialize_theme_preview_hooks() {}; | |
class WP_Widget {} | |
require ABSPATH . WPINC . '/class-wp-embed.php'; | |
$GLOBALS['wp_embed'] = new WP_Embed(); | |
require ABSPATH . WPINC . '/class-wp-textdomain-registry.php'; | |
$GLOBALS['wp_textdomain_registry'] = new WP_Textdomain_Registry(); | |
$GLOBALS['wp_textdomain_registry']->init(); | |
require ABSPATH . WPINC . '/theme.php'; | |
require ABSPATH . WPINC . '/embed.php'; | |
require ABSPATH . WPINC . '/media.php'; | |
require ABSPATH . WPINC . '/link-template.php'; | |
require ABSPATH . WPINC . '/class-wp-post-type.php'; | |
require ABSPATH . WPINC . '/post.php'; | |
require ABSPATH . WPINC . '/taxonomy.php'; | |
require ABSPATH . WPINC . '/class-wp-taxonomy.php'; | |
require ABSPATH . WPINC . '/class-wp-term.php'; | |
wp_plugin_directory_constants(); | |
$GLOBALS['wp_plugin_paths'] = array(); | |
// Load must-use plugins. | |
foreach ( wp_get_mu_plugins() as $mu_plugin ) { | |
$_wp_plugin_file = $mu_plugin; | |
include_once $mu_plugin; | |
$mu_plugin = $_wp_plugin_file; // Avoid stomping of the $mu_plugin variable in a plugin. | |
/** | |
* Fires once a single must-use plugin has loaded. | |
* | |
* @since 5.1.0 | |
* | |
* @param string $mu_plugin Full path to the plugin's main file. | |
*/ | |
do_action( 'mu_plugin_loaded', $mu_plugin ); | |
} | |
unset( $mu_plugin, $_wp_plugin_file ); | |
// Load network activated plugins. | |
if ( is_multisite() ) { | |
foreach ( wp_get_active_network_plugins() as $network_plugin ) { | |
wp_register_plugin_realpath( $network_plugin ); | |
$_wp_plugin_file = $network_plugin; | |
include_once $network_plugin; | |
$network_plugin = $_wp_plugin_file; // Avoid stomping of the $network_plugin variable in a plugin. | |
/** | |
* Fires once a single network-activated plugin has loaded. | |
* | |
* @since 5.1.0 | |
* | |
* @param string $network_plugin Full path to the plugin's main file. | |
*/ | |
do_action( 'network_plugin_loaded', $network_plugin ); | |
} | |
unset( $network_plugin, $_wp_plugin_file ); | |
} | |
/** | |
* Fires once all must-use and network-activated plugins have loaded. | |
* | |
* @since 2.8.0 | |
*/ | |
do_action( 'muplugins_loaded' ); | |
if ( is_multisite() ) { | |
ms_cookie_constants(); | |
} | |
// Define constants after multisite is loaded. | |
wp_cookie_constants(); | |
// Define and enforce our SSL constants. | |
wp_ssl_constants(); | |
// Create common globals. | |
require ABSPATH . WPINC . '/vars.php'; | |
// Make taxonomies and posts available to plugins and themes. | |
// @plugin authors: warning: these get registered again on the init hook. | |
create_initial_taxonomies(); | |
create_initial_post_types(); | |
wp_start_scraping_edited_file_errors(); | |
// Register the default theme directory root. | |
// register_theme_directory( get_theme_root() ); | |
// if ( ! is_multisite() && wp_is_fatal_error_handler_enabled() ) { | |
// // Handle users requesting a recovery mode link and initiating recovery mode. | |
// wp_recovery_mode()->initialize(); | |
// } | |
// Load active plugins. | |
foreach ( wp_get_active_and_valid_plugins() as $plugin ) { | |
wp_register_plugin_realpath( $plugin ); | |
$_wp_plugin_file = $plugin; | |
include_once $plugin; | |
$plugin = $_wp_plugin_file; // Avoid stomping of the $plugin variable in a plugin. | |
/** | |
* Fires once a single activated plugin has loaded. | |
* | |
* @since 5.1.0 | |
* | |
* @param string $plugin Full path to the plugin's main file. | |
*/ | |
do_action( 'plugin_loaded', $plugin ); | |
} | |
unset( $plugin, $_wp_plugin_file ); | |
/** | |
* Fires once all must-use and network-activated plugins have loaded. | |
* | |
* @since 2.8.0 | |
*/ | |
do_action( 'muplugins_loaded' ); | |
do_action( 'plugins_loaded' ); | |
// Load pluggable functions. | |
require ABSPATH . WPINC . '/pluggable.php'; | |
// END OF doing the minimum required to load plugins and themes (and most of their dependencies, except widgets, blocks, and shortcodes). | |
// Call any function from your custom plugin here. | |
// my_custom_plugin_function(); | |
// exit; | |
// Or do a custom query: | |
// global $wpdb; | |
// $post_id = 1805; | |
// $result = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) ); | |
// echo json_encode( $result ); | |
// exit; | |
// Or get the current user: | |
// print_r( wp_get_current_user() ); | |
// die(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment