Is it possible to filter comments in a post so a user can only see the comments they have written?

Assuming your comment authors are intended to be registered users, the easiest way is probably to use a pre_get_comments action hook to modify the WP_Comment_Query object‘s user_id query var such that the query only returns comments from the current user: function wpse262203_restrict_comment_views( $comments_query ) { // Don’t interfere with comment results in the dashboard if( … Read more

Insert new element to array with add_filter

Filters work by calling each of the hooked callback functions (in priority order). The value to be filtered is passed to the first callback funtion. The returned value of that callback function is then passed to the second callback, and the returned value from that is passed onto third and so on, until all hooked … Read more

Earliest hook to reliably get $post/$posts

For all admin pages and front end pages except individual post edit screens (wp-admin/post.php), ‘wp’ is the most reliable hook for getting the global values. http://phpxref.ftwr.co.uk/wordpress/nav.html?wp-includes/class-wp.php.source.html#l486 You can see there that it fires immediately after WP::main() fires WP::register_globals(). The problem with using things like post_results and get_posts is that it will run every time you … Read more

How to add headers to outgoing email?

Thanks to the above, I’ve realized my central mistake — I didn’t quite realize that the arguments being passed in were a multi-dimensional array. For now, I’ve re-implemented the function thus: function ws_add_site_header($email) { $email[‘headers’][] = ‘X-WU-Site: ‘ . parse_url(get_site_url(), PHP_URL_HOST) ; return $email; } My reading of the wp_mail() source (see: https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/pluggable.php#L235) leads me … Read more

WordPress Internal @ Mentions

This is a little tricky because sanitize_user allows spaces in usernames, meaning it difficult to avoid grabbing the whole phrase ‘@johndoe said that … ‘ as opposed to just the actual username ‘@johndoe’ and you have no separator at the end that would help. To avoid that I imposed a requirement that spaces in the … Read more

Filter specific shortcode output?

There is no filter that I know of that is meant to target individual shortcodes like you want. You can filter attributes with shortcode_atts_{$shortcode} though. You can hijack another shortcode by creating your own callback and registering it with the original shortcode slug. I think that is what you are probably going to need to … Read more

Why is javascript allowed in my post content?

If you have the unfiltered_html capability then you can use JS. Admins and editors have this capability by default. Personally I use a plugin for fine control of my users’ capabilities, but you can make this change easily in code: $role = get_role( ‘administrator’ ); $role->remove_cap( ‘unfiltered_html’ ); $role = get_role( ‘editor’ ); $role->remove_cap( ‘unfiltered_html’ … Read more