plugin-icon

Redirect to login if not logged in

제작자: Daan Kortenbach·
Redirects users to the login page if the visitor is not logged in.
평가
4.8
버전
1.7.0
활성화된 설치 항목
200
최근 업데이트일
Sep 13, 2018

Redirects users to the login page if the user is not logged in. After login the user gets redirected to the original entry page. For advanced users a filter is provided to override the redirect.

The principle behind this plugin is to redirect all users – from every post, page, archive, etc. – to the login page (usually wp-login.php). Except for the override filter it does nothing else.

Overriding the redirect

  • Note: This plugin may not be for you, a membership plugin might be a better fit. Chris Lema writes excellent reviews of +30 membership plugins here: http://chrislema.com/category/memberships-plugins/

If you do have a need for this plugin and you want to exclude specific views under specific conditions, a filter is provided to override the redirect.

To override the redirect the filter must return a boolean value of true. WordPress core provides many conditional tags that either return true or false or you can write your own conditionals.

Take a look at the Conditional Tags page on The WordPress Codex for some inspiration. https://codex.wordpress.org/Conditional_Tags

Usage: Copy/paste/edit an example to the functions.php of your theme or create a new file in wp-content/mu-plugins/ if you do not wish to edit your theme.

Note: Be carefull not to use multiple filters at the same time as that may cause unexpected results. Instead use multiple conditions in one filter.

  • Override if the front page is either posts or a page:

    add_filter( ‘rtl_override_redirect’, ‘is_front_page’ );

  • Override if the post is ‘hello-world’:

    add_filter( ‘rtl_override_redirect’, function() { return is_single( ‘hello-world’ ); });

  • Override if the page is ‘sample-page’:

    add_filter( ‘rtl_override_redirect’, function() { return is_page( ‘sample-page’ ); });

  • Override if the page ID is 42, the slug is ‘sample-page’ or the title is ‘About Me’:

    add_filter( ‘rtl_override_redirect’, function() { return is_page( array( 42, ‘sample-page’, ‘About Me’ ) ); });

  • Override if the page ID is 42 or a post is ‘hello-world’:

    add_filter( ‘rtl_override_redirect’, function() { if ( is_page( 42 ) || is_single( ‘hello-world’ ) ) { return true; } });

무료Business 요금제에서
설치하면 WordPress.com 서비스 약관서드파티 플러그인 약관에 동의하게 됩니다.
테스트된 버전
WordPress 5.0.24
이 플러그인은 다운로드할 수 있으며 에서 사용할 수 있습니다.