= 5 * - Never shown OR shown 7+ days ago * - User hasn't clicked "never ask again" * * @param int $user_id The user ID. * @return bool True if rating should be shown, false otherwise. */ public static function should_show_rating( $user_id ) { $user_id = absint( $user_id ); // Check if user permanently dismissed $never_show = get_user_meta( $user_id, self::META_KEY_NEVER_SHOW, true ); if ( $never_show ) { return false; } // Check generation threshold $generation_count = self::get_generation_count( $user_id ); if ( $generation_count < self::GENERATION_THRESHOLD ) { return false; } // Check if never shown before $last_shown = get_user_meta( $user_id, self::META_KEY_RATING_SHOWN, true ); if ( ! $last_shown ) { return true; } // Check cooldown (7 days) $last_shown_timestamp = absint( $last_shown ); $days_since = floor( ( time() - $last_shown_timestamp ) / DAY_IN_SECONDS ); return $days_since >= self::REMINDER_COOLDOWN_DAYS; } /** * Mark rating to never show again for user. * * @param int $user_id The user ID. * @return void */ public static function mark_never_show( $user_id ) { $user_id = absint( $user_id ); update_user_meta( $user_id, self::META_KEY_NEVER_SHOW, true ); } /** * Get rating modal data for display. * * @param int $user_id The user ID. * @return array|false Array with modal data if should show, false otherwise. */ public static function get_modal_data( $user_id ) { if ( ! self::should_show_rating( $user_id ) ) { return false; } return array( 'should_show' => true, 'generation_count' => self::get_generation_count( $user_id ), 'user_id' => $user_id, 'wordpress_review_url' => 'https://wordpress.org/plugins/ai-story-maker/#reviews', ); } /** * Reset generation count and rating state (for testing). * * @param int $user_id The user ID. * @return void */ public static function reset_for_testing( $user_id ) { $user_id = absint( $user_id ); delete_user_meta( $user_id, self::META_KEY_GENERATION_COUNT ); delete_user_meta( $user_id, self::META_KEY_RATING_SHOWN ); delete_user_meta( $user_id, self::META_KEY_NEVER_SHOW ); } }