Skip to content

Commit

Permalink
Introduce an rda_redirect_url filter to make the redirect URL filtera…
Browse files Browse the repository at this point in the history
…ble. If empty, the redirect will be skipped altogether.
  • Loading branch information
DrewAPicture committed Oct 29, 2017
1 parent 8f2346e commit 95a72a2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions inc/class.rda-options.php
Expand Up @@ -401,7 +401,7 @@ public function access_switch_cb() {
/**
* Retrieves the default capabilities for the role-based settings.
*
* @since 1.2
* @since 1.2.0
*
* @return array Pairs of role-based setting abbreviations and their default capabilities.
*/
Expand All @@ -416,7 +416,7 @@ public static function get_default_caps() {
/**
* Filter the capability defaults for admins, editors, and authors.
*
* @since 1.1
* @since 1.2.0
*
* @param array $capabilities {
* Default capabilities for various roles.
Expand Down
22 changes: 20 additions & 2 deletions inc/class.rda-remove-access.php
Expand Up @@ -133,8 +133,26 @@ function dashboard_redirect() {
/** @global string $pagenow */
global $pagenow;

if ( ! in_array( $pagenow, $this->get_allowed_pages(), true ) || ! $this->settings['enable_profile'] ) {
wp_redirect( $this->settings['redirect_url'] );
/**
* Filters the URL to redirect disallowed users to.
*
* If the redirect URL passed to this hook is empty, the redirect will be skipped.
*
* Example to disable the redirect:
*
* add_filter( 'rda_redirect_url', '__return_empty_string' );
*
* @since 1.2.0
*
* @param string $url URL to redirect disallowed users to.
* @param \RDA_Remove_Access $this RDA_Remove_Access instance.
*/
$redirect_url = apply_filters( 'rda_redirect_url', $this->settings['redirect_url'], $this );

if ( ( ! in_array( (string) $pagenow, $this->get_allowed_pages(), true ) || ! $this->settings['enable_profile'] )
&& ! empty( $redirect_url )
) {
wp_redirect( $redirect_url );
exit;
}
}
Expand Down

0 comments on commit 95a72a2

Please sign in to comment.