What hook to use to redirect based on $post

add_action( ‘pre_get_posts’, ‘mytheme_restrict_user_content’ ); function mytheme_restrict_user_content( $query ){ $restricted_post_types = array(‘documentlibrary’, ‘events’); if ( is_main_query() && is_singular($restricted_post_types) && ! is_user_logged_in() ) { $redirect = set_url_scheme(‘http://’ . $_SERVER[‘HTTP_HOST’] . $_SERVER[‘REQUEST_URI’]); wp_redirect( wp_login_url($redirect, true) ); exit(); } } I don’t use auth_redirect because that function check if the user is logged in, but we already know that … Read more

add_action which contains first argument admin_print_scripts-$page

http://codex.wordpress.org/Plugin_API/Action_Reference/admin_print_scripts echos inline javascript in all admin pages header but http://codex.wordpress.org/Plugin_API/Action_Reference/admin_print_scripts-%28hookname%29 echos inline javascript in specific admin page header passed as second parameter.

How to hook into action/filter call

The callbacks hooked onto ‘all’ are called prior to the callbacks for any hook (action and filters) being called. (See source) add_action( ‘all’, ‘wpse115617_all_hooks’ ); function wpse115617_all_hooks(){ //This is called for every filter & action //You can get the current hook to which it belongs with: $hook = current_filter(); } See http://queryposts.com/function/current_filter/

How to pass hook variable to function?

You can’t use an action or hook within a function in the way you are expecting. Actions and hooks are about delayed execution You are attaching code that will execute at a later point. After an action is added, your function will continue as normal. Then when the user is actually being registered, your code … Read more

alternative to the_content filter

In functions.php: function myExcerpt($text) { $text = str_replace(‘]]>’, ‘]]>’, $text); $text = strip_tags($text); $excerpt_length = 50; // max number of words $words = explode(‘ ‘, $text, $excerpt_length + 1); array_pop($words); array_push($words, ‘-N’); $text = implode(‘ ‘, $words); return $text; } In your loops: echo myExcerpt ( get_the_content() );