PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 3.19.2
GiveWP – Donation Plugin and Fundraising Platform v3.19.2
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 2.31.0 2.31.1 All 253 releases
← All changes | src/Subscriptions/SubscriptionsAdminPage.php +66 -30 4.16.03.19.2 View file →
@@ -1,44 +1,88 @@
1 1 <?php
2 2
3 3 namespace Give\Subscriptions;
4 4
5 -use Give\Subscriptions\Actions\LoadSubscriptionDetailsAssets;
6 -use Give\Subscriptions\Actions\LoadSubscriptionsListTableAssets;
7 -use Give\Subscriptions\Models\Subscription;
5 +use Give\Framework\Database\DB;
6 +use Give\Helpers\EnqueueScript;
7 +use Give\Subscriptions\ListTable\SubscriptionsListTable;
8 8
9 9 class SubscriptionsAdminPage
10 10 {
11 11 /**
12 + * @var string
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()
27 + {
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();
31 + }
32 +
33 + /**
12 34 * @since 2.24.0
13 35 */
14 36 public function loadScripts()
15 37 {
16 - give(LoadSubscriptionsListTableAssets::class)();
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 + ];
47 +
48 + EnqueueScript::make('give-admin-subscriptions', 'assets/dist/js/give-admin-subscriptions.js')
49 + ->loadInFooter()
50 + ->registerTranslations()
51 + ->registerLocalizeData('GiveSubscriptions', $data)->enqueue();
52 +
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 + );
17 59 }
18 60
19 61 /**
20 - * Render the Subscription Details page.
62 + * Retrieve a list of donation forms to populate the form filter dropdown
21 63 *
22 - * @since 4.8.0
64 + * @since 2.24.0
65 + *
66 + * @return array
23 67 */
24 - public function render()
68 + private function getForms()
25 69 {
26 - if (self::isShowingDetailsPage()) {
27 - remove_action('give_forms_page_give-subscriptions', 'give_subscriptions_page');
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);
28 78
29 - $subscription = Subscription::find(absint($_GET['id']));
30 -
31 - if ( ! $subscription) {
32 - wp_die(__('Subscription not found', 'give'), 404);
33 - }
34 -
35 - give(LoadSubscriptionDetailsAssets::class)();
36 - } else {
37 - give(LoadSubscriptionsListTableAssets::class)();
38 - }
39 -
40 - echo '<div id="give-admin-subscriptions-root"></div>';
79 + return array_merge([
80 + [
81 + 'value' => '0',
82 + 'text' => __('Any', 'give'),
83 + ]
84 + ], $options);
41 85 }
42 86
43 87 /**
44 88 * Display a button on the old subscriptions table that switches to the React view
@@ -77,15 +121,7 @@
77 121 * @return bool
78 122 */
79 123 public static function isShowing()
80 124 {
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'];
125 + return isset($_GET['page']) && $_GET['page'] === 'give-subscriptions' && !isset($_GET['view']);
90 126 }
91 127 }