PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.16.9
GiveWP – Donation Plugin and Fundraising Platform v4.16.9
4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 All 255 releases
← All changes | src/Subscriptions/SubscriptionsAdminPage.php +31 -67 2.30.04.16.9 View file →
@@ -1,88 +1,44 @@
1 1 <?php
2 2
3 3 namespace Give\Subscriptions;
4 4
5 -use Give\Framework\Database\DB;
6 -use Give\Helpers\EnqueueScript;
7 -use Give\Subscriptions\ListTable\SubscriptionsListTable;
5 +use Give\Subscriptions\Actions\LoadSubscriptionDetailsAssets;
6 +use Give\Subscriptions\Actions\LoadSubscriptionsListTableAssets;
7 +use Give\Subscriptions\Models\Subscription;
8 8
9 9 class SubscriptionsAdminPage
10 10 {
11 11 /**
12 - * @var string
12 + * @since 2.24.0
13 13 */
14 - private $apiRoot;
15 -
16 - /**
17 - * @var string
18 - */
19 - private $apiNonce;
20 -
21 - /**
22 - * @var string
23 - */
24 - private $adminUrl;
25 -
26 - public function __construct()
14 + public function loadScripts()
27 15 {
28 - $this->apiRoot = esc_url_raw(rest_url('give-api/v2/admin/subscriptions'));
29 - $this->apiNonce = wp_create_nonce('wp_rest');
30 - $this->adminUrl = admin_url();
16 + give(LoadSubscriptionsListTableAssets::class)();
31 17 }
32 18
33 19 /**
34 - * @since 2.24.0
20 + * Render the Subscription Details page.
21 + *
22 + * @since 4.8.0
35 23 */
36 - public function loadScripts()
24 + public function render()
37 25 {
38 - $data = [
39 - 'apiRoot' => $this->apiRoot,
40 - 'apiNonce' => $this->apiNonce,
41 - 'forms' => $this->getForms(),
42 - 'table' => give(SubscriptionsListTable::class)->toArray(),
43 - 'adminUrl' => $this->adminUrl,
44 - 'paymentMode' => give_is_test_mode(),
45 - 'pluginUrl' => GIVE_PLUGIN_URL
46 - ];
26 + if (self::isShowingDetailsPage()) {
27 + remove_action('give_forms_page_give-subscriptions', 'give_subscriptions_page');
47 28
48 - EnqueueScript::make('give-admin-subscriptions', 'assets/dist/js/give-admin-subscriptions.js')
49 - ->loadInFooter()
50 - ->registerTranslations()
51 - ->registerLocalizeData('GiveSubscriptions', $data)->enqueue();
29 + $subscription = Subscription::find(absint($_GET['id']));
52 30
53 - wp_enqueue_style(
54 - 'give-admin-ui-font',
55 - 'https://fonts.googleapis.com/css2?family=Open+Sans:wght@400..700&display=swap',
56 - [],
57 - null
58 - );
59 - }
31 + if ( ! $subscription) {
32 + wp_die(__('Subscription not found', 'give'), 404);
33 + }
60 34
61 - /**
62 - * Retrieve a list of donation forms to populate the form filter dropdown
63 - *
64 - * @since 2.24.0
65 - *
66 - * @return array
67 - */
68 - private function getForms()
69 - {
70 - $options = DB::table('posts')
71 - ->select(
72 - ['ID', 'value'],
73 - ['post_title', 'text']
74 - )
75 - ->where('post_type', 'give_forms')
76 - ->whereIn('post_status', ['publish', 'draft', 'pending', 'private'])
77 - ->getAll(ARRAY_A);
35 + give(LoadSubscriptionDetailsAssets::class)();
36 + } else {
37 + give(LoadSubscriptionsListTableAssets::class)();
38 + }
78 39
79 - return array_merge([
80 - [
81 - 'value' => '0',
82 - 'text' => 'Any',
83 - ]
84 - ], $options);
40 + echo '<div id="give-admin-subscriptions-root"></div>';
85 41 }
86 42
87 43 /**
88 44 * Display a button on the old subscriptions table that switches to the React view
@@ -105,9 +61,9 @@
105 61 });
106 62 }
107 63 jQuery( function() {
108 64 jQuery(jQuery(".wrap .wp-header-end")).before(
109 - '<button class="page-title-action" onclick="showReactTable()">Switch to New View</button>'
65 + '<button class="page-title-action" onclick="showReactTable()"><?php _e('Switch to New View', 'give') ?></button>'
110 66 );
111 67 });
112 68 </script>
113 69 <?php
@@ -121,7 +77,15 @@
121 77 * @return bool
122 78 */
123 79 public static function isShowing()
124 80 {
125 - return isset($_GET['page']) && $_GET['page'] === 'give-subscriptions' && !isset($_GET['view']);
81 + return isset($_GET['page']) && $_GET['page'] === 'give-subscriptions' && ! isset($_GET['view']);
82 + }
83 +
84 + /**
85 + * @since 4.8.0
86 + */
87 + public static function isShowingDetailsPage(): bool
88 + {
89 + return isset($_GET['id'], $_GET['page']) && 'give-subscriptions' === $_GET['page'];
126 90 }
127 91 }