PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.6.60
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.6.60
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / admin / settings / class-charitable-licenses-settings.php

class-charitable-licenses-settings.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.6.60, at includes/admin/settings/class-charitable-licenses-settings.php

212 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Licenses Settings UI.
4 *
5 * @package Charitable/Classes/Charitable_Licenses_Settings
6 * @version 1.0.0
7 * @author Eric Daams
8 * @copyright Copyright (c) 2022, Studio 164a
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 if ( ! class_exists( 'Charitable_Licenses_Settings' ) ) :
18
19 /**
20 * Charitable_Licenses_Settings
21 *
22 * @final
23 * @since 1.0.0
24 */
25 final class Charitable_Licenses_Settings {
26
27 /**
28 * The single instance of this class.
29 *
30 * @var Charitable_Licenses_Settings|null
31 */
32 private static $instance = null;
33
34 /**
35 * Create object instance.
36 *
37 * @since 1.0.0
38 */
39 private function __construct() {
40 }
41
42 /**
43 * Returns and/or create the single instance of this class.
44 *
45 * @since 1.2.0
46 *
47 * @return Charitable_Licenses_Settings
48 */
49 public static function get_instance() {
50 if ( is_null( self::$instance ) ) {
51 self::$instance = new self();
52 }
53
54 return self::$instance;
55 }
56
57 /**
58 * Optionally add the licenses tab.
59 *
60 * @since 1.4.7
61 *
62 * @param string[] $tabs Settings tabs.
63 * @return string[]
64 */
65 public function maybe_add_licenses_tab( $tabs ) {
66
67 $products = charitable_get_helper( 'licenses' )->get_products();
68
69 if ( empty( $products ) ) {
70 return $tabs;
71 }
72
73 $tabs = charitable_add_settings_tab(
74 $tabs,
75 'licenses',
76 __( 'Licenses', 'charitable' ),
77 array(
78 'index' => 4,
79 )
80 );
81
82 return $tabs;
83
84 }
85
86 /**
87 * Add the licenses tab settings fields.
88 *
89 * @since 1.0.0
90 *
91 * @return array
92 */
93 public function add_licenses_fields() {
94 if ( ! charitable_is_settings_view( 'licenses' ) ) {
95 return array();
96 }
97
98 $fields = array(
99 'section' => array(
100 'title' => '',
101 'type' => 'hidden',
102 'priority' => 10000,
103 'value' => 'licenses',
104 'save' => false,
105 ),
106 'licenses' => array(
107 'title' => false,
108 'callback' => array( $this, 'render_licenses_table' ),
109 'priority' => 4,
110 ),
111 );
112
113 foreach ( charitable_get_helper( 'licenses' )->get_products() as $key => $product ) {
114 $fields[ $key ] = array(
115 'type' => 'text',
116 'render' => false,
117 'priority' => 6,
118 );
119 }
120
121 return $fields;
122 }
123
124 /**
125 * Add the licenses group.
126 *
127 * @since 1.0.0
128 *
129 * @param string[] $groups Settings groups.
130 * @return string[]
131 */
132 public function add_licenses_group( $groups ) {
133 $groups['licenses'] = array();
134 return $groups;
135 }
136
137 /**
138 * Render the licenses table.
139 *
140 * @since 1.0.0
141 *
142 * @return void
143 */
144 public function render_licenses_table() {
145 charitable_admin_view( 'settings/licenses' );
146 }
147
148 /**
149 * Add an extra button to the Licenses tab to re-check licenses.
150 *
151 * @since 1.6.0
152 *
153 * @param string $button The button HTML.
154 * @return string
155 */
156 public function add_license_recheck_button( $button ) {
157 $licenses = array_filter( charitable_get_helper( 'licenses' )->get_licenses(), 'is_array' );
158
159 if ( empty( $licenses ) ) {
160 return $button;
161 }
162
163 $html = '<input style="margin-left:8px;height:29px;" type="submit" class="button button-secondary" name="recheck" value="' . esc_attr__( 'Save & Re-check All Licenses', 'charitable' ) . '" /></p>';
164
165 return str_replace(
166 '</p>',
167 $html,
168 $button
169 );
170 }
171
172 /**
173 * Checks for updated license and invalidates status field if not set.
174 *
175 * @since 1.0.0
176 *
177 * @param mixed[] $values The parsed values combining old values & new values.
178 * @param mixed[] $new_values The newly submitted values.
179 * @return mixed[]
180 */
181 public function save_license( $values, $new_values ) {
182 /* If we didn't just submit licenses, stop here. */
183 if ( ! isset( $new_values['licenses'] ) ) {
184 return $values;
185 }
186
187 $re_check = array_key_exists( 'recheck', $_POST );
188 $licenses = $new_values['licenses'];
189
190 foreach ( $licenses as $product_key => $license ) {
191 $license = trim( $license );
192
193 if ( empty( $license ) ) {
194 $values['licenses'][ $product_key ] = '';
195 continue;
196 }
197
198 $license_data = charitable_get_helper( 'licenses' )->verify_license( $product_key, $license, $re_check );
199
200 if ( empty( $license_data ) ) {
201 continue;
202 }
203
204 $values['licenses'][ $product_key ] = $license_data;
205 }
206
207 return $values;
208 }
209 }
210
211 endif;
212