'POST', 'callback' => array( __CLASS__, 'rest_choice' ), 'permission_callback' => function () { return current_user_can( 'manage_options' ); }, 'args' => array( 'choice' => array( 'type' => 'string', 'enum' => array( 'done', 'later', 'never' ), 'required' => true, ), ), ) ); } /** * REST-Antwort. * * @param WP_REST_Request $request Anfrage. * @return WP_REST_Response */ public static function rest_choice( $request ) { $stand = self::state( get_current_user_id() ); $wahl = (string) $request['choice']; if ( 'later' === $wahl ) { $stand['state'] = 'later'; $stand['until'] = time() + self::LATER_DAYS * DAY_IN_SECONDS; } else { $stand['state'] = $wahl; } ++$stand['asked']; update_user_meta( get_current_user_id(), self::META, $stand ); return rest_ensure_response( array( 'state' => $stand['state'] ) ); } /** * Veröffentlichte Bewertungen dieser Seite (gefiltert über threerb_thanks_count). * * @return int */ public static function count() { $q = new WP_Query( array( 'post_type' => (array) ThreeRB_Settings::value( 'post_types' ), 'post_status' => 'publish', 'meta_key' => ThreeRB_Box::META_SCORE, // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- eine Zählung auf der eigenen Verwaltungsseite. 'fields' => 'ids', 'posts_per_page' => 1, 'no_found_rows' => false, ) ); /** * Zahl der Bewertungen, nach der die Danke-Karte fragt. * * @param int $anzahl Veröffentlichte Beiträge mit Bewertung. */ return (int) apply_filters( 'threerb_thanks_count', (int) $q->found_posts ); } /** * Karte für einen Reiter der eigenen Verwaltung, oder leer. * * @param string $tab Reiter. * @return string */ public static function card( $tab ) { if ( ! in_array( $tab, array( 'overview', 'boxes' ), true ) || ! current_user_can( 'manage_options' ) ) { return ''; } $installiert = (int) get_option( self::INSTALLED, 0 ); if ( $installiert < 1 ) { add_option( self::INSTALLED, time(), '', false ); return ''; } if ( time() - $installiert < self::WAIT_DAYS * DAY_IN_SECONDS ) { return ''; } $stand = self::state( get_current_user_id() ); if ( in_array( $stand['state'], array( 'done', 'never' ), true ) || $stand['asked'] >= self::MAX_ASKS || ( 'later' === $stand['state'] && time() < $stand['until'] ) ) { return ''; } $anzahl = self::count(); if ( $anzahl < self::MIN_REVIEWS ) { return ''; } $html = '
'; $html .= ''; /* translators: %d: number of published reviews written with the plugin. */ $html .= '

' . esc_html( sprintf( _n( 'You have published %d review with Review Box. Thank you.', 'You have published %d reviews with Review Box. Thank you.', $anzahl, '3task-review-box' ), $anzahl ) ) . '

'; $html .= '

' . esc_html__( 'You know better than most how much an honest review is worth: it takes time, and it helps the next person decide.', '3task-review-box' ) . '

'; $html .= '

' . esc_html__( 'I am Frank, and I build Review Box in the evenings next to my job, without ads and without tracking. Nobody has to pay for it. What keeps it going is hearing from the people who use it.', '3task-review-box' ) . '

'; $html .= '

' . esc_html__( 'Would you leave a short review on WordPress.org? One honest sentence is enough, good or critical. If something is missing, tell me in the support forum and I will look at it.', '3task-review-box' ) . '

'; $html .= '

'; $html .= '' . esc_html__( 'Write a review on WordPress.org', '3task-review-box' ) . ' '; $html .= '' . esc_html__( 'Something is missing? Tell me', '3task-review-box' ) . ' '; $html .= ' · '; $html .= ''; $html .= '

' . esc_html__( 'This note appears at most twice and never outside the Review Box pages. Nothing changes in the plugin, whatever you choose.', '3task-review-box' ) . '

'; return $html; } /** * Gespeicherte Entscheidung eines Nutzers. * * @param int $user_id Nutzer. * @return array{state:string, until:int, asked:int} */ private static function state( $user_id ) { $roh = get_user_meta( (int) $user_id, self::META, true ); $roh = is_array( $roh ) ? $roh : array(); return array( 'state' => isset( $roh['state'] ) && in_array( $roh['state'], array( 'done', 'later', 'never' ), true ) ? $roh['state'] : '', 'until' => isset( $roh['until'] ) ? (int) $roh['until'] : 0, 'asked' => isset( $roh['asked'] ) ? max( 0, (int) $roh['asked'] ) : 0, ); } }