dshanske / syndication-links

Add and Display Syndication Links in WordPress
https://wordpress.org/plugins/syndication-links/
GNU General Public License v2.0
30 stars 13 forks source link

PHP Fatal error: Uncaught TypeError: array_merge(): Argument #2 must be of type array, string given in syndication-links/includes/class-syn-meta.php:97 #176

Closed janboddez closed 1 year ago

janboddez commented 1 year ago

Might be an edge case, but I ran into this playing around with the settings.

In short, I disabled all post types (which maybe you shouldn't do, but it is possible ...). Looks like the option is then deleted (?), causing get_option() to return an empty string (the default).

Could likely be fixed by adding a default option (get_option( '<something-something>', array() ), or checking for an empty value (if ( empty( $post_types ) ) and so on ...).

Speaking of: what is the preferred way to not append any links to post_content but keep the WP-Admin meta box? Remove the the_content filter? (I'm looking into doing this in a block outside the post content / e-content.) There's a "no display" setting, but I was under the impression that this would still add hidden links.

dshanske commented 1 year ago

@janboddez It is in the readme.

syndication_links_display( true ) - Adds Syndication Links to content display.

Just add a false return to this filter.

janboddez commented 1 year ago

Just FYI: the actual issue is definitely still present.

[10-Feb-2023 12:39:10 UTC] PHP Fatal error:  Uncaught TypeError: array_merge(): Argument #2 must be of type array, string given in <...>/syndication-links/includes/class-syn-meta.php:97
Stack trace:
#0 <...>/syndication-links/includes/class-syn-meta.php(97): array_merge()
#1 <...>/syndication-links/includes/class-syn-meta.php(102): Syn_Meta::screens()
... 

Reappeared the moment I reinstalled and activated the (latest version of the) plugin. (Presumably because the faulty setting is never purged, which is okay, as long as the code itself is able to handle it.)

dshanske commented 1 year ago

I'll do the full array check then

janboddez commented 1 year ago

Can give it another look later too. Might be sufficient to cast to an array, which I think would give you either an empty array or one with an empty string in it, at least until one or more post types are selected and saved. That would likely prevent the fatal error.

dshanske commented 1 year ago

I have to upgrade my dev testing from 7.4 to 8.

dshanske commented 1 year ago

@janboddez Check again?

janboddez commented 1 year ago

I now get, or rather, got the error on the settings page only instead of it taking down the entire site. :-)

image

Mind you, I did not purge the settings from the database before reinstalling. Once I selected that first unlabeled checkbox and forced the form to submit, the error disappeared.

janboddez commented 1 year ago

I'll have a look at the actual error as soon as I get the chance. (No longer actively using the plugin so it's not super urgent [for me] ...)

dshanske commented 1 year ago

Tried the other way of dealing with this.

janboddez commented 1 year ago

This works/no longer throws an error.