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