Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/2610 #2627

Merged
merged 3 commits into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion includes/admin/upgrades/class-give-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public function setup() {

if ( is_admin() ) {
add_action( 'admin_init', array( $this, '__change_donations_label' ), 9999 );
add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 );

if( give_test_ajax_works() ) {
add_action( 'admin_menu', array( $this, '__register_menu' ), 9999 );
}
}
}

Expand Down Expand Up @@ -321,6 +324,20 @@ public function __show_notice() {
return;
}

// Show notice if ajax is not working.
if ( ! give_test_ajax_works() ) {
Give()->notices->register_notice(
array(
'id' => 'give_db_upgrade_ajax_inaccessible',
'type' => 'error',
'description' => __( 'Give needs to upgrade the database but cannot because AJAX is not functioning properly. Please contact your host and ask them to ensure admin-ajax.php is accessible.', 'give' ),
'show' => true,
)
);

return;
}

// Show db upgrade completed notice.
if ( ! empty( $_GET['give-db-update-completed'] ) ) {
Give()->notices->register_notice( array(
Expand Down
13 changes: 12 additions & 1 deletion includes/ajax-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
* @return bool True if AJAX works, false otherwise
*/
function give_test_ajax_works() {
// Handle ajax.
if( wp_doing_ajax() ) {
wp_die( 0, 200 );
}

// Check if the Airplane Mode plugin is installed.
if ( class_exists( 'Airplane_Mode_Core' ) ) {
Expand Down Expand Up @@ -91,15 +95,18 @@ function give_test_ajax_works() {
return $works;
}

add_action( 'wp_ajax_nopriv_give_test_ajax', 'give_test_ajax_works' );

/**
* Get AJAX URL
*
* @since 1.0
*
* @param array $query
*
* @return string
*/
function give_get_ajax_url() {
function give_get_ajax_url( $query = array() ) {
$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';

$current_url = give_get_current_page_url();
Expand All @@ -109,6 +116,10 @@ function give_get_ajax_url() {
$ajax_url = preg_replace( '/^http/', 'https', $ajax_url );
}

if( ! empty( $query ) ) {
$ajax_url = add_query_arg( $query, $ajax_url );
}

return apply_filters( 'give_ajax_url', $ajax_url );
}

Expand Down