Hot answers tagged

2

BETTER SOLUTION Actually, there is a note on the WP_Query reference: Note: Ticket #18408 For querying posts in the admin, consider using get_posts() as wp_reset_postdata() might not behave as expected. So instead of attempting to reset the global post data, the more proper solution is either: Use get_posts(): $seriesPosts = get_posts($args); ...


2

Looks to me like WordPress doesn't enable UTF-8 mode when it runs the regex. https://github.com/WordPress/WordPress/blob/5.2.1/wp-includes/rest-api/class-wp-rest-server.php#L837 In PHP, matching multibyte characters requires the u flag. (The code above just adds the case-insensitive flag). So although some strings will still match (like "Département"), ...


1

The replace code is replacing the whole a element content with <a rel="nofollow">. Here's the correction: I used (.+?) between <a and href" and before and after /go/pluto/ to the closing >. Then in the replace, we put $1 $2 $3 etc. to keep them and add rel="nofollow". You can check in this test, and here's explanation about the replace. return ...


1

There's already a function for checking if a post has a shortcode: has_shortcode(): function enqueue_script_if_shortcode_is_detected() { global $post; wp_register_script( 'leweb-widgets', get_stylesheet_directory_uri() . '/includes/leweb-widgets.php', '1.0', true ); if ( has_shortcode( $post->post_content, 'leweb_suggested_events' ) ) { ...


1

It's called a path variable: Path variables enable us to add dynamic routes. See below example taken from the REST API handbook: // Here we are registering our route for single products. The (?P<id>[\d]+) is // our path variable for the ID, which, in this example, can only be some form // of positive number. register_rest_route( 'my-shop/v1', '/...


1

I would approach this by modifying the attributes allowed in the table, tr, and td markup from wp_kses. wp_kses is a function that runs on the content to filter out unwanted tags and attributes. It stands for KSES Strips Evil Scripts, but it does much more than that. It's a large and sometimes convoluted function, but it's very useful if you want to extend ...


Only top voted, non community-wiki answers of a minimum length are eligible