A good hook to check authorization and redirect?
I’m guessing the built-in template_redirect action is the best for this… 😀 http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
I’m guessing the built-in template_redirect action is the best for this… 😀 http://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect
I had to do this recently in a custom plugin The basic idea was this: add_action( ‘wp_footer’, ‘create_view_entry’ ) ); function create_view_entry() { $uid = get_current_user_id(); if ( $uid != 0 && is_single() ) $wpdb->insert( $this->tableName, array( ‘uid’ => $uid, ‘pid’ => $post->ID, ‘date’ => current_time( ‘mysql’ ) ) ); } This uses a custom … Read more
As @shanebp suggested you in a comment to OP, that is one of the hook fired by the function wp_transition_post_status, it’s a bit hard to find it doing a search in code because is a dynamic hook, in facts the line in code that fires it looks like: do_action( “{$new_status}_{$post->post_type}”, $post->ID, $post ); Where $new_status … Read more
Problem#1: You can create a customized php file for your page using a Page Template Page Templates WordPress looks for template files in the following order: Page Template — If the page has a custom template assigned, WordPress looks for that file and, if found, uses it. page-{slug}.php — If no custom template has been … Read more
I am not sure how are you ending up with these results. The earliest hook it should work at is roughly admin_init. Anything as early as load process (wp-settings.php, including function.php, plugins_loaded, and even init) should (and does in my installation) produce fatal error, because function definitions hadn’t loaded yet. The definition for these functions … Read more
If you need to change the template used, you can use the template_include filter (change “itermediate-template.php” and “page.php” with correct file names of your template files): add_filter( ‘template_include’, ‘cyb_exclude_template_for_editors’, 99 ); function cyb_exclude_template_for_editors( $template ) { $user = wp_get_current_user(); if( in_array( “editor”, (array) $user->roles ) && is_page_template( “itermediate-template.php” ) ) { $new_template = locate_template( array( … Read more
Please note that the post_Type query variable is not set for standard types (page, post and attachment, see WP_QUery class file line 2396 on trac), only for custom post types, so this is how you can test for each type, add_filter( ‘posts_where’ , ‘posts_where’, 10, 2); function posts_where( $args, $wp_query_obj ) { $type = $wp_query_obj->query_vars[‘post_type’]; … Read more
WordPress provides wp-admin/admin-post.php endpoint to work with form submissions. You should likely point your form to it, add an identifying action, and use hooks in the file to process submission.
It’s probably Firefox prefetching pages, which it can do based on the rel attribute of links (see https://stackoverflow.com/a/18156967/664741). You could alter these links to remove eg rel=”next”, or you could detect Firefox prefetching by checking the headers sent: if ( ! isset( $_SERVER[‘HTTP_X_MOZ’] ) || $_SERVER[‘HTTP_X_MOZ’] != ‘prefetch’ ) { add_action( ‘wp’, ‘function_name’ ); }
Once a fucntion has been hooked to an action, the function will be executed every time the action is called (with do_action). To stop this, the action should be removed. See remove_action: function do_entry() { if ( get_the_title() ) { add_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } else { remove_action(‘loop_entry_before’, ‘function_that_adds_h2_structure’); } add_action(‘loop_entry_entry’, ‘function_that_adds_content_structure’); } In your case, I … Read more