Closed epartipilo closed 10 years ago
You can use the hook authenticator_exclude_posts
to exclude posts from the Authenticator. See the documentation inside the readme, point "API".
What have you tried so far? In general this code should exclude a post by it's title:
add_action( 'plugins_loaded', function() {
add_filter( 'authenticator_exclude_posts', function( $titles ) {
$titles[] = 'Contact'; // here goes the post-title of the post/page you want to exclude
return $titles;
} );
} );
Note that the filter authenticator_exclude_posts
is applied at the plugins_loaded
hook.
Now I enhance the readme, a good points to close the issue.
Hi, thanks for the reply,
Still not working =S
I also modified the $exclude_posts array from authenticator.php but the same result.
My page has title: Contact
When logged the URL is http:/custom.mydomain.com/contact/
When not logged it writes this URL: http://localhost:9001/wp-login.php?redirect_to=%2Fcontact%2F
I have the code below on my functions.php
add_action( 'plugins_loaded', function() { add_filter( 'authenticator_exclude_posts', function( $titles ) { $titles[] = 'Contact'; // here goes the post-title of the post/page you want to exclude return $titles; } ); } );
::::: UPDATE :::::
OK, when doing $exclude_posts = array('Contact');
in authenticator.php works! but not from the code suggested in functions.php.
Thanks!
Please check again with the example plugin, now inside the repository: https://github.com/bueltge/Authenticator/blob/master/example_plugin__exclude_posts.php
I have write in a longer php style, but I think it is easier to understand for much more users, there have the same goal.
<?php
/**
* Plugin Name: Authenticator Example Plugin to exclude posts
* Plugin URI: https://github.com/bueltge/Authenticator
* Description: This plugin allows you to publish posts or pages exclude from inaccessible site for non logged in users. This is only a example to read and use the source.
* Author: Inpsyde GmbH
* Version: 2014-09-01
* Author URI: http://inpsyde.com/
* License: GPLv2+
* License URI: ./assets/license.txt
* Textdomain: authenticator
*/
// check for uses in WP
if ( ! function_exists( 'add_filter' ) ) {
echo "Hi there! I'm just a part of plugin, not much I can do when called directly.";
exit;
}
add_action( 'plugins_loaded', 'authenticator_example_add_exclude' );
function authenticator_example_add_exclude() {
add_filter( 'authenticator_exclude_posts', 'authenticator_example_exclude_posts' );
}
function authenticator_example_exclude_posts( $titles ) {
// here goes the post-title of the post/page you want to exclude
$titles[] = 'Sample Page';
// For more as one title use the follow php function
array_push( $titles, 'Sample Page', 'My Title' );
return $titles;
}
Hi! Thanks for the reply!.
Your suggestion doesn't work either but I found a solution that could lead you to solve the issue.
1.- Using add_action( 'plugins_loaded', 'authenticator_example_add_exclude' );
doesn't fill the array, so I used add_action('wp_loaded','authenticator_example_add_exclude');
2.- In line 278
of authenticator.php instead of using in_array( get_the_title(), self::$exclude_posts )
inside the if sentence, I use in_array( get_the_title(), apply_filters( 'authenticator_exclude_posts', self::$exclude_posts) )
That works! hope it helps to solve the problem and you upload your latest version to still using it on my page. ;) Thanks!!
Hi, I just want to skip the redirection of one page. I mean, I want just my /contact page visible for both not logedin an login users. I have tryed with add_filter thing but not results. I have pretty permalinks activated Is this possible?
Thanks!