Skip to content

Commit

Permalink
Check DOING_AJAX with wp_doing_ajax (#747)
Browse files Browse the repository at this point in the history
  • Loading branch information
herrvigg committed Oct 20, 2019
1 parent e259af3 commit 3b64615
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion admin/qtx_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function qtranxf_collect_translations_posted() {
qtranxf_clean_request( 'qtranslate-fields' );
}

if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( wp_doing_ajax() ) {
// parse variables collected as a query string in an option
foreach ( $_REQUEST as $name => $value ) {
if ( ! is_string( $value ) ) {
Expand Down
2 changes: 1 addition & 1 deletion admin/qtx_admin_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ function qtranxf_before_admin_bar_render() {

function qtranxf_admin_the_title( $title ) {
// For nav menus, keep the raw value as the languages are handled client-side (LSB)
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'add-menu-item' ) {
if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'add-menu-item' ) {
// When a nav menu is being added it is first handled by AJAX, see "wp_ajax_add_menu_item" in ajax-actions.php
// For the call to the filter "the_title", see "wp_setup_nav_menu_item" in nav-menus.php
return $title;
Expand Down
4 changes: 2 additions & 2 deletions modules/wp-seo/qwpseo-activation.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
//if(is_admin() && !defined('DOING_AJAX')){
//if(is_admin() && !wp_doing_ajax()){
// require_once(dirname(__FILE__).'/qwpseo-activation.php');
// $file = wp_normalize_path(__FILE__);
// register_activation_hook($file, 'qwpseo_activation_hook');
//}

//if(defined('DOING_AJAX')){
//if(wp_doing_ajax()){
// require_once(dirname(__FILE__).'/qwpseo-activation.php');
// add_action('wp_ajax_qwpseo_meta_fix', 'qwpseo_ajax_meta_fix');
//}else{
Expand Down
6 changes: 3 additions & 3 deletions qtranslate_core.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function qtranxf_init_language() {
if ( defined( 'WP_ADMIN' ) && WP_ADMIN ) {
$url_info['WP_ADMIN'] = true;
}
if ( defined( 'DOING_AJAX' ) ) {
if ( wp_doing_ajax() ) {
$url_info['DOING_AJAX_POST'] = $_POST;
}
if ( wp_doing_cron() ) {
Expand Down Expand Up @@ -166,7 +166,7 @@ function qtranxf_detect_language( &$url_info ) {
// TODO check if we shouldn't generalize the referrer parsing to all cases, do we need all these limitations?
$parse_referrer = qtranxf_is_rest_request_expected() ||
( ( ! $lang || ! isset( $url_info['doing_front_end'] ) ) &&
( defined( 'DOING_AJAX' ) || ! $url_info['cookie_enabled'] ) );
( wp_doing_ajax() || ! $url_info['cookie_enabled'] ) );

// parse language and front info from HTTP_REFERER
if ( isset( $_SERVER['HTTP_REFERER'] ) && $parse_referrer ) {
Expand Down Expand Up @@ -227,7 +227,7 @@ function qtranxf_detect_language( &$url_info ) {
$url_info['language'] = $lang;

// REST calls should be deterministic (stateless), no special language detection e.g. based on cookie
$url_info['set_cookie'] = ! defined( 'DOING_AJAX' ) && ! qtranxf_is_rest_request_expected();
$url_info['set_cookie'] = ! wp_doing_ajax() && ! qtranxf_is_rest_request_expected();

/**
* Hook for possible other methods
Expand Down
4 changes: 2 additions & 2 deletions qtranslate_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ function qtranxf_is_rest_request_expected() {
* @return bool
*/
function qtranxf_can_redirect() {
return ! defined( 'WP_ADMIN' ) && ! defined( 'DOING_AJAX' ) && ! defined( 'WP_CLI' ) && ! wp_doing_cron() && empty( $_POST )
return ! defined( 'WP_ADMIN' ) && ! wp_doing_ajax() && ! defined( 'WP_CLI' ) && ! wp_doing_cron() && empty( $_POST )
&& ( ! qtranxf_is_rest_request_expected() )
// TODO clarify: 'REDIRECT_*' needs more testing --> && !isset($_SERVER['REDIRECT_URL'])
&& ( ! isset( $_SERVER['REDIRECT_STATUS'] ) || $_SERVER['REDIRECT_STATUS'] == '200' );
Expand Down Expand Up @@ -1042,7 +1042,7 @@ function qtranxf_match_language_locale( $locale ) {
}

function qtranxf_get_page_referer() {
if ( defined( 'DOING_AJAX' ) ) {
if ( wp_doing_ajax() ) {
global $q_config;
if ( isset( $q_config['url_info']['page_referer'] ) ) {
return $q_config['url_info']['page_referer'];
Expand Down

0 comments on commit 3b64615

Please sign in to comment.