Skip to content
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
5 changes: 5 additions & 0 deletions clef-require.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion includes/class.clef-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
),
Expand Down
43 changes: 43 additions & 0 deletions includes/class.clef-logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -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') );
}
}

/**
Expand Down Expand Up @@ -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;
}
}
?>
11 changes: 11 additions & 0 deletions includes/class.clef-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
?>