“Seen by” Feature in posts [closed]

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

Where is publish_post hook fired?

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

Creating customized php files in theme folder

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

Can i exclude certain page templates for a specific role?

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

wordpress post_where set only for my costum post type

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

update_post_meta is Updating with two page id

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’ ); }

add_action in the loop hooks

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