Allow Profile HTML for select users

You can hook on an early action and apply the filter for your use case: add_action( ‘load-profile.php’, ‘allow_profile_html_wpse_91564’ ); function allow_profile_html_wpse_91564() { global $current_user; if( ‘2’ == $current_user->ID ) remove_filter(‘pre_user_description’, ‘wp_filter_kses’); } The hook load-$pagenow runs in all default admin pages (i.e., not added by a third party), and it’s declared in the file /wp-admin/admin.php. … Read more

Search content for shortcodes and get parameters

This is working for me $shortcode=”book”; $pattern = get_shortcode_regex(); // if shortcode ‘book’ exists if ( preg_match_all( “https://wordpress.stackexchange.com/”. $pattern .’/s’, $post->post_content, $matches ) && array_key_exists( 2, $matches ) && in_array( $shortcode, $matches[2] ) ) { $shortcode_atts = array_keys($matches[2], $shortcode); // if shortcode has attributes if (!empty($shortcode_atts)) { foreach($shortcode_atts as $att) { preg_match(‘/id=”(\d+)”https://wordpress.stackexchange.com/”, $matches[3][$att], $book_id); // … Read more

How can I hide all posts that don’t have a thumbnail?

What filter / hook should I use? You can use the pre_get_posts action hook. Following Tom’s comment on the question about querying for what you want, maybe set meta_query to _thumbnail_id. I would also ( group ) the conditionals to read: “Is both not admin and is main query, AND is either home, category, or … Read more

How to limit the pages displayed for choosing parent page on page attribute’s menu?

This meta box is printed with page_attributes_meta_box and the select field for choosing parent is generated with this code: if ( is_post_type_hierarchical( $post->post_type ) ) : $dropdown_args = array( ‘post_type’ => $post->post_type, ‘exclude_tree’ => $post->ID, ‘selected’ => $post->post_parent, ‘name’ => ‘parent_id’, ‘show_option_none’ => __(‘(no parent)’), ‘sort_column’ => ‘menu_order, post_title’, ‘echo’ => 0, ); $dropdown_args = … Read more

How do I know if author field was changed on post save?

Best Hook for that would be wp_insert_post_data function wpse44358_filter_handler( $data , $postarr ){ //do your stuff //if ($data[‘post_author’] == … return data; // make sure you return something } add_filter( ‘wp_insert_post_data’ , ‘wpse44358_filter_handler’ , ’99’, 2 );

add_filter on “the_excerpt” only works when post does not have excerpt

I posted an article about this a while ago: function wp_trim_all_excerpt($text) { // Creates an excerpt if needed; and shortens the manual excerpt as well global $post; $raw_excerpt = $text; if ( ” == $text ) { $text = get_the_content(”); $text = strip_shortcodes( $text ); $text = apply_filters(‘the_content’, $text); $text = str_replace(‘]]>’, ‘]]>’, $text); } … Read more

Detecting Embed URLs Within post_content

OK, got it. I just dug around in wp core a bit and found the function they use to grab autodetcts. WP uses the php preg_replace_callback function within the WP autoembed function. Here is the code, as seen in wp-includes/class-wp-embed.php: /** * Passes any unlinked URLs that are on their own line to {@link WP_Embed::shortcode()} … Read more

Anyway to edit the titlebar of WordPress Widgets in the Admin area?

I believe you are looking for $params = apply_filters( ‘dynamic_sidebar_params’, $params ); (look here: https://github.com/WordPress/WordPress/blob/master/wp-includes/widgets.php#L706). Now this filter will evaluate both in front end and back end. so to answer your question, you could wrap your filter in a if( is_admin() ){ // Do icons } check. Better yet, you could define this at registration … Read more