wordpress-micropub icon indicating copy to clipboard operation
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

Open janboddez opened this issue 2 years ago • 1 comments

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.

janboddez avatar Jul 07 '22 10:07 janboddez

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.

janboddez avatar Jul 07 '22 10:07 janboddez

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.

janboddez avatar Oct 03 '22 15:10 janboddez

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.

janboddez avatar Oct 03 '22 15:10 janboddez