PluginProbe
Datafeedr API / 1.0.17
Datafeedr API v1.0.17
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 / classes / class-dfrapi-env.php

class-dfrapi-env.php in Datafeedr API 1.0.17, at classes/class-dfrapi-env.php

118 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
4
5 if ( ! class_exists( 'Dfrapi_Env' ) ) {
6
7 /**
8 * Check environment and print errors..
9 */
10 class Dfrapi_Env {
11
12 function __construct() {
13
14 // Cascading Errors
15 if ( !self::api_keys_exist() ) {
16 dfrapi_admin_messages( 'missing_api_keys' );
17 } elseif ( !self::network_is_selected() ) {
18 dfrapi_admin_messages( 'missing_network_ids' );
19 } elseif ( !self::merchant_is_selected() ) {
20 dfrapi_admin_messages( 'missing_merchant_ids' );
21 }
22
23 // Non-cascading Errors
24 if ( self::usage_over_90_percent() ) {
25 dfrapi_admin_messages( 'usage_over_90_percent' );
26 }
27
28 if ( self::missing_affiliate_ids() ) {
29 dfrapi_admin_messages( 'missing_affiliate_ids' );
30 }
31
32 if ( self::check_gmt_time() ) {
33 dfrapi_admin_messages( 'database_rotation' );
34 }
35
36 if ( self::unapproved_zanox_merchants_exist() ) {
37 dfrapi_admin_messages( 'unapproved_zanox_merchants' );
38 }
39 }
40
41 static function api_keys_exist() {
42
43 $configuration = (array) get_option( 'dfrapi_configuration' );
44 $access_id = false;
45 $secret_key = false;
46
47 if ( isset( $configuration['access_id'] ) && ( $configuration['access_id'] != '' ) ) {
48 $access_id = $configuration['access_id'];
49 }
50
51 if ( isset( $configuration['secret_key'] ) && ( $configuration['secret_key'] != '' ) ) {
52 $secret_key = $configuration['secret_key'];
53 }
54
55 if ( $access_id && $secret_key ) {
56 return true;
57 }
58
59 return false;
60 }
61
62 static function network_is_selected() {
63 $networks = (array) get_option( 'dfrapi_networks' );
64 if ( !empty( $networks['ids'] ) ) {
65 return true;
66 }
67 return false;
68 }
69
70 static function merchant_is_selected() {
71 $merchants = (array) get_option( 'dfrapi_merchants' );
72 if ( !empty( $merchants['ids'] ) ) {
73 return true;
74 }
75 return false;
76 }
77
78 static function usage_over_90_percent() {
79 $percentage = dfrapi_get_api_usage_percentage();
80 if ( $percentage >= 90 ) {
81 return true;
82 }
83 return false;
84 }
85
86 static function missing_affiliate_ids() {
87 $networks = get_option( 'dfrapi_networks', array() );
88 if ( !empty( $networks ) ) {
89 foreach ( $networks['ids'] as $network ) {
90 if ( empty( $network['aid'] ) ) {
91 return true;
92 }
93 }
94 }
95 return false;
96 }
97
98 static function check_gmt_time() {
99 $gmt_time = gmdate( 'Gis' );
100 if ( $gmt_time > 80000 && $gmt_time < 82000 ) {
101 return true;
102 }
103 return false;
104 }
105
106 static function unapproved_zanox_merchants_exist() {
107 global $wpdb;
108 $results = $wpdb->get_results( "SELECT option_name FROM $wpdb->options WHERE option_value = 'dfrapi_unapproved_zanox_merchant' ", OBJECT );
109 if ( !empty( $results ) ) {
110 return TRUE;
111 }
112 return FALSE;
113 }
114
115 } // class Dfrapi_Env
116
117 } // class_exists check
118