PluginProbe
Datafeedr API / 1.0.14
Datafeedr API v1.0.14
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.14, at classes/class-dfrapi-env.php

105 lines 2.4 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
37 static function api_keys_exist() {
38
39 $configuration = (array) get_option( 'dfrapi_configuration' );
40 $access_id = false;
41 $secret_key = false;
42
43 if ( isset( $configuration['access_id'] ) && ( $configuration['access_id'] != '' ) ) {
44 $access_id = $configuration['access_id'];
45 }
46
47 if ( isset( $configuration['secret_key'] ) && ( $configuration['secret_key'] != '' ) ) {
48 $secret_key = $configuration['secret_key'];
49 }
50
51 if ( $access_id && $secret_key ) {
52 return true;
53 }
54
55 return false;
56 }
57
58 static function network_is_selected() {
59 $networks = (array) get_option( 'dfrapi_networks' );
60 if ( !empty( $networks['ids'] ) ) {
61 return true;
62 }
63 return false;
64 }
65
66 static function merchant_is_selected() {
67 $merchants = (array) get_option( 'dfrapi_merchants' );
68 if ( !empty( $merchants['ids'] ) ) {
69 return true;
70 }
71 return false;
72 }
73
74 static function usage_over_90_percent() {
75 $percentage = dfrapi_get_api_usage_percentage();
76 if ( $percentage >= 90 ) {
77 return true;
78 }
79 return false;
80 }
81
82 static function missing_affiliate_ids() {
83 $networks = get_option( 'dfrapi_networks', array() );
84 if ( !empty( $networks ) ) {
85 foreach ( $networks['ids'] as $network ) {
86 if ( empty( $network['aid'] ) ) {
87 return true;
88 }
89 }
90 }
91 return false;
92 }
93
94 static function check_gmt_time() {
95 $gmt_time = gmdate( 'Gis' );
96 if ( $gmt_time > 80000 && $gmt_time < 82000 ) {
97 return true;
98 }
99 return false;
100 }
101
102 } // class Dfrapi_Env
103
104 } // class_exists check
105