get_var( $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE status IN ( %s, %s, %s )', $table, 'applied', 'partially_applied', 'reverted' ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching } /** * Whether the request is shown to the current user now. */ public static function eligible(): bool { if ( ! current_user_can( Config::settings_capability() ) ) { return false; } if ( get_user_meta( get_current_user_id(), self::META, true ) ) { return false; } return self::approved_count() >= self::THRESHOLD; } /** * «Leave a review» (opens wordpress.org) or «Don't ask again»: either answers the request for good. */ public function handle(): void { if ( ! current_user_can( Config::settings_capability() ) ) { wp_die( esc_html__( 'You are not allowed to access this page.', 'addsynapse-store-assistant' ), 403 ); } check_admin_referer( self::ACTION ); $choice = isset( $_POST['addsynapse_assistant_review'] ) ? sanitize_key( wp_unslash( $_POST['addsynapse_assistant_review'] ) ) : ''; update_user_meta( get_current_user_id(), self::META, 'review' === $choice ? 'review' : 'dismissed' ); if ( 'review' === $choice ) { add_filter( 'allowed_redirect_hosts', array( self::class, 'allow_host' ) ); wp_safe_redirect( self::REVIEW_URL ); exit; } $tab = isset( $_POST['addsynapse_assistant_tab'] ) ? sanitize_key( wp_unslash( $_POST['addsynapse_assistant_tab'] ) ) : ''; wp_safe_redirect( 'settings' === $tab ? SettingsPage::url() : AdminPage::url() ); exit; } /** * Allows wordpress.org for the «Leave a review» redirect. * * @param mixed $hosts Hosts. * @return array */ public static function allow_host( $hosts ): array { $hosts = is_array( $hosts ) ? $hosts : array(); $hosts[] = self::HOST; return $hosts; } /** * The request (server-rendered, on the plugin's own screen). * * @param string $tab chat | settings. */ public static function render( string $tab ): void { if ( ! self::eligible() ) { return; } $count = self::approved_count(); echo '
'; /* translators: %d: number of approved changes. */ echo '

' . esc_html( sprintf( _n( 'You have approved %d change with Store Assistant.', 'You have approved %d changes with Store Assistant.', $count, 'addsynapse-store-assistant' ), $count ) ) . ' '; echo esc_html__( 'If it saves you time, a short review on WordPress.org helps other shop owners find it.', 'addsynapse-store-assistant' ) . '

'; echo '
'; wp_nonce_field( self::ACTION ); echo ''; echo ''; echo ' '; echo ''; echo '
'; } }