[BUG] Plugin breaks REST search
-
Hi!
I’m running version 5.3.5 of Modern Events Calendar Lite and it is breaking the
/v2/search
REST endpoint, which manifests itself primarily as no other post types other than events showing up in the link creation search box in Gutenberg.Steps to reproduce
- Make a new post/page using Gutenberg, select some text and press “Link”
- Type in the title of an existing post/page
Nothing appears (besides any MEC events that happen to match the keywords)
Repeat the above after disabling Modern Event Calendar Lite and your posts, pages and everything else will apperar again.
Cause
On line 242 of plugin file
./app/features/search.php
a check is made to determine whether to take over a search query. If thepost_type
array containsmec-events
, the query is rewritten and on line 304, limited to only themec-events
post type.The problem with this is that the post_type array may have contained other post types that should have been searched, but were removed by the function. This is the case with the Gutenberg search box, as it is designed to search all post types, which includes
mec-events
.Proposed fix
I updated the aforementioned condition to not only check if
mec-events
is present in thepost_types
array, but also that it is the only one (array length is at most 1). This fixes the issue.if((is_array($query->get('post_type')) and (!in_array('mec-events', $query->get('post_type')) or count($query->get('post_type')) > 1)) or (!is_array($query->get('post_type')) and $query->get('post_type') != 'mec-events')) return $query;
Note
I have not tested whether my fix breaks any aspect of event searching/filtering, as I do not use those features.
I would also like to ask you to notify me when a fix for this issue lands, as I will be avoiding updating the plugin until then to prevent my hotfix from being undone.
- The topic ‘[BUG] Plugin breaks REST search’ is closed to new replies.