*/ public static function defaults(): array { return [ 'photo' => self::PHOTO_REQUIRED, 'media_image' => true, 'media_audio' => true, 'media_video' => true, 'instagram_id' => true, 'instagram_purchase' => false, 'product_pick' => self::PRODUCT_OFF, ]; } /** * The effective configuration. * * `product_pick` reads as off without WooCommerce whatever is stored, so a * shop that deactivates it is not left with a picker searching nothing. * * @return array{photo:string, media:list, instagram_id:bool, instagram_purchase:bool, product_pick:string} */ public static function get(): array { $s = array_merge( self::defaults(), Settings::all( 'testimonials' ) ); $photo = in_array( $s['photo'], [ self::PHOTO_REQUIRED, self::PHOTO_OPTIONAL, self::PHOTO_OFF ], true ) ? (string) $s['photo'] : self::PHOTO_REQUIRED; $media = []; foreach ( [ 'image', 'audio', 'video' ] as $kind ) { if ( ! empty( $s[ 'media_' . $kind ] ) ) { $media[] = $kind; } } $product = in_array( $s['product_pick'], [ self::PRODUCT_ALL, self::PRODUCT_PURCHASED ], true ) ? (string) $s['product_pick'] : self::PRODUCT_OFF; if ( ! class_exists( 'WooCommerce' ) ) { $product = self::PRODUCT_OFF; } return [ 'photo' => $photo, 'media' => $media, 'instagram_id' => ! empty( $s['instagram_id'] ), 'instagram_purchase' => ! empty( $s['instagram_purchase'] ), 'product_pick' => $product, ]; } /** * What a theme needs to draw the form: the configuration plus the picker's * endpoint. * * @internal Hooked callback for `rahkar_wp_testimonials_form`. * * @return array */ public static function forTheme(): array { $config = self::get(); $config['endpoints'] = [ 'products' => self::PRODUCT_OFF === $config['product_pick'] ? '' : esc_url_raw( rest_url( 'rahkar/v1/testimonial/products' ) ), ]; return $config; } }