PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
1.4.3 1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 All 182 releases
datafeedr-api / hooks / admin / admin-notices.php

admin-notices.php in Datafeedr API 1.4.3, at hooks/admin/admin-notices.php

366 lines 10.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5 /**
6 * Display Admin Notice if user has selected more than the DFRAPI_EXCESSIVE_MERCHANT_COUNT amount (default 1,000).
7 *
8 * @return void
9 */
10 function dfrapi_excessive_merchants_selected_admin_notice() {
11
12 if ( ! current_user_can( 'manage_options' ) ) {
13 return;
14 }
15
16 $merchant_count = dfrapi_selected_merchant_count();
17
18 if ( $merchant_count < DFRAPI_EXCESSIVE_MERCHANT_COUNT ) {
19 return;
20 }
21
22 $status = 'error';
23 $plugin = 'Datafeedr API';
24 $heading = __( 'Too Many Merchants Selected', 'datafeedr-api' );
25 $message = sprintf(
26 __( 'You have selected <a href="%2$s">%1$s merchants</a>. Please go to <a href="%2$s">Datafeedr API > Merchants</a> and reduce the number of merchants you have selected to be less than %3$s.', 'datafeedr-api' ),
27 number_format_i18n( $merchant_count ),
28 esc_url( dfrapi_merchants_page_url() ),
29 number_format_i18n( DFRAPI_EXCESSIVE_MERCHANT_COUNT )
30 );
31
32 dfrapi_admin_notice( $message, $status, $heading, $plugin );
33 }
34
35 add_action( 'admin_notices', 'dfrapi_excessive_merchants_selected_admin_notice' );
36
37 /**
38 * Display Admin Notice if user has not entered their Datafeedr API keys.
39 *
40 * @return void
41 */
42 function dfrapi_datafeedr_api_keys_do_not_exist_notice() {
43
44 if ( ! current_user_can( 'manage_options' ) ) {
45 return;
46 }
47
48 if ( dfrapi_datafeedr_api_keys_exist() ) {
49 return;
50 }
51
52 $status = 'error';
53 $plugin = 'Datafeedr API';
54 $heading = __( 'API Keys Missing', 'datafeedr-api' );
55 $message = sprintf(
56 __( 'You have not entered your Datafeedr API keys. Please go to <a href="%1$s">Datafeedr API > Configuration</a> and enter your Datafeedr API Access ID and Secret Key.', 'datafeedr-api' ),
57 esc_url( dfrapi_configuration_page_url() )
58 );
59
60 dfrapi_admin_notice( $message, $status, $heading, $plugin );
61 }
62
63 add_action( 'admin_notices', 'dfrapi_datafeedr_api_keys_do_not_exist_notice' );
64
65 /**
66 * Display Admin Notice if user has not selected any affiliate networks.
67 *
68 * @return void
69 */
70 function dfrapi_no_networks_selected_admin_notice() {
71
72 if ( ! current_user_can( 'manage_options' ) ) {
73 return;
74 }
75
76 // Don't display notice if at least one network has been selected.
77 if ( dfrapi_user_has_selected_networks() ) {
78 return;
79 }
80
81 // Don't display notice if user has not entered API keys yet.
82 if ( ! dfrapi_datafeedr_api_keys_exist() ) {
83 return;
84 }
85
86 $status = 'error';
87 $plugin = 'Datafeedr API';
88 $heading = __( 'No Affiliate Networks Selected', 'datafeedr-api' );
89 $message = sprintf(
90 __( 'You have not selected any affiliate networks yet. Please go to <a href="%1$s">Datafeedr API > Networks</a> and select your desired affiliate networks.', 'datafeedr-api' ),
91 esc_url( dfrapi_networks_page_url() )
92 );
93
94 dfrapi_admin_notice( $message, $status, $heading, $plugin );
95 }
96
97 add_action( 'admin_notices', 'dfrapi_no_networks_selected_admin_notice' );
98
99 /**
100 * Display Admin Notice if user has not selected any merchants.
101 *
102 * @return void
103 */
104 function dfrapi_no_merchants_selected_admin_notice() {
105
106 if ( ! current_user_can( 'manage_options' ) ) {
107 return;
108 }
109
110 // Don't display notice if at least one merchant has been selected.
111 if ( dfrapi_user_has_selected_merchants() ) {
112 return;
113 }
114
115 // Don't display notice if user has not entered API keys yet.
116 if ( ! dfrapi_datafeedr_api_keys_exist() ) {
117 return;
118 }
119
120 // Don't display notice if no networks have been selected yet.
121 if ( ! dfrapi_user_has_selected_networks() ) {
122 return;
123 }
124
125 $status = 'error';
126 $plugin = 'Datafeedr API';
127 $heading = __( 'No Merchants Selected', 'datafeedr-api' );
128 $message = sprintf(
129 __( 'You have not selected any merchants yet. Please go to <a href="%1$s">Datafeedr API > Merchants</a> and select your desired merchants.', 'datafeedr-api' ),
130 esc_url( dfrapi_merchants_page_url() )
131 );
132
133 dfrapi_admin_notice( $message, $status, $heading, $plugin );
134 }
135
136 add_action( 'admin_notices', 'dfrapi_no_merchants_selected_admin_notice' );
137
138 /**
139 * Display Admin Notice if user has used more than 90% of their API requests for this pay-period.
140 *
141 * @return void
142 */
143 function dfrapi_api_usage_over_90_percent_admin_notice() {
144
145 if ( ! current_user_can( 'manage_options' ) ) {
146 return;
147 }
148
149 if ( ! dfrapi_api_usage_over_90_percent() ) {
150 return;
151 }
152
153 $status = 'warning';
154 $plugin = 'Datafeedr API';
155 $heading = __( '90% of API Requests Used', 'datafeedr-api' );
156 $message = sprintf(
157 __( 'You have used over 90%% of your Datafeedr API requests for the current period. <a href="%1$s" target="_blank" rel="noopener nofollow">Upgrade your Datafeedr API subscription</a> to immediately access additional API requests.', 'datafeedr-api' ),
158 esc_url( dfrapi_user_pages( 'change' ) )
159 );
160
161 dfrapi_admin_notice( $message, $status, $heading, $plugin );
162 }
163
164 add_action( 'admin_notices', 'dfrapi_api_usage_over_90_percent_admin_notice' );
165
166 /**
167 * Display Admin Notice if user is missing at least 1 affiliate ID on the Networks page.
168 *
169 * @return void
170 */
171 function dfrapi_user_is_missing_affiliate_ids_admin_notice() {
172
173 if ( ! current_user_can( 'manage_options' ) ) {
174 return;
175 }
176
177 if ( ! dfrapi_user_is_missing_affiliate_ids() ) {
178 return;
179 }
180
181 $missing_count = count( dfrapi_get_network_ids_missing_affiliate_id() );
182
183 $status = 'warning';
184 $plugin = 'Datafeedr API';
185 $heading = __( 'Missing Affiliate IDs', 'datafeedr-api' );
186 $ids = translate_nooped_plural( _n_noop( 'affiliate ID', 'affiliate IDs', 'datafeedr-api' ), number_format_i18n( $missing_count ) );
187 $message = sprintf(
188 __( 'You are missing %2$d %3$s. Please go to <a href="%1$s">Datafeedr API > Networks</a> and enter your missing %3$s.', 'datafeedr-api' ),
189 esc_url( dfrapi_networks_page_url() ),
190 absint( $missing_count ),
191 esc_html( $ids )
192 );
193
194 dfrapi_admin_notice( $message, $status, $heading, $plugin );
195 }
196
197 add_action( 'admin_notices', 'dfrapi_user_is_missing_affiliate_ids_admin_notice' );
198
199 /**
200 * Display Admin Notice if user has selected a Partnerize merchant which they are not approved by.
201 *
202 * @return void
203 */
204 function dfrapi_unapproved_partnerize_merchants_selected() {
205
206 if ( ! current_user_can( 'manage_options' ) ) {
207 return;
208 }
209
210 global $wpdb;
211
212 // Get Partnerize Network IDs
213 $partnerize_network_ids = dfrapi_get_partnerize_network_ids();
214
215 // Get user's currently selected networks and convert into simple array of IDs.
216 $selected_network_ids = dfrapi_get_selected_network_ids();
217
218 // Get all Partnerize Network IDs from the user's selected Network IDs.
219 $selected_partnerize_ids = array_intersect( $partnerize_network_ids, $selected_network_ids );
220
221 // If there are no selected Partnerize IDs, return.
222 if ( empty( $selected_partnerize_ids ) ) {
223 return;
224 }
225
226 $results = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%_transient_camref_%' " );
227
228 // No results so nothing to worry about. Return false.
229 if ( empty( $results ) ) {
230 return;
231 }
232
233 $unapproved_merchant_ids = [];
234
235 foreach ( $results as $row ) {
236
237 if ( 'dfrapi_unapproved_ph_merchant' !== $row->option_value ) {
238 continue;
239 }
240
241 $option_name = $row->option_name; // Example: _transient_camref_46627
242
243 $unapproved_merchant_ids[] = absint( dfrapi_str_after_last( $option_name, '_' ) );
244 }
245
246 $unapproved_merchant_ids = array_filter( array_unique( $unapproved_merchant_ids ) );
247
248 if ( empty( $unapproved_merchant_ids ) ) {
249 return;
250 }
251
252 $merchants = dfrapi_api_get_merchants_by_id( $unapproved_merchant_ids );
253
254 if ( empty( $merchants ) ) {
255 return;
256 }
257
258 $list = '';
259 foreach ( $merchants as $merchant ) {
260 $list .= sprintf(
261 '<br />- %1$s: <strong>%2$s</strong> <small>(%3$d)</small>',
262 esc_html( $merchant['source'] ),
263 esc_html( $merchant['name'] ),
264 absint( $merchant['_id'] )
265 );
266 }
267
268 $status = 'error';
269 $plugin = 'Datafeedr API';
270 $heading = __( 'Unapproved Partnerize Merchants Selected', 'datafeedr-api' );
271 $message = sprintf(
272 __( 'You have selected one or more Partnerize merchants who have not approved your publisher account:<br />%1$s<br /><br />Please go to <a href="%2$s">Datafeedr API > Merchants</a> and remove these merchants from your selected list of Merchants. Then go here <a href="%3$s">Datafeedr API > Tools</a> and click the <strong>[Delete Cached API Data]</strong> button.', 'datafeedr-api' ),
273 $list,
274 esc_url( dfrapi_merchants_page_url() ),
275 esc_url( dfrapi_tools_page_url() )
276 );
277
278 dfrapi_admin_notice( $message, $status, $heading, $plugin );
279 }
280
281 add_action( 'admin_notices', 'dfrapi_unapproved_partnerize_merchants_selected' );
282
283 /**
284 * Display Admin Notice if user has selected a Effiliation merchant which they are not approved by.
285 *
286 * @return void
287 */
288 function dfrapi_unapproved_effiliation_merchants_selected() {
289
290 if ( ! current_user_can( 'manage_options' ) ) {
291 return;
292 }
293
294 global $wpdb;
295
296 // Get range of Effiliation Network IDs
297 $effiliation_network_ids = dfrapi_get_effiliation_network_ids();
298
299 // Get user's currently selected networks and convert into simple array of IDs.
300 $selected_network_ids = dfrapi_get_selected_network_ids();
301
302 // Get all Effiliation Network IDs from the user's selected Network IDs.
303 $selected_effiliation_ids = array_intersect( $effiliation_network_ids, $selected_network_ids );
304
305 // If there are no selected Effiliation IDs, return.
306 if ( empty( $selected_effiliation_ids ) ) {
307 return;
308 }
309
310 $results = $wpdb->get_results( "SELECT option_name, option_value FROM $wpdb->options WHERE option_name LIKE '%_transient_effiliation_%' AND option_name != '_transient_effiliation_affiliate_ids' " );
311
312 // No results so nothing to worry about. Return false.
313 if ( empty( $results ) ) {
314 return;
315 }
316
317 $unapproved_merchant_ids = [];
318
319 foreach ( $results as $row ) {
320
321 if ( 'dfrapi_unapproved_effiliation_merchant' !== $row->option_value ) {
322 continue;
323 }
324
325 $option_name = $row->option_name; // Example: _transient_effiliation_46627
326
327 $unapproved_merchant_ids[] = absint( dfrapi_str_after_last( $option_name, '_' ) );
328 }
329
330 $unapproved_merchant_ids = array_filter( array_unique( $unapproved_merchant_ids ) );
331
332 if ( empty( $unapproved_merchant_ids ) ) {
333 return;
334 }
335 $merchants = dfrapi_api_get_merchants_by_id( $unapproved_merchant_ids );
336
337 if ( empty( $merchants ) ) {
338 return;
339 }
340
341 $list = '';
342 foreach ( $merchants as $merchant ) {
343 $list .= sprintf(
344 '<br />- %1$s: <strong>%2$s</strong> <small>(%3$d)</small>',
345 esc_html( $merchant['source'] ),
346 esc_html( $merchant['name'] ),
347 absint( $merchant['_id'] )
348 );
349 }
350
351 $status = 'error';
352 $plugin = 'Datafeedr API';
353 $heading = __( 'Unapproved Effiliation Merchants Selected', 'datafeedr-api' );
354 $message = sprintf(
355 __( 'You have selected one or more Effiliation merchants who have not approved your publisher account:<br />%1$s<br /><br />Please go to <a href="%2$s">Datafeedr API > Merchants</a> and remove these merchants from your selected list of Merchants. Then go here <a href="%3$s">Datafeedr API > Tools</a> and click the <strong>[Delete Cached API Data]</strong> button.', 'datafeedr-api' ),
356 $list,
357 esc_url( dfrapi_merchants_page_url() ),
358 esc_url( dfrapi_tools_page_url() )
359 );
360
361 dfrapi_admin_notice( $message, $status, $heading, $plugin );
362 }
363
364 add_action( 'admin_notices', 'dfrapi_unapproved_effiliation_merchants_selected' );
365
366