| @@ -11,16 +11,18 @@ | ||
| 11 | 11 | |
| 12 | 12 | private $page = 'dfrapi-account'; |
| 13 | 13 | private $key; |
| 14 | 14 | |
| 15 | + public $options; | |
| 16 | + | |
| 15 | 17 | public function __construct() { |
| 16 | 18 | $this->key = 'dfrapi_account'; |
| 17 | - add_action( 'admin_init', array( &$this, 'register_settings' ) ); | |
| 18 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); | |
| 19 | - add_action( 'init', array( &$this, 'load_settings' ) ); | |
| 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' ) ); | |
| 20 | 22 | } |
| 21 | - | |
| 22 | - function load_settings() { | |
| 23 | + | |
| 24 | + function load_settings() { | |
| 23 | 25 | $this->options = (array) get_option( $this->key ); |
| 24 | 26 | if ( isset( $this->options[0] ) && empty( $this->options[0] ) ) { |
| 25 | 27 | $this->options = $status = dfrapi_api_get_status(); |
| 26 | 28 | if ( !array_key_exists( 'dfrapi_api_error', $status ) ) { |
| @@ -27,17 +29,17 @@ | ||
| 27 | 29 | update_option( $this->key, $status ); |
| 28 | 30 | } |
| 29 | 31 | } |
| 30 | 32 | } |
| 31 | - | |
| 33 | + | |
| 32 | 34 | function admin_menu() { |
| 33 | 35 | add_submenu_page( |
| 34 | 36 | 'dfrapi', |
| 35 | - __( 'Account — Datafeedr API', DFRAPI_DOMAIN ), | |
| 36 | - __( 'Account', DFRAPI_DOMAIN ), | |
| 37 | - 'manage_options', | |
| 37 | + __( 'Account — Datafeedr API', 'datafeedr-api' ), | |
| 38 | + __( 'Account', 'datafeedr-api' ), | |
| 39 | + 'manage_options', | |
| 38 | 40 | $this->key, |
| 39 | - array( $this, 'output' ) | |
| 41 | + array( $this, 'output' ) | |
| 40 | 42 | ); |
| 41 | 43 | } |
| 42 | 44 | |
| 43 | 45 | function output() { |
| @@ -48,27 +50,27 @@ | ||
| 48 | 50 | echo '</div>'; |
| 49 | 51 | } |
| 50 | 52 | |
| 51 | 53 | function register_settings() { |
| 52 | - | |
| 54 | + | |
| 53 | 55 | register_setting( $this->page, $this->key, array( $this, 'validate' ) ); |
| 54 | - | |
| 56 | + | |
| 55 | 57 | // Current Plan |
| 56 | - add_settings_section( 'current_plan', __( 'Current Plan', DFRAPI_DOMAIN ), array( &$this, 'section_current_plan_desc' ), $this->page ); | |
| 57 | - | |
| 58 | + add_settings_section( 'current_plan', __( 'Current Plan', 'datafeedr-api' ), array( &$this, 'section_current_plan_desc' ), $this->page ); | |
| 59 | + | |
| 58 | 60 | // Only show the following if there is no Error. |
| 59 | 61 | if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) { |
| 60 | - | |
| 62 | + | |
| 61 | 63 | // Current Usage |
| 62 | - add_settings_section( 'current_usage', __( 'Current Usage', DFRAPI_DOMAIN ), array( &$this, 'section_current_usage_desc' ), $this->page ); | |
| 64 | + add_settings_section( 'current_usage', __( 'Current Usage', 'datafeedr-api' ), array( &$this, 'section_current_usage_desc' ), $this->page ); | |
| 63 | 65 | } |
| 64 | - | |
| 66 | + | |
| 65 | 67 | // Account Links |
| 66 | - add_settings_section( 'account', __( 'Account Links', DFRAPI_DOMAIN ), array( &$this, 'section_account_desc' ), $this->page ); | |
| 68 | + add_settings_section( 'account', __( 'Account Links', 'datafeedr-api' ), array( &$this, 'section_account_desc' ), $this->page ); | |
| 67 | 69 | } |
| 68 | - | |
| 70 | + | |
| 69 | 71 | function section_current_plan_desc() { |
| 70 | - | |
| 72 | + | |
| 71 | 73 | $plans = dfrapi_get_membership_plans(); |
| 72 | 74 | $plan_name = ''; |
| 73 | 75 | if ( $this->options['plan_id'] > 0 ) { |
| 74 | 76 | $plan_name .= $plans[$this->options['plan_id']]; |
| @@ -73,107 +75,62 @@ | ||
| 73 | 75 | if ( $this->options['plan_id'] > 0 ) { |
| 74 | 76 | $plan_name .= $plans[$this->options['plan_id']]; |
| 75 | 77 | if ( $this->options['plan_id'] != 10250000 ) { |
| 76 | 78 | $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>'; | |
| 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>'; | |
| 78 | 80 | $plan_name .= ')'; |
| 79 | 81 | } |
| 80 | 82 | } else { |
| 81 | 83 | $plan_name .= '<em>'; |
| 82 | - $plan_name .= __( 'None', DFRAPI_DOMAIN ); | |
| 84 | + $plan_name .= __( 'None', 'datafeedr-api' ); | |
| 83 | 85 | $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>'; | |
| 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>'; | |
| 85 | 87 | $plan_name .= ')'; |
| 86 | 88 | } |
| 87 | - | |
| 89 | + | |
| 88 | 90 | echo ' |
| 89 | 91 | <table class="widefat account_table" cellspacing="0"> |
| 90 | 92 | <tbody> |
| 91 | 93 | <tr class="alternate"> |
| 92 | - <td class="row-title">' . __( 'Plan name', DFRAPI_DOMAIN ) . '</td> | |
| 94 | + <td class="row-title">' . __( 'Plan name', 'datafeedr-api' ) . '</td> | |
| 93 | 95 | <td class="desc">' . $plan_name . '</td> |
| 94 | 96 | </tr> |
| 95 | 97 | '; |
| 96 | - | |
| 98 | + | |
| 97 | 99 | if ( !array_key_exists( 'dfrapi_api_error', $this->options ) ) { |
| 98 | 100 | echo ' |
| 99 | 101 | <tr> |
| 100 | - <td class="row-title">' . __( 'Requests per month (RPM)', DFRAPI_DOMAIN ) . '</td> | |
| 102 | + <td class="row-title">' . __( 'Requests per month (RPM)', 'datafeedr-api' ) . '</td> | |
| 101 | 103 | <td class="desc">' . number_format( $this->options['max_requests'] ) . '</td> |
| 102 | 104 | </tr> |
| 103 | 105 | <tr class="alternate"> |
| 104 | - <td class="row-title">' . __( 'Products per request (PPR)', DFRAPI_DOMAIN ) . '</td> | |
| 106 | + <td class="row-title">' . __( 'Products per request (PPR)', 'datafeedr-api' ) . '</td> | |
| 105 | 107 | <td class="desc">' . number_format( $this->options['max_length'] ) . '</td> |
| 106 | 108 | </tr> |
| 107 | 109 | '; |
| 108 | 110 | } |
| 109 | - | |
| 111 | + | |
| 110 | 112 | echo ' |
| 111 | 113 | </tbody> |
| 112 | 114 | </table> |
| 113 | 115 | '; |
| 114 | 116 | } |
| 115 | - | |
| 117 | + | |
| 116 | 118 | function section_current_usage_desc() { |
| 117 | - | |
| 118 | - // Percent of API Requests Used | |
| 119 | - $percent_api_requests_users = ''; | |
| 120 | - if ( $this->options['max_requests'] > 0 ) { | |
| 121 | - $percent_api_requests_users .= floor ( ( intval( $this->options['request_count'] ) / intval( $this->options['max_requests'] ) * 100 ) ); | |
| 122 | - } else { | |
| 123 | - $percent_api_requests_users .= 0; | |
| 124 | - } | |
| 125 | - $percent_api_requests_users .= '%'; | |
| 126 | - | |
| 127 | - // Your API requests will reset on | |
| 128 | - $reset_date = ''; | |
| 129 | - $today = date('j'); | |
| 130 | - $num_days = date('t'); | |
| 131 | - if ( $this->options['bill_day'] > $num_days ) { | |
| 132 | - $bill_day = $num_days; | |
| 133 | - } else { | |
| 134 | - $bill_day = $this->options['bill_day']; | |
| 135 | - } | |
| 136 | - if ( $bill_day == 0 ) { | |
| 137 | - $reset_date .= '<em>' . __( 'Never', DFRAPI_DOMAIN ) . '</em>'; | |
| 138 | - } elseif ( $today >= $bill_day ) { | |
| 139 | - $reset_date .= date('F', strtotime('+1 month')) . ' ' . $bill_day . ', ' . date('Y', strtotime('+1 month')); | |
| 140 | - } else { | |
| 141 | - $reset_date .= date('F') . ' ' . $bill_day . ', ' . date('Y'); | |
| 142 | - } | |
| 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 | + } | |
| 143 | 124 | |
| 144 | - echo ' | |
| 145 | - <table class="widefat account_table" cellspacing="0"> | |
| 146 | - <tbody> | |
| 147 | - <tr class="alternate"> | |
| 148 | - <td class="row-title">' . __( 'API requests used this period', DFRAPI_DOMAIN ) . '</td> | |
| 149 | - <td class="desc">' . number_format( $this->options['request_count'] ) . '</td> | |
| 150 | - </tr> | |
| 151 | - <tr> | |
| 152 | - <td class="row-title">' . __( 'API requests remaining this period', DFRAPI_DOMAIN ) . '</td> | |
| 153 | - <td class="desc">' . number_format( $this->options['max_requests'] - $this->options['request_count'] ) . '</td> | |
| 154 | - </tr> | |
| 155 | - <tr class="alternate"> | |
| 156 | - <td class="row-title">' . __( 'Percent of API requests used this period', DFRAPI_DOMAIN ) . '</td> | |
| 157 | - <td class="desc">' . $percent_api_requests_users . '</td> | |
| 158 | - </tr> | |
| 159 | - <tr> | |
| 160 | - <td class="row-title">' . __( 'Your API requests will reset on', DFRAPI_DOMAIN ) . '</td> | |
| 161 | - <td class="desc">' . $reset_date . '</td> | |
| 162 | - </tr> | |
| 163 | - </tbody> | |
| 164 | - </table> | |
| 165 | - '; | |
| 166 | - } | |
| 167 | - | |
| 168 | 125 | function section_account_desc() { |
| 169 | - 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>'; | |
| 170 | - 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 | + 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>'; | |
| 171 | 128 | } |
| 172 | - | |
| 129 | + | |
| 173 | 130 | function validate( $input ) { |
| 174 | 131 | return $input; |
| 175 | 132 | } |
| 176 | - | |
| 133 | + | |
| 177 | 134 | } // class Dfrapi_Account |
| 178 | 135 | |
| 179 | 136 | } // class_exists check |