key = 'dfrapi_account';
add_action( 'admin_init', array( &$this, 'register_settings' ) );
add_action( 'admin_menu', array( $this, 'admin_menu' ) );
add_action( 'init', array( &$this, 'load_settings' ) );
}
function load_settings() {
$this->options = (array) get_option( $this->key );
if ( isset( $this->options[0] ) && empty( $this->options[0] ) ) {
$this->options = $status = dfrapi_api_get_status();
if ( !array_key_exists( 'dfrapi_api_error', $status ) ) {
update_option( $this->key, $status );
}
}
}
function admin_menu() {
add_submenu_page(
'dfrapi',
__( 'Account — Datafeedr API', DFRAPI_DOMAIN ),
__( 'Account', DFRAPI_DOMAIN ),
'manage_options',
$this->key,
array( $this, 'output' )
);
}
function output() {
echo '
';
echo '
' . dfrapi_setting_pages( $this->page ) . ' — Datafeedr API
';
settings_fields( $this->page );
do_settings_sections( $this->page);
echo '';
}
function register_settings() {
register_setting( $this->page, $this->key, array( $this, 'validate' ) );
// Current Plan
add_settings_section( 'current_plan', __( 'Current Plan', DFRAPI_DOMAIN ), array( &$this, 'section_current_plan_desc' ), $this->page );
// Only show the following if there is no Error.
if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
// Current Usage
add_settings_section( 'current_usage', __( 'Current Usage', DFRAPI_DOMAIN ), array( &$this, 'section_current_usage_desc' ), $this->page );
}
// Account Links
add_settings_section( 'account', __( 'Account Links', DFRAPI_DOMAIN ), array( &$this, 'section_account_desc' ), $this->page );
}
function section_current_plan_desc() {
$plans = dfrapi_get_membership_plans();
$plan_name = '';
if ( $this->options['plan_id'] > 0 ) {
$plan_name .= $plans[$this->options['plan_id']];
if ( $this->options['plan_id'] != 10250000 ) {
$plan_name .= ' (';
$plan_name .= '' . __( 'Upgrade', DFRAPI_DOMAIN ) . '';
$plan_name .= ')';
}
} else {
$plan_name .= '';
$plan_name .= __( 'None', DFRAPI_DOMAIN );
$plan_name .= ' (';
$plan_name .= '' . __( 'Reactivate your subscription', DFRAPI_DOMAIN ) . '';
$plan_name .= ')';
}
echo '
| ' . __( 'Plan name', DFRAPI_DOMAIN ) . ' |
' . $plan_name . ' |
';
if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) {
echo '
| ' . __( 'Requests per month (RPM)', DFRAPI_DOMAIN ) . ' |
' . number_format( $this->options['max_requests'] ) . ' |
| ' . __( 'Products per request (PPR)', DFRAPI_DOMAIN ) . ' |
' . number_format( $this->options['max_length'] ) . ' |
';
}
echo '
';
}
function section_current_usage_desc() {
// Percent of API Requests Used
$percent_api_requests_users = '';
if ( $this->options['max_requests'] > 0 ) {
$percent_api_requests_users .= floor ( ( intval( $this->options['request_count'] ) / intval( $this->options['max_requests'] ) * 100 ) );
} else {
$percent_api_requests_users .= 0;
}
$percent_api_requests_users .= '%';
// Your API requests will reset on
$reset_date = '';
$today = date('j');
$num_days = date('t');
if ( $this->options['bill_day'] > $num_days ) {
$bill_day = $num_days;
} else {
$bill_day = $this->options['bill_day'];
}
if ( $bill_day == 0 ) {
$reset_date .= '' . __( 'Never', DFRAPI_DOMAIN ) . '';
} elseif ( $today >= $bill_day ) {
$reset_date .= date('F', strtotime('+1 month')) . ' ' . $bill_day . ', ' . date('Y', strtotime('+1 month'));
} else {
$reset_date .= date('F') . ' ' . $bill_day . ', ' . date('Y');
}
echo '
| ' . __( 'API requests used this period', DFRAPI_DOMAIN ) . ' |
' . number_format( $this->options['request_count'] ) . ' |
| ' . __( 'API requests remaining this period', DFRAPI_DOMAIN ) . ' |
' . number_format( $this->options['max_requests'] - $this->options['request_count'] ) . ' |
| ' . __( 'Percent of API requests used this period', DFRAPI_DOMAIN ) . ' |
' . $percent_api_requests_users . ' |
| ' . __( 'Your API requests will reset on', DFRAPI_DOMAIN ) . ' |
' . $reset_date . ' |
';
}
function section_account_desc() {
echo '' . __( 'View your Datafeedr account', DFRAPI_DOMAIN ) . '
';
echo '' . __( 'Upgrade your plan', DFRAPI_DOMAIN ) . '
';
}
function validate( $input ) {
return $input;
}
} // class Dfrapi_Account
} // class_exists check