$preview ) ); echo paygrab_get_template( 'preview-page', array( 'html' => $html ) ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- a full page built from escaped templates. exit; } /** * What the theme loads in header.php, which the preview page does not use. * TCD themes enqueue their style.css and jQuery there; without them the preview * would be drawn without the theme's styles, and theme scripts stop on "jQuery is not defined". * * @return void */ public static function theme_assets() { wp_enqueue_script( 'jquery' ); $sheet = strtok( get_stylesheet_uri(), '?' ); foreach ( wp_styles()->queue as $handle ) { $src = wp_styles()->registered[ $handle ]->src ?? ''; if ( is_string( $src ) && '' !== $src && strtok( $src, '?' ) === $sheet ) { return; } } wp_enqueue_style( 'paygrab-preview-theme', $sheet, array(), (string) wp_get_theme()->get( 'Version' ) ); } /** * Clean the values sent by the form. * * @param array $v Raw values. * @return array Preview arguments for Paygrab_Product::buy_box(). */ private static function values( array $v ) { $id = isset( $v['id'] ) ? absint( $v['id'] ) : 0; $id = $id && Paygrab_Product::TYPE === get_post_type( $id ) ? $id : 0; $file = $id ? Paygrab_Product::data( $id )['file'] : null; if ( ! empty( $v['file'] ) && is_array( $v['file'] ) ) { $file = array( 'name' => sanitize_file_name( (string) ( $v['file']['name'] ?? 'file.zip' ) ), 'size' => absint( $v['file']['size'] ?? 0 ), 'path' => '', ); } elseif ( array_key_exists( 'file', $v ) && null === $v['file'] ) { $file = null; } return array( 'id' => $id, 'title' => sanitize_text_field( (string) ( $v['title'] ?? '' ) ), 'excerpt' => Paygrab_Product::clean_excerpt( (string) ( $v['excerpt'] ?? '' ) ), 'state' => sanitize_key( (string) ( $v['state'] ?? 'buy' ) ), 'data' => array( 'price' => min( 10000000, absint( $v['price'] ?? 0 ) ), 'limit' => min( 1000, absint( $v['limit'] ?? 0 ) ), 'days' => min( 3650, absint( $v['days'] ?? 0 ) ), 'on_sale' => ! empty( $v['onSale'] ), 'file' => $file, // An image chosen in the form, or 'sample' for the design settings. 'image' => isset( $v['image'] ) && 'sample' === $v['image'] ? 'sample' : ( isset( $v['image'] ) && wp_attachment_is_image( absint( $v['image'] ) ) ? absint( $v['image'] ) : 0 ), ), ); } }