Skip to content

Instantly share code, notes, and snippets.

<?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' ) ) {
$.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
<?php
// Init
// -----------------------------------------------------------------------
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// -----------------------------------------------------------------------
require('wp-load.php');
<?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 ...");
}
<?php
// File: ajax.php (Root WP Install)
// Init
// -----------------------------------------------------------------------
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load
// -----------------------------------------------------------------------
<?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()
$.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);
}
<?php
// File: ajax.php (Root WP Install)
// Init
// -----------------------------------------------------------------------
define('DOING_AJAX', true);
define('SHORTINIT', true);
// WP Load & Requirements
// -----------------------------------------------------------------------
<?php
ini_set('memory_limit', '-1');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once('../wp-load.php');
// Vérification de l'utilisateur
if(!current_user_can('administrator'))
<?php
remove_action('welcome_panel', 'wp_welcome_panel');
add_action('admin_footer', 'hwk_admin_welcome_panel');
function hwk_admin_welcome_panel(){
if(get_current_screen()->base !== 'dashboard')
return;
$favicon = false;
if($favicon = get_option('site_icon', false))