PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / shortcode / order-downloads.php

order-downloads.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/shortcode/order-downloads.php

75 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Shortcode;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9 use StoreEngine\Classes\DownloadPermission;
10 use StoreEngine\Utils\Formatting;
11 use StoreEngine\Utils\Helper;
12 use StoreEngine\Utils\Template;
13 use WP_Error;
14
15 class OrderDownloads {
16
17 public function __construct() {
18 add_shortcode( 'storeengine_order_downloads', [ $this, 'render' ] );
19 }
20
21 public function render( $atts ) {
22 $attributes = shortcode_atts( [ 'dummy' => false ], $atts );
23 $dummy = Formatting::string_to_bool( $attributes['dummy'] );
24
25 if ( ! $dummy ) {
26 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
27 $order_hash = isset( $_GET['order_hash'] ) ? sanitize_text_field( wp_unslash( $_GET['order_hash'] ) ) : '';
28 $order = Helper::get_order_by_key( $order_hash );
29 $order = $order instanceof WP_Error ? false : $order;
30
31 // Fall back to sample content when there's no real order to show
32 // (page opened directly, previewed, or rendered in the editor).
33 if ( ! $order ) {
34 $dummy = true;
35 }
36 }
37
38 $downloadable_permissions = $dummy
39 ? self::get_dummy_permissions()
40 : apply_filters( 'storeengine/order/downloadable_permissions', $order->get_downloadable_permissions(), $order );
41
42 ob_start();
43 Template::get_template( 'shortcode/order-downloads.php', [
44 'downloadable_permissions' => $downloadable_permissions,
45 ] );
46
47 return ob_get_clean();
48 }
49
50 /**
51 * A sample download row for previews / empty-order rendering. The template
52 * only reads the product title, file name and download URL, so a lightweight
53 * {@see DownloadPermission} subclass overriding just those three is enough.
54 *
55 * @return DownloadPermission[]
56 */
57 protected static function get_dummy_permissions(): array {
58 $permission = new class( 0 ) extends DownloadPermission {
59 public function get_product_title(): string {
60 return __( 'Sample product', 'storeengine' );
61 }
62
63 public function get_file_name(): string {
64 return __( 'sample-file.zip', 'storeengine' );
65 }
66
67 public function get_download_url(): string {
68 return '#';
69 }
70 };
71
72 return [ $permission ];
73 }
74 }
75