indieweb / wordpress-micropub

A Micropub Endpoint plugin for WordPress
https://wordpress.org/plugins/micropub
51 stars 12 forks source link

Uncaught TypeError: preg_match(): Argument #2 ($subject) must be of type string, array given in /[...]/wp-includes/formatting.php:1595 #278

Closed janboddez closed 2 years ago

janboddez commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.