Skip to content

Instantly share code, notes, and snippets.

@sc0ttkclark
Created June 9, 2021 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sc0ttkclark/0d328db9a82c1b819751c18301933528 to your computer and use it in GitHub Desktop.
Save sc0ttkclark/0d328db9a82c1b819751c18301933528 to your computer and use it in GitHub Desktop.
PMPro compatibility for the Elementor page builder editor screen
<?php
/**
* Maybe turn off the redirect if we are on the Elementor editor screen logged in as someone who can edit the post.
*
* @param string $redirect_to The URL to redirect to.
*
* @return string The URL to redirect to.
*/
function my_pmpro_elementor_fix_redirect( $redirect_to ) {
// Bypass if not logged in or not on Elementor editor screen.
if ( ! is_user_logged_in() || empty( $_GET['elementor-preview'] ) ) {
return $redirect_to;
}
// Bypass if they cannot edit this post.
if ( ! current_user_can( 'edit_post', get_the_ID() ) ) {
return $redirect_to;
}
// Turn off the redirect if we are on the Elementor editor screen logged in as someone who can edit the post.
return '';
}
add_filter( 'pmprocpt_redirect_to', 'my_pmpro_elementor_fix_redirect', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment