diff --git a/clef-require.php b/clef-require.php index 0b5c41a..a95c879 100644 --- a/clef-require.php +++ b/clef-require.php @@ -33,6 +33,11 @@ private function define_constants() { if (!defined('CLEF_BASE')) define( 'CLEF_BASE', 'https://clef.io'); if (!defined('CLEF_JS_URL')) define( 'CLEF_JS_URL', CLEF_BASE . '/v3/clef.js'); if (!defined('CLEF_API_BASE')) define( 'CLEF_API_BASE', CLEF_BASE . '/api/v1/'); + + // Accommodate WP Engine's throttle on the Heartbeat API + if ( class_exists('WPE_Heartbeat_Throttle') ) { + if (!defined('WPE_HEARTBEAT_INTERVAL')) define('WPE_HEARTBEAT_INTERVAL', 5); + } } public static function start() { diff --git a/includes/class.clef-admin.php b/includes/class.clef-admin.php index b1cd56c..b9bdb74 100644 --- a/includes/class.clef-admin.php +++ b/includes/class.clef-admin.php @@ -208,7 +208,7 @@ public function general_settings($options = false) { 'setup' => array( 'siteName' => get_option('blogname'), 'siteDomain' => get_option('siteurl'), - 'logoutHook' => wp_login_url(), + 'logoutHook' => ClefUtils::get_logout_hook_url(), 'source' => 'wordpress', 'affiliates' => apply_filters('clef_add_affiliate', array()) ), diff --git a/includes/class.clef-logout.php b/includes/class.clef-logout.php index 628d521..26654c6 100644 --- a/includes/class.clef-logout.php +++ b/includes/class.clef-logout.php @@ -16,6 +16,14 @@ public function initialize_hooks() { if (!defined('DOING_AJAX') || !DOING_AJAX) { add_filter('init', array($this, "logged_out_check_with_redirect")); } + + /** + * Accommodate WP Engine's restriction on the scope of the Heartbeat API (i.e., restricted to post/page editing pages only) + * by expanding the scope to all pages in WP Dashboard; this scope is required for Clef to display the WP logout modal upon Clef-enabled logouts. + */ + if ( class_exists('WPE_Heartbeat_Throttle') ) { + add_filter( 'wpe_heartbeat_allowed_pages', array( $this, 'increase_heartbeat_scope_for_wpe') ); + } } /** @@ -108,5 +116,40 @@ public static function start($settings) { } return self::$instance; } + + /*** + * Ported from Jeremy Pry (http://jeremypry.com/); Original: https://gist.github.com/JPry/b1f6c55a5d5337557f97 + * Remove WP Engine's reduced scope for the Heartbeat API (i.e., editing-only pages) so that the WP logout modal will appear + * when the Clef logout hook is received. + */ + public function increase_heartbeat_scope_for_wpe( $heartbeat_allowed_pages ) { + $heartbeat_allowed_pages[] = 'admin.php'; + $heartbeat_allowed_pages[] = 'customize.php'; + $heartbeat_allowed_pages[] = 'edit-comments.php'; + $heartbeat_allowed_pages[] = 'export.php'; + $heartbeat_allowed_pages[] = 'import.php'; + $heartbeat_allowed_pages[] = 'index.php.php'; + $heartbeat_allowed_pages[] = 'media-new.php'; + $heartbeat_allowed_pages[] = 'nav-menus.php'; + $heartbeat_allowed_pages[] = 'options-discussion.php'; + $heartbeat_allowed_pages[] = 'options-general.php'; + $heartbeat_allowed_pages[] = 'options-media.php'; + $heartbeat_allowed_pages[] = 'options-permalink.php'; + $heartbeat_allowed_pages[] = 'options-reading.php'; + $heartbeat_allowed_pages[] = 'options-writing.php'; + $heartbeat_allowed_pages[] = 'plugin-editor.php'; + $heartbeat_allowed_pages[] = 'plugin-install.php'; + $heartbeat_allowed_pages[] = 'plugins.php'; + $heartbeat_allowed_pages[] = 'profile.php'; + $heartbeat_allowed_pages[] = 'themes.php'; + $heartbeat_allowed_pages[] = 'tools.php'; + $heartbeat_allowed_pages[] = 'update-core.php'; + $heartbeat_allowed_pages[] = 'upload.php'; + $heartbeat_allowed_pages[] = 'users.php'; + $heartbeat_allowed_pages[] = 'user-new.php'; + $heartbeat_allowed_pages[] = 'widgets.php'; + + return $heartbeat_allowed_pages; + } } ?> diff --git a/includes/class.clef-utils.php b/includes/class.clef-utils.php index 3f59f89..1aa86b9 100644 --- a/includes/class.clef-utils.php +++ b/includes/class.clef-utils.php @@ -295,5 +295,16 @@ public static function send_email($email, $subject, $template, $vars) { return $sent; } + + public static function get_logout_hook_url() { + $logout_hook_url = wp_login_url(); + + // Accommodate WP Engine's firewall rules, which require a wpe-login param on POST requests to the login script URL + if ( function_exists( 'wpe_site' ) ) { + $logout_hook_url = add_query_arg('wpe-login', 'clef', $logout_hook_url); + } + + return $logout_hook_url; + } } ?>