From 68bd07783a0fe535338cf97a5c5e5cb7fa29b74f Mon Sep 17 00:00:00 2001 From: Laurence Date: Tue, 31 May 2016 22:07:51 +0000 Subject: [PATCH 1/6] Add get_logout_hook_url method to class ClefUtils --- includes/class.clef-utils.php | 11 +++++++++++ 1 file changed, 11 insertions(+) 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; + } } ?> From 0cacf84f4b4cb644dc7cdc9b333bca11fba3528b Mon Sep 17 00:00:00 2001 From: Laurence Date: Tue, 31 May 2016 22:13:20 +0000 Subject: [PATCH 2/6] Change setup settings to call ClefUtils::get_logout_hook_url instead of wp_login_url for the logoutHook value --- includes/class.clef-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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()) ), From 0fbd283140bf5969f8684e9c8358485512da113e Mon Sep 17 00:00:00 2001 From: Laurence Date: Tue, 31 May 2016 22:49:16 +0000 Subject: [PATCH 3/6] Filter wpe_heartbeat_allowed_pages to expand the scope of the Heartbeat API if we are on a WP Engine server --- includes/class.clef-logout.php | 38 ++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/includes/class.clef-logout.php b/includes/class.clef-logout.php index 628d521..6396c26 100644 --- a/includes/class.clef-logout.php +++ b/includes/class.clef-logout.php @@ -16,6 +16,11 @@ public function initialize_hooks() { if (!defined('DOING_AJAX') || !DOING_AJAX) { add_filter('init', array($this, "logged_out_check_with_redirect")); } + + // Add this filter to expand the scope of the Heartbeat API only if we're running on a WP Engine server + if ( class_exists('WPE_Heartbeat_Throttle') ) { + add_filter( 'wpe_heartbeat_allowed_pages', array( $this, 'increase_heartbeat_scope_for_wpe') ); + } } /** @@ -108,5 +113,38 @@ 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. + */ + private 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[] = '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; + } } ?> From 565ad43217cc27c57cff52c15e737b7c3f0583c6 Mon Sep 17 00:00:00 2001 From: Laurence Date: Tue, 31 May 2016 23:20:55 +0000 Subject: [PATCH 4/6] Fix visibility on increase_heartbeat_scope_for_wpe method --- includes/class.clef-logout.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class.clef-logout.php b/includes/class.clef-logout.php index 6396c26..57769e2 100644 --- a/includes/class.clef-logout.php +++ b/includes/class.clef-logout.php @@ -119,7 +119,7 @@ public static function start($settings) { * 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. */ - private function increase_heartbeat_scope_for_wpe( $heartbeat_allowed_pages ) { + 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'; From 007c161bfb50fe75f377a742d129e898dc023a7a Mon Sep 17 00:00:00 2001 From: Laurence Date: Wed, 1 Jun 2016 17:05:56 +0000 Subject: [PATCH 5/6] Add accommodation for Heartbeat throttle; ammend Heartbeat allowed files list --- clef-require.php | 5 +++++ includes/class.clef-logout.php | 7 ++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clef-require.php b/clef-require.php index 0b5c41a..8885d6e 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-logout.php b/includes/class.clef-logout.php index 57769e2..26654c6 100644 --- a/includes/class.clef-logout.php +++ b/includes/class.clef-logout.php @@ -17,7 +17,10 @@ public function initialize_hooks() { add_filter('init', array($this, "logged_out_check_with_redirect")); } - // Add this filter to expand the scope of the Heartbeat API only if we're running on a WP Engine server + /** + * 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') ); } @@ -134,6 +137,8 @@ public function increase_heartbeat_scope_for_wpe( $heartbeat_allowed_pages ) { $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'; From 0e85fae666181fe45b2b85e086d6b228ff34d7e0 Mon Sep 17 00:00:00 2001 From: Laurence Date: Wed, 1 Jun 2016 17:26:39 +0000 Subject: [PATCH 6/6] Fix indenting on clef-require.php lines 39-40 --- clef-require.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clef-require.php b/clef-require.php index 8885d6e..a95c879 100644 --- a/clef-require.php +++ b/clef-require.php @@ -36,8 +36,8 @@ private function define_constants() { // 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); - } + if (!defined('WPE_HEARTBEAT_INTERVAL')) define('WPE_HEARTBEAT_INTERVAL', 5); + } } public static function start() {