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