return_optimized_images() ->set_paging_size( 1 ) ->execute(); if ( ! $optimized_image_query->post_count ) { return false; } return true; } /** * Checks if the notice should be rendered after the one third of images were optimized. * * @param bool $check_location * * @return bool */ public function should_render_third_optimized_notice( bool $check_location = true ): bool { if ( Pointers::is_dismissed( self::THIRD_OF_IMAGES_OPTIMIZED_FEEDBACK_SLUG ) ) { return false; } if ( $check_location && ! Utils::is_plugin_settings_page() ) { return false; } $images_query = ( new Image_Query_Builder() ) ->execute(); $optimized_images_query = ( new Image_Query_Builder() ) ->return_optimized_images() ->execute(); if ( ! $optimized_images_query->post_count ) { return false; } $optimized_percentage = round( $optimized_images_query->post_count / $images_query->post_count * 100 ); if ( $optimized_percentage < 33.33 ) { return false; } return true; } /** * Renders the notice after the first optimization. * * @return void */ public function render_first_optimized_notice() { ?>

★★★★★ review to spread the word.', 'image-optimization' ), esc_url( self::NOTICE_FEEDBACK_LINK ), esc_attr__( 'Five stars', 'image-optimization' ) ) ); ?>

★★★★★ review to spread the word.', 'image-optimization' ), esc_url( self::NOTICE_FEEDBACK_LINK ), esc_attr__( 'Five stars', 'image-optimization' ) ) ); ?>

Found Image Optimization helpful? Leave us a ★★★★★ rating!', 'image-optimization' ), esc_url( self::FOOTER_FEEDBACK_LINK ), esc_attr__( 'Five stars', 'image-optimization' ) ) ); } public function __construct() { add_action('current_screen', function () { if ( ! Utils::user_is_admin() ) { return; } if ( $this->should_render_first_optimized_notice() ) { add_action( 'admin_notices', [ $this, 'render_first_optimized_notice' ] ); } if ( $this->should_render_third_optimized_notice() ) { add_action( 'admin_notices', [ $this, 'render_third_optimized_notice' ] ); } if ( Utils::is_media_page() || Utils::is_plugin_page() || Utils::is_single_attachment_page() ) { add_filter( 'admin_footer_text', [ $this, 'add_leave_feedback_footer_text' ] ); } }); } }