Popup Maker function returns wrong type, can prevent popup options from showing
-
This bug is happening on version 1.18.0 of the plugin.
The plugin is returning a boolean in the callback for for a
usort
function, but PHP requires the callback for ausort
to be an integer. This is causing the popup options to not show at the bottom of the Gutenberg editor on some of my popups.The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second.
PHP Documentation on usortHere’s the code causing the issue. This is lines 1160-1198 of
classes/Model/Popup.php
– theusort
callbackcompare_resets
is returning abool
not anint
./** * Returns the last reset information. * * @return mixed */ public function get_last_count_reset() { $resets = $this->get_meta( 'popup_count_reset', false ); if ( empty( $resets ) ) { // No results found. return false; } if ( ! empty( $resets['timestamp'] ) ) { // Looks like the result is already the last one, return it. return $resets; } if ( count( $resets ) === 1 ) { // Looks like we only got one result, return it. return $resets[0]; } usort( $resets, [ $this, 'compare_resets' ] ); return $resets[0]; } /** * Array comparison callback function comparing timestamps. * * @param array $a Array with
timestamp
key for comparison. * @param array $b Array withtimestamp
key for comparison. * * @return bool */ public function compare_resets( $a, $b ) { return (float) $a['timestamp'] < (float) $b['timestamp']; }On my site, certain popups are not displaying the popup options in the editor as a result – they still display correctly on the frontend. I’m using PHP 8.1.
Here’s the stack trace from the error:
development.ERROR: usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero {"userId":30,"exception":"[object] (ErrorException(code: 0): usort(): Returning bool from comparison function is deprecated, return an integer less than, equal to, or greater than zero at /app/web/app/plugins/popup-maker/classes/Model/Popup.php:1183) [stacktrace] #0 /app/web/app/plugins/popup-maker/classes/Model/Popup.php(1183): usort(Array, Array) #1 /app/web/app/plugins/popup-maker/classes/Admin/Popups.php(1070): PUM_Model_Popup->get_last_count_reset() #2 /app/web/wp/wp-admin/includes/template.php(1409): PUM_Admin_Popups::render_analytics_meta_box(Object(WP_Post), Array) #3 /app/web/wp/wp-admin/includes/post.php(2249): do_meta_boxes(Object(WP_Screen), 'side', Object(WP_Post)) #4 /app/web/wp/wp-admin/edit-form-blocks.php(316): the_block_editor_meta_boxes() #5 /app/web/wp/wp-admin/post.php(187): require('/app/web/wp/wp-...') #6 {main} "}
- The topic ‘Popup Maker function returns wrong type, can prevent popup options from showing’ is closed to new replies.