• Resolved thunder

    (@thunderdw)


    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 a usort 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 usort

    Here’s the code causing the issue. This is lines 1160-1198 of classes/Model/Popup.php – the usort callback compare_resets is returning a bool not an int.

    /**
     * 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 with timestamp 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}
    "} 
    
    • This topic was modified 1 year, 7 months ago by thunder.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Bel

    (@belimperial)

    Hi @thunderdw

    Thank you for reaching out, and for this information.

    We tried to reproduce the issue, but all popup options are showing when using WordPress Gutenberg.

    Please see: https://share.getcloudapp.com/v1uPAEqJ

    Can you provide steps or screen capture on how we can reproduce the issue to help the investigation?

    We might also need to take a closer look at your site. Can you send us a message through our support form? 

    <u>https://wppopupmaker.com/support/#submit-a-support-ticket</u&gt;

    Please include the page link(s) with a popup.

    Thank you!

    Thread Starter thunder

    (@thunderdw)

    Thanks for getting back to me. I’m won’t have bandwidth to dig deeper into this until later this week – I’ll reply with the info requested then.

    But the deprecation error is happening at all because the compare_resets callback does not follow the PHP specification for a callback for the PHP usort function. Is it possible for PUM to take a look into aligning that function to the PHP spec? As long as it doesn’t align to the specification this kind of error has the potential to happen regardless of the root cause.

    Thanks so much for your help!

    Thread Starter thunder

    (@thunderdw)

    Didn’t realize there was a Github repo for this plugin – I’ll move this issue there since it isn’t really a support issue. Thank you again!

    Plugin Support Kim L

    (@kimmyx)

    Hi @thunderdw,

    Thanks for the update!

    I’ll now mark this thread as resolved since the issue has been moved to our github.

    Feel free to create a new thread if you have other questions.

    Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Popup Maker function returns wrong type, can prevent popup options from showing’ is closed to new replies.