wordpress-micropub
wordpress-micropub copied to clipboard
Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in /[...]/wp-includes/formatting.php:1595
Not too sure why I'm seeing this only now, but it looks like Micropub_Endpoint::mp_to_wp()
calls Micropub_Endpoint::suggest_post_title
, which returns $props['name']
, which I think in this case (trying to add a bookmark from Indigenous) is an array, which, when run through sanitize_title
leads to the fatal error in the issue title.
Can be addressed like so (in mp_to_wp()
):
if ( isset( $args['post_name'] ) ) {
$args['post_name'] = sanitize_title( ((array) $args['post_name'])[0] );
}
Not too sure why I'm seeing this only now[.]
I mostly long-press links from my feed reader; in this case Indigenous does not set a title (and suggest_post_title()
returns an empty string) and the error does not occur. In the rare occurrence that I use my mobile browsers actual share menu, it does fill out the page title, and I get the error.
I just ran into this again and wondered why it worked on my other site. Turns out I had applied the workaround above ...
Am I the only one seeing this?
Tested with all plugins disabled except IndieAuth and Micropub and it happens all the time, and stops as soon as I apply the change above.
Might be different for JSON vs. form requests? I seem to remember the spec saying JSON values should always be arrays. Either way, casting to an array and then grabbing the first item should work for both single strings and arrays with one or more (string) values.