PluginProbe
Datafeedr API / 1.0.125
Datafeedr API v1.0.125
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-account.php

class-dfrapi-account.php in Datafeedr API 1.0.125, at classes/class-dfrapi-account.php

135 lines 4.6 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_Account' ) ) {
6
7 /**
8 * Configuration page.
9 */
10 class Dfrapi_Account {
11
12 private $page = 'dfrapi-account';
13 private $key;
14
15 public function __construct() {
16 $this->key = 'dfrapi_account';
17 add_action( 'admin_init', array( $this, 'register_settings' ) );
18 add_action( 'admin_menu', array( $this, 'admin_menu' ), 70 );
19 add_action( 'init', array( $this, 'load_settings' ) );
20 }
21
22 function load_settings() {
23 $this->options = (array) get_option( $this->key );
24 if ( isset( $this->options[0] ) && empty( $this->options[0] ) ) {
25 $this->options = $status = dfrapi_api_get_status();
26 if ( !array_key_exists( 'dfrapi_api_error', $status ) ) {
27 update_option( $this->key, $status );
28 }
29 }
30 }
31
32 function admin_menu() {
33 add_submenu_page(
34 'dfrapi',
35 __( 'Account &#8212; Datafeedr API', DFRAPI_DOMAIN ),
36 __( 'Account', DFRAPI_DOMAIN ),
37 'manage_options',
38 $this->key,
39 array( $this, 'output' )
40 );
41 }
42
43 function output() {
44 echo '<div class="wrap" id="' . $this->key . '">';
45 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
46 settings_fields( $this->page );
47 do_settings_sections( $this->page);
48 echo '</div>';
49 }
50
51 function register_settings() {
52
53 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
54
55 // Current Plan
56 add_settings_section( 'current_plan', __( 'Current Plan', DFRAPI_DOMAIN ), array( &$this, 'section_current_plan_desc' ), $this->page );
57
58 // Only show the following if there is no Error.
59 if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
60
61 // Current Usage
62 add_settings_section( 'current_usage', __( 'Current Usage', DFRAPI_DOMAIN ), array( &$this, 'section_current_usage_desc' ), $this->page );
63 }
64
65 // Account Links
66 add_settings_section( 'account', __( 'Account Links', DFRAPI_DOMAIN ), array( &$this, 'section_account_desc' ), $this->page );
67 }
68
69 function section_current_plan_desc() {
70
71 $plans = dfrapi_get_membership_plans();
72 $plan_name = '';
73 if ( $this->options['plan_id'] > 0 ) {
74 $plan_name .= $plans[$this->options['plan_id']];
75 if ( $this->options['plan_id'] != 10250000 ) {
76 $plan_name .= ' (';
77 $plan_name .= '<a href="' . dfrapi_user_pages( 'change' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank" class="dfrapi_plan_link">' . __( 'Upgrade', DFRAPI_DOMAIN ) . '</a>';
78 $plan_name .= ')';
79 }
80 } else {
81 $plan_name .= '<em>';
82 $plan_name .= __( 'None', DFRAPI_DOMAIN );
83 $plan_name .= '</em> (';
84 $plan_name .= '<a href="' . dfrapi_user_pages( 'signup' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank" class="dfrapi_plan_link">' . __( 'Reactivate your subscription', DFRAPI_DOMAIN ) . '</a>';
85 $plan_name .= ')';
86 }
87
88 echo '
89 <table class="widefat account_table" cellspacing="0">
90 <tbody>
91 <tr class="alternate">
92 <td class="row-title">' . __( 'Plan name', DFRAPI_DOMAIN ) . '</td>
93 <td class="desc">' . $plan_name . '</td>
94 </tr>
95 ';
96
97 if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
98 echo '
99 <tr>
100 <td class="row-title">' . __( 'Requests per month (RPM)', DFRAPI_DOMAIN ) . '</td>
101 <td class="desc">' . number_format( $this->options['max_requests'] ) . '</td>
102 </tr>
103 <tr class="alternate">
104 <td class="row-title">' . __( 'Products per request (PPR)', DFRAPI_DOMAIN ) . '</td>
105 <td class="desc">' . number_format( $this->options['max_length'] ) . '</td>
106 </tr>
107 ';
108 }
109
110 echo '
111 </tbody>
112 </table>
113 ';
114 }
115
116 function section_current_usage_desc() {
117 echo '<p>';
118 _e( 'View your current API usage, number of API requests remaining and reset date', DFRAPI_DOMAIN );
119 echo ' <a href="' . dfrapi_user_pages( 'api' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage#api-usage" target="_blank">' . __( 'here', DFRAPI_DOMAIN ) . '</a>.';
120 echo '<p>';
121 }
122
123 function section_account_desc() {
124 echo '<p><a href="' . dfrapi_user_pages( 'summary' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank">' . __( 'View your Datafeedr account', DFRAPI_DOMAIN ) . '</a></p>';
125 echo '<p><a href="' . dfrapi_user_pages( 'change' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=dfrapiaccountpage" target="_blank">' . __( 'Upgrade your plan', DFRAPI_DOMAIN ) . '</a></p>';
126 }
127
128 function validate( $input ) {
129 return $input;
130 }
131
132 } // class Dfrapi_Account
133
134 } // class_exists check
135