| @@ -45,14 +45,8 @@ | ||
| 45 | 45 | */ |
| 46 | 46 | public $options_pages = array(); |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * Is pro plugin installed | |
| 50 | - * @var array | |
| 51 | - */ | |
| 52 | - public $pro_plugin = false; | |
| 53 | - | |
| 54 | - /** | |
| 55 | 49 | * Holds an instance of the object |
| 56 | 50 | * |
| 57 | 51 | * @var Myprefix_Admin |
| 58 | 52 | **/ |
| @@ -65,9 +59,8 @@ | ||
| 65 | 59 | private function __construct() { |
| 66 | 60 | // Set our title |
| 67 | 61 | $this->menu_title = __( 'WPGetAPI', 'wpgetapi' ); |
| 68 | 62 | $this->title = __( 'WPGetAPI', 'wpgetapi' ); |
| 69 | - | |
| 70 | 63 | } |
| 71 | 64 | |
| 72 | 65 | /** |
| 73 | 66 | * Returns the running object |
| @@ -89,23 +82,11 @@ | ||
| 89 | 82 | public function hooks() { |
| 90 | 83 | add_action( 'admin_init', array( $this, 'init' ) ); |
| 91 | 84 | add_action( 'admin_menu', array( $this, 'add_options_pages' ) ); |
| 92 | 85 | |
| 93 | - add_action( 'cmb2_admin_init', array( $this, 'init_custom_fields' ) ); | |
| 94 | - | |
| 95 | - add_action( "cmb2_save_options-page_fields", array( $this, 'redirect' ), 1, 2 ); | |
| 96 | - | |
| 97 | - add_action( 'admin_footer', array( $this, 'load_testing_javascript' ) ); | |
| 98 | - | |
| 99 | - add_action( 'wp_ajax_wpgetapi_test_endpoint', array( $this, 'test_the_endpoint' ) ); | |
| 100 | - | |
| 86 | + add_action( 'cmb2_init', array( $this, 'init_custom_fields' ) ); | |
| 101 | 87 | } |
| 102 | 88 | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * Setup our custom fields | |
| 106 | - * @since 0.1.0 | |
| 107 | - */ | |
| 108 | 89 | public function init_custom_fields() { |
| 109 | 90 | require_once WPGETAPIDIR . 'includes/class-fields.php'; |
| 110 | 91 | WpGetApi_Parameter_Field::init_parameter(); |
| 111 | 92 | } |
| @@ -114,9 +95,8 @@ | ||
| 114 | 95 | * Register our setting to WP |
| 115 | 96 | * @since 0.1.0 |
| 116 | 97 | */ |
| 117 | 98 | public function init() { |
| 118 | - $this->pro_plugin = is_plugin_active( 'wpgetapi-extras/wpgetapi-extras.php' ) ? true : false; | |
| 119 | 99 | $option_tabs = self::option_fields(); |
| 120 | 100 | foreach ($option_tabs as $index => $option_tab) { |
| 121 | 101 | register_setting( $option_tab['id'], $option_tab['id'] ); |
| 122 | 102 | } |
| @@ -127,12 +107,16 @@ | ||
| 127 | 107 | * Get our saved API's from setup |
| 128 | 108 | * @since 0.1.0 |
| 129 | 109 | */ |
| 130 | 110 | public function get_apis() { |
| 111 | + | |
| 131 | 112 | $setup = get_option( 'wpgetapi_setup' ); |
| 113 | + | |
| 132 | 114 | if( empty( $setup ) || ! isset( $setup['apis'] ) || empty( $setup['apis'] ) ) |
| 133 | 115 | return; |
| 116 | + | |
| 134 | 117 | return $setup['apis']; |
| 118 | + | |
| 135 | 119 | } |
| 136 | 120 | |
| 137 | 121 | |
| 138 | 122 | /** |
| @@ -145,15 +129,15 @@ | ||
| 145 | 129 | if ( ! empty( $this->option_metabox ) ) { |
| 146 | 130 | return $this->option_metabox; |
| 147 | 131 | } |
| 148 | 132 | |
| 149 | - // setup tab | |
| 133 | + // sale tab | |
| 150 | 134 | $option_metabox[] = array( |
| 151 | 135 | 'title' => __( 'Setup', 'wpgetapi' ), |
| 152 | 136 | 'menu_title' => __( 'Setup', 'wpgetapi' ), |
| 153 | 137 | 'id' => 'wpgetapi_setup', |
| 154 | - 'desc' => __( 'Add the details of the API(s) you are using. Endpoints will be setup in the next step after hitting save.', 'wpgetapi' ), | |
| 155 | - 'show_on' => array( 'key' => 'options-page', 'value' => array( 'wpgetapi_setup' ), ), | |
| 138 | + 'desc' => __( 'Add the details of your API(s) below and hit the Save button.', 'wpgetapi' ), | |
| 139 | + 'show_on' => array( 'key' => 'options-page', 'value' => array( 'setup' ), ), | |
| 156 | 140 | 'show_names' => true, |
| 157 | 141 | 'fields' => $this->setup_fields(), |
| 158 | 142 | ); |
| 159 | 143 | |
| @@ -175,9 +159,9 @@ | ||
| 175 | 159 | 'id' => $metabox_id, |
| 176 | 160 | 'desc' => '', |
| 177 | 161 | 'show_on' => array( 'key' => 'options-page', 'value' => array( $metabox_id ), ), |
| 178 | 162 | 'show_names' => true, |
| 179 | - 'fields' => $this->endpoint_fields( $type, $api_id, $base_url ), | |
| 163 | + 'fields' => $this->api_fields( $type, $api_id, $base_url ), | |
| 180 | 164 | ); |
| 181 | 165 | |
| 182 | 166 | } |
| 183 | 167 | |
| @@ -182,14 +166,13 @@ | ||
| 182 | 166 | } |
| 183 | 167 | |
| 184 | 168 | } |
| 185 | 169 | |
| 186 | - $option_metabox = apply_filters( 'wpgetapi_admin_pages', $option_metabox ); | |
| 187 | - | |
| 188 | 170 | return $option_metabox; |
| 189 | 171 | |
| 190 | 172 | } |
| 191 | 173 | |
| 174 | + | |
| 192 | 175 | public function setup_fields() { |
| 193 | 176 | |
| 194 | 177 | $fields[] = array( |
| 195 | 178 | 'id' => 'apis', |
| @@ -197,43 +180,42 @@ | ||
| 197 | 180 | 'name' => '', |
| 198 | 181 | 'description' => '', |
| 199 | 182 | 'options' => array( |
| 200 | 183 | 'group_title' => __( 'API {#}', 'wpgetapi' ), |
| 201 | - 'add_button' => __( 'Add New API', 'wpgetapi' ), | |
| 184 | + 'add_button' => __( 'Add API', 'wpgetapi' ), | |
| 202 | 185 | 'remove_button' => __( 'Remove API', 'wpgetapi' ), |
| 203 | 186 | 'sortable' => true, // beta |
| 204 | 187 | ), |
| 205 | 188 | 'fields' => array( |
| 206 | 189 | array( |
| 207 | - 'name' => __( 'API Name', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The name of this API. Call it whatever you like.', 'wpgetapi' ) . '"></span>', | |
| 190 | + 'name' => __( 'API Name', 'wpgetapi' ), | |
| 208 | 191 | 'id' => 'name', |
| 209 | 192 | 'type' => 'text', |
| 210 | 193 | 'attributes' => array( |
| 211 | 194 | 'required' => true, |
| 212 | - 'placeholder' => 'Google Maps', | |
| 195 | + 'placeholder' => 'New API Name', | |
| 213 | 196 | ), |
| 214 | - 'desc' => '', | |
| 197 | + 'desc' => __( 'The name of the API you are connecting to.', 'wpgetapi' ), | |
| 215 | 198 | ), |
| 216 | 199 | array( |
| 217 | - 'name' => __( 'Unique ID', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Choose your own unique ID for this API. Use lowercase letters and underscores only!', 'wpgetapi' ) . '"></span>', | |
| 200 | + 'name' => __( 'API ID', 'wpgetapi' ), | |
| 218 | 201 | 'id' => 'id', |
| 219 | 202 | 'type' => 'text', |
| 220 | 203 | 'attributes' => array( |
| 221 | 204 | 'required' => true, |
| 222 | - 'placeholder' => 'google_maps', | |
| 205 | + 'placeholder' => 'new_api_name', | |
| 223 | 206 | ), |
| 224 | - 'desc' => '', | |
| 225 | - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id' | |
| 207 | + 'desc' => __( 'A unique ID for your API. Once this is set you should not change this value.', 'wpgetapi' ), | |
| 226 | 208 | ), |
| 227 | 209 | array( |
| 228 | - 'name' => __( 'Base URL', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The base URL of the API you are connecting to.', 'wpgetapi' ) . '"></span>', | |
| 210 | + 'name' => __( 'Base URL', 'wpgetapi' ), | |
| 229 | 211 | 'id' => 'base_url', |
| 230 | 212 | 'type' => 'text', |
| 231 | 213 | 'attributes' => array( |
| 232 | 214 | 'required' => true, |
| 233 | - 'placeholder' => 'https://maps.googleapis.com/maps/api', | |
| 215 | + 'placeholder' => 'https://newapiurl.com', | |
| 234 | 216 | ), |
| 235 | - 'desc' => '', | |
| 217 | + 'desc' => __( 'The base URL of the API you are connecting to.', 'wpgetapi' ), | |
| 236 | 218 | ), |
| 237 | 219 | |
| 238 | 220 | ) |
| 239 | 221 | ); |
| @@ -243,23 +225,40 @@ | ||
| 243 | 225 | } |
| 244 | 226 | |
| 245 | 227 | |
| 246 | 228 | /** |
| 247 | - * Endpoint settings. | |
| 229 | + * Site wide info on the current sale. | |
| 248 | 230 | * @return sale info array |
| 249 | 231 | * |
| 250 | 232 | */ |
| 251 | - public function endpoint_fields( $type = '', $api_id = '', $base_url = '' ) { | |
| 233 | + public function api_fields( $type = '', $api_id = '', $base_url = '' ) { | |
| 252 | 234 | |
| 253 | 235 | $fields = array(); |
| 254 | 236 | |
| 255 | - $cache_disabled = $this->pro_plugin ? '' : 'disabled'; | |
| 256 | - $cache_url = $this->pro_plugin ? '<a target="_blank" href="https://wpgetapi.com/docs/caching-api-calls/">Caching Help</a>' : '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=Cache">View PRO Plugin</a>'; | |
| 257 | - $cache_desc = $this->pro_plugin ? '' : 'Available in PRO plugin.'; | |
| 258 | - | |
| 237 | + $fields[] = array( | |
| 238 | + 'name' => __( 'Timeout', 'wpgetapi' ), | |
| 239 | + 'id' => 'timeout', | |
| 240 | + 'type' => 'text', | |
| 241 | + 'desc' => __( 'Timeout of the API call.', 'wpgetapi' ), | |
| 242 | + 'attributes' => array( | |
| 243 | + 'placeholder' => '10' | |
| 244 | + ), | |
| 245 | + 'before_row' => '<pre class="url"><span>Base URL: </span>' . $base_url . '</pre>', | |
| 246 | + ); | |
| 247 | + $fields[] = array( | |
| 248 | + 'name' => __( 'SSL Verify', 'wpgetapi' ), | |
| 249 | + 'id' => 'sslverify', | |
| 250 | + 'type' => 'select', | |
| 251 | + 'desc' => __( 'This should normally be set to true. If you are having issues, you can try false.', 'wpgetapi' ), | |
| 252 | + 'options' => array( | |
| 253 | + '1' => 'True', | |
| 254 | + '0' => 'False' | |
| 255 | + ), | |
| 256 | + ); | |
| 257 | + | |
| 259 | 258 | $endpoint_fields = apply_filters( 'wpgetapi_fields_endpoints', array( |
| 260 | 259 | array( |
| 261 | - 'name' => __( 'Unique ID', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Choose your own unique ID for this endpoint. Use lowercase letters and underscores only!', 'wpgetapi' ) . '"></span>', | |
| 260 | + 'name' => __( 'Unique ID', 'wpgetapi' ), | |
| 262 | 261 | 'id' => 'id', |
| 263 | 262 | 'type' => 'text', |
| 264 | 263 | 'classes' => 'field-id', |
| 265 | 264 | 'attributes' => array( |
| @@ -265,16 +264,18 @@ | ||
| 265 | 264 | 'attributes' => array( |
| 266 | 265 | 'required' => true, |
| 267 | 266 | 'placeholder' => 'new_endpoint', |
| 268 | 267 | ), |
| 269 | - 'desc' => '', | |
| 270 | - 'before_row' => "wpgetapi_output_top_of_endpoint", | |
| 271 | - 'api_id' => $api_id, | |
| 272 | - 'sanitization_cb' => 'wpgetapi_sanitize_unique_id' | |
| 273 | - | |
| 268 | + 'desc' => __( 'Choose a unique ID for this endpoint. Once this is set you should not change this value.', 'wpgetapi' ), | |
| 269 | + 'before_row' => " | |
| 270 | + <pre class='functions'> | |
| 271 | + Template Tag: </span><span>wpgetapi_endpoint( '" . $api_id . "', '<span class='endpoint_id'></span>', array('debug' => false) );</span><br> | |
| 272 | + Shortcode: <span>[wpgetapi_endpoint api_id='" . $api_id . "' endpoint_id='<span class='endpoint_id'></span>' debug='false']</span> | |
| 273 | + </pre> | |
| 274 | + ", | |
| 274 | 275 | ), |
| 275 | 276 | array( |
| 276 | - 'name' => __( 'Endpoint', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'This Endpoint will be appended to the Base URL to create the full URL that will be called.', 'wpgetapi' ) . '"></span>', | |
| 277 | + 'name' => __( 'Endpoint', 'wpgetapi' ), | |
| 277 | 278 | 'id' => 'endpoint', |
| 278 | 279 | 'type' => 'text', |
| 279 | 280 | 'classes' => 'field-endpoint', |
| 280 | 281 | 'attributes' => array( |
| @@ -280,12 +281,12 @@ | ||
| 280 | 281 | 'attributes' => array( |
| 281 | 282 | 'required' => true, |
| 282 | 283 | 'placeholder' => '/newendpoint', |
| 283 | 284 | ), |
| 284 | - 'desc' => '', | |
| 285 | + 'desc' => __( 'The endpoint that will be appended to the base URL to get the data. Include slash at beginning.', 'wpgetapi' ), | |
| 285 | 286 | ), |
| 286 | 287 | array( |
| 287 | - 'name' => __( 'Method', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'The Request Method for this endpoint. If you are displaying data from the API, it will usually be GET. If you are sending to the API, it will usually be POST.', 'wpgetapi' ) . '"></span>', | |
| 288 | + 'name' => __( 'Method', 'wpgetapi' ), | |
| 288 | 289 | 'id' => 'method', |
| 289 | 290 | 'type' => 'select', |
| 290 | 291 | 'classes' => 'field-method', |
| 291 | 292 | 'attributes' => array( |
| @@ -293,23 +294,13 @@ | ||
| 293 | 294 | ), |
| 294 | 295 | 'options' => array( |
| 295 | 296 | 'GET' => 'GET', |
| 296 | 297 | 'POST' => 'POST', |
| 297 | - 'PUT' => 'PUT', | |
| 298 | - 'PATCH' => 'PATCH', | |
| 299 | - 'DELETE' => 'DELETE', | |
| 300 | 298 | ), |
| 301 | - 'desc' => '', | |
| 299 | + 'desc' => __( 'The request method for this endpoint.', 'wpgetapi' ), | |
| 302 | 300 | ), |
| 303 | - | |
| 304 | 301 | array( |
| 305 | - 'name' => __( 'Results Format', 'wpgetapi' ) . | |
| 306 | - '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 307 | - sprintf( | |
| 308 | - __( 'The format that the API data will be returned in. To format the data as HTML, click the link below to learn how. %1s', 'wpgetapi' ), | |
| 309 | - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/formatting-json-data/?utm_campaign=Shortcode JSON&utm_medium=Admin&utm_source=User">Format as HTML</a>' ) | |
| 310 | - ) . | |
| 311 | - '"></span>', | |
| 302 | + 'name' => __( 'Results Format', 'wpgetapi' ), | |
| 312 | 303 | 'id' => 'results_format', |
| 313 | 304 | 'type' => 'select', |
| 314 | 305 | 'classes' => 'field-results-format', |
| 315 | 306 | 'attributes' => array( |
| @@ -315,120 +306,45 @@ | ||
| 315 | 306 | 'attributes' => array( |
| 316 | 307 | 'required' => true, |
| 317 | 308 | ), |
| 318 | 309 | 'options_cb' => 'wpgetapi_results_format_options', |
| 319 | - 'desc' => '' | |
| 310 | + 'desc' => __( 'The format of the results.', 'wpgetapi' ), | |
| 320 | 311 | ), |
| 321 | - | |
| 322 | 312 | array( |
| 323 | - 'name' => __( 'Cache Time', 'wpgetapi' ) . | |
| 324 | - '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 325 | - sprintf( | |
| 326 | - __( 'The time in seconds to cache this request for. %1s', 'wpgetapi' ), | |
| 327 | - htmlentities( '<br>' . $cache_url ) | |
| 328 | - ) . | |
| 329 | - '"></span>', | |
| 330 | - 'id' => 'cache_time', | |
| 331 | - 'type' => 'text', | |
| 332 | - 'classes' => 'field-cache-time', | |
| 333 | - 'attributes' => array( | |
| 334 | - 'placeholder' => '3600', | |
| 335 | - $cache_disabled => $cache_disabled, | |
| 336 | - ), | |
| 337 | - 'desc' => $cache_desc | |
| 338 | - ), | |
| 339 | - | |
| 340 | - array( | |
| 341 | - 'name' => __( 'Query String', 'wpgetapi' ) . | |
| 342 | - '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 343 | - sprintf( | |
| 344 | - __( 'Parameters as name/value pairs that will be appended to the URL. The query string is the part of the URL after the question mark, like so: https://yoururl.com<b>?key=value&key3=value3</b> %1s', 'wpgetapi' ), | |
| 345 | - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/adding-query-string-parameters/?utm_campaign=Query String&utm_medium=Admin&utm_source=User">More Info</a>' ) | |
| 346 | - ) . | |
| 347 | - '"></span>', | |
| 313 | + 'name' => __( 'Query String', 'wpgetapi' ), | |
| 348 | 314 | 'id' => 'query_parameters', |
| 349 | 315 | 'type' => 'parameter', |
| 350 | 316 | 'classes' => 'field-query-parameters', |
| 351 | 317 | 'repeatable' => true, |
| 352 | - 'desc' => '' | |
| 318 | + 'desc' => __( 'Parameters as name/value pairs that will be appended to the URL. ', 'wpgetapi' ), | |
| 353 | 319 | ), |
| 354 | 320 | array( |
| 355 | - 'name' => __( 'Headers', 'wpgetapi' ) . | |
| 356 | - '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 357 | - sprintf( | |
| 358 | - __( 'Parameters as name/value pairs, sent in the Headers. %1s', 'wpgetapi' ), | |
| 359 | - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/sending-headers-in-request/?utm_campaign=Headers&utm_medium=Admin&utm_source=User">More Info</a>' ) | |
| 360 | - ) . | |
| 361 | - '"></span>', | |
| 321 | + 'name' => __( 'Headers', 'wpgetapi' ), | |
| 362 | 322 | 'id' => 'header_parameters', |
| 363 | 323 | 'type' => 'parameter', |
| 364 | 324 | 'classes' => 'field-header-parameters', |
| 365 | 325 | 'repeatable' => true, |
| 366 | - 'desc' => '' | |
| 326 | + 'desc' => __( 'Parameters as name/value pairs that will be included in the header. ', 'wpgetapi' ), | |
| 367 | 327 | ), |
| 368 | 328 | array( |
| 369 | - 'name' => __( 'Body POST Fields', 'wpgetapi' ) . | |
| 370 | - '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 371 | - sprintf( | |
| 372 | - __( 'Parameters as name/value pairs, sent in the Body as POST fields. %1s', 'wpgetapi' ), | |
| 373 | - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/docs/sending-post-fields-in-request/?utm_campaign=Body&utm_medium=Admin&utm_source=User">More Info</a>' ) | |
| 374 | - ) . | |
| 375 | - '"></span>', | |
| 329 | + 'name' => __( 'Body', 'wpgetapi' ), | |
| 376 | 330 | 'id' => 'body_parameters', |
| 377 | 331 | 'type' => 'parameter', |
| 378 | 332 | 'classes' => 'field-body-parameters', |
| 379 | 333 | 'repeatable' => true, |
| 380 | - 'desc' => '' | |
| 334 | + 'desc' => __( 'Parameters as name/value pairs that will be included in the POST body fields. Only used when POST method is selected. ', 'wpgetapi' ), | |
| 381 | 335 | ), |
| 382 | 336 | array( |
| 383 | - 'name' => __( 'Encode Body', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . __( 'Encoding of the above Body parameters.', 'wpgetapi' ) . '"></span>', | |
| 337 | + 'name' => __( 'JSON Encode Body', 'wpgetapi' ), | |
| 384 | 338 | 'id' => 'body_json_encode', |
| 385 | 339 | 'type' => 'select', |
| 386 | 340 | 'classes' => 'field-body-json-encode', |
| 387 | - 'options' => array( | |
| 388 | - 'false' => __( 'No encoding (raw)', 'wpgetapi' ), | |
| 389 | - 'true' => __( 'JSON encode', 'wpgetapi' ), | |
| 390 | - 'url' => __( 'URL encode (x-www-form-urlencoded)', 'wpgetapi' ), | |
| 391 | - 'base64' => __( 'Base64 encode', 'wpgetapi' ), | |
| 392 | - 'xml' => __( 'XML format (available in PRO)', 'wpgetapi' ), | |
| 393 | - | |
| 341 | + 'options' => array( | |
| 342 | + 'true' => __( 'Yes', 'wpgetapi' ), | |
| 343 | + 'false' => __( 'No', 'wpgetapi' ), | |
| 394 | 344 | ), |
| 395 | - 'desc' => '', | |
| 345 | + 'desc' => __( 'Do you want to JSON encode the Body parameters above. ', 'wpgetapi' ), | |
| 396 | 346 | ), |
| 397 | - array( | |
| 398 | - 'name' => __( 'Actions', 'wpgetapi' ) . '<span class="dashicons dashicons-editor-help" data-tip="' . | |
| 399 | - sprintf( | |
| 400 | - __( 'Call this endpoint when your chosen action runs. This feature is available in the PRO plugin. %1s', 'wpgetapi' ), | |
| 401 | - htmlentities( '<br><a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=Actions">View PRO Plugin</a>' ) | |
| 402 | - ) . | |
| 403 | - '"></span>', | |
| 404 | - 'id' => 'actions', | |
| 405 | - 'type' => 'select', | |
| 406 | - 'classes' => 'field-actions', | |
| 407 | - 'desc' => __( 'Available in PRO plugin.', 'wpgetapi' ), | |
| 408 | - 'options' => array( | |
| 409 | - '' => __( '-- No Action --', 'wpgetapi-extras' ), | |
| 410 | - 'new_post_published' => __( 'Post/Custom Post - New Post Published', 'wpgetapi-extras' ), | |
| 411 | - 'transition_post_status' => __( 'Post/Custom Post - Status Changed', 'wpgetapi-extras' ), | |
| 412 | - 'delete_post' => __( 'Post/Custom Post - Delete Post', 'wpgetapi-extras' ), | |
| 413 | - | |
| 414 | - 'user_register' => __( 'User - New User Registered', 'wpgetapi-extras' ), | |
| 415 | - 'delete_user' => __( 'User - Delete User', 'wpgetapi-extras' ), | |
| 416 | - 'user_login' => __( 'User - User Logs In', 'wpgetapi-extras' ), | |
| 417 | - 'woocommerce_new_product' => __( 'WooCommerce - New Product Created', 'wpgetapi-extras' ), | |
| 418 | - 'woocommerce_new_order' => __( 'WooCommerce - New Order Created', 'wpgetapi-extras' ), | |
| 419 | - 'woocommerce_order_status_changed' => __( 'WooCommerce - Order Status Changed', 'wpgetapi-extras' ), | |
| 420 | - 'contact_form_7' => __( 'Contact Form 7', 'wpgetapi-extras' ), | |
| 421 | - 'gravity_forms' => __( 'Gravity Forms', 'wpgetapi-extras' ), | |
| 422 | - 'wpforms' => __( 'WPForms', 'wpgetapi-extras' ), | |
| 423 | - 'jetformbuilder' => __( 'JetFormBuilder', 'wpgetapi-extras' ), | |
| 424 | - 'formidable_forms' => __( 'Formidable Forms', 'wpgetapi-extras' ), | |
| 425 | - 'pmp' => __( 'Paid Memberships Pro - After Checkout', 'wpgetapi-extras' ), | |
| 426 | - 'edd' => __( 'Easy Digital Downloads - Complete Purchase', 'wpgetapi-extras' ), | |
| 427 | - ), | |
| 428 | - 'default' => '', | |
| 429 | - ) | |
| 430 | - | |
| 431 | 347 | ) ); |
| 432 | 348 | |
| 433 | 349 | |
| 434 | 350 | $fields[] = array( |
| @@ -433,9 +349,9 @@ | ||
| 433 | 349 | |
| 434 | 350 | $fields[] = array( |
| 435 | 351 | 'id' => 'endpoints', |
| 436 | 352 | 'type' => 'group', |
| 437 | - 'name' => '', | |
| 353 | + 'name' => __( 'Endpoints', 'wpgetapi' ), | |
| 438 | 354 | 'description' => '', |
| 439 | 355 | 'options' => array( |
| 440 | 356 | 'group_title' => __( 'Endpoint {#}', 'wpgetapi' ), |
| 441 | 357 | 'add_button' => __( 'Add Endpoint', 'wpgetapi' ), |
| @@ -441,13 +357,12 @@ | ||
| 441 | 357 | 'add_button' => __( 'Add Endpoint', 'wpgetapi' ), |
| 442 | 358 | 'remove_button' => __( 'Remove Endpoint', 'wpgetapi' ), |
| 443 | 359 | 'sortable' => true, // beta |
| 444 | 360 | ), |
| 445 | - 'before_group' => '<pre class="url">Base URL: <span>' . $base_url . '</span></pre>', | |
| 446 | 361 | 'fields' => $endpoint_fields, |
| 447 | 362 | ); |
| 448 | 363 | |
| 449 | - return apply_filters( 'wpgetapi_fields', $fields ); | |
| 364 | + return $fields; | |
| 450 | 365 | |
| 451 | 366 | } |
| 452 | 367 | |
| 453 | 368 | |
| @@ -457,9 +372,9 @@ | ||
| 457 | 372 | |
| 458 | 373 | foreach ($option_tabs as $index => $option_tab) { |
| 459 | 374 | if ( $index == 0) { |
| 460 | 375 | |
| 461 | - $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'none' | |
| 376 | + $this->options_pages[] = add_menu_page( $this->title, $this->menu_title, 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ), 'dashicons-editor-code' | |
| 462 | 377 | ); //Link admin menu to first tab |
| 463 | 378 | |
| 464 | 379 | add_submenu_page( $option_tabs[0]['id'], $this->menu_title, $option_tab['menu_title'], 'manage_options', $option_tab['id'], array( $this, 'admin_page_display' ) ); //Duplicate menu link for first submenu page |
| 465 | 380 | } else { |
| @@ -487,15 +402,12 @@ | ||
| 487 | 402 | <div class="wrap wpgetapi"> |
| 488 | 403 | |
| 489 | 404 | <div class="main_content_cell"> |
| 490 | 405 | |
| 491 | - <h1 class="wp-heading-inline"> | |
| 492 | - <img width="24" height="22" src="<?php echo esc_url( WPGETAPIURL . 'assets/img/wpgetapi-icon.png' ); ?>" /> <?php esc_html_e( $this->title, 'wpgetapi' ) ?> <span class="vnum"><?php echo WPGETAPIVERSION; ?></span> | |
| 493 | - </h1> | |
| 406 | + <h2><?php esc_html_e( $this->title, 'wpgetapi' ) ?></h2> | |
| 494 | 407 | <!-- Options Page Nav Tabs --> |
| 495 | 408 | <h2 class="nav-tab-wrapper"> |
| 496 | 409 | <?php foreach ($option_tabs as $option_tab) : |
| 497 | - | |
| 498 | 410 | $tab_slug = $option_tab['id']; |
| 499 | 411 | $nav_class = 'nav-tab'; |
| 500 | 412 | if ( $tab_slug == $_GET['page'] ) { |
| 501 | 413 | $nav_class .= ' nav-tab-active'; //add active class to current tab |
| @@ -500,20 +412,15 @@ | ||
| 500 | 412 | if ( $tab_slug == $_GET['page'] ) { |
| 501 | 413 | $nav_class .= ' nav-tab-active'; //add active class to current tab |
| 502 | 414 | $tab_forms[] = $option_tab; //add current tab to forms to be rendered |
| 503 | 415 | } |
| 504 | - | |
| 505 | - ?> | |
| 506 | - | |
| 507 | - <a class="<?php esc_attr_e( $nav_class ); ?>" href="<?php esc_url( menu_page_url( $tab_slug ) ); ?>"><?php esc_attr_e( $option_tab['menu_title'], 'wpgetapi' ); ?></a> | |
| 508 | - | |
| 416 | + ?> | |
| 417 | + <a class="<?php esc_attr_e( $nav_class ); ?>" href="<?php esc_url( menu_page_url( $tab_slug ) ); ?>"><?php esc_attr_e( $option_tab['title'], 'wpgetapi' ); ?></a> | |
| 509 | 418 | <?php endforeach; ?> |
| 510 | 419 | </h2> |
| 511 | 420 | <!-- End of Nav Tabs --> |
| 512 | 421 | |
| 513 | - <?php | |
| 514 | - //render all tab forms (normaly just 1 form) | |
| 515 | - foreach ($tab_forms as $tab_form) : ?> | |
| 422 | + <?php foreach ($tab_forms as $tab_form) : //render all tab forms (normaly just 1 form) ?> | |
| 516 | 423 | |
| 517 | 424 | <div id="<?php esc_attr_e($tab_form['id']); ?>" class="cmb-form group"> |
| 518 | 425 | <div class="metabox-holder"> |
| 519 | 426 | <div class="pmpbox pad"> |
| @@ -518,9 +425,9 @@ | ||
| 518 | 425 | <div class="metabox-holder"> |
| 519 | 426 | <div class="pmpbox pad"> |
| 520 | 427 | <h3 class="title"><?php esc_html_e($tab_form['title'], 'wpgetapi'); ?></h3> |
| 521 | 428 | <div class="desc"><?php echo wp_kses_post( $tab_form['desc'] ); ?></div> |
| 522 | - <?php cmb2_metabox_form( $tab_form, $tab_form['id'], $tab_form ); ?> | |
| 429 | + <?php cmb2_metabox_form( $tab_form, $tab_form['id'] ); ?> | |
| 523 | 430 | </div> |
| 524 | 431 | </div> |
| 525 | 432 | </div> |
| 526 | 433 | |
| @@ -528,14 +435,21 @@ | ||
| 528 | 435 | |
| 529 | 436 | </div> |
| 530 | 437 | |
| 531 | 438 | <div class="sidebar_cell"> |
| 532 | - | |
| 533 | - <?php | |
| 534 | - $sidebar = self::sidebar_display(); | |
| 535 | - echo apply_filters( 'wpgetapi_admin_sidebar_display', $sidebar ); | |
| 536 | - ?> | |
| 439 | + <div class="box"> | |
| 440 | + <h3>Help & Tips</h3> | |
| 441 | + <p><a class="button-primary" target="_blank" href="https://wpgetapi.com/docs/?utm_campaign=Help&utm_medium=Admin&utm_source=User">View The Docs</a></p> | |
| 442 | + <ul> | |
| 443 | + <li><b>Using the Template Tag within your theme is the most flexible option and is recommended.</b></li> | |
| 444 | + <li>The Template Tag will 'return' data only. To output to your page you will need to 'echo' or 'var_dump'.</li> | |
| 445 | + <li>Trying to 'echo' the data when using the 'JSON (as array data)' option will result in a PHP warning. You will need to use 'var_dump' instead to see the output.</li> | |
| 446 | + <li>Using the Shortcode within a page (or post) becomes a little more flexible when used in conjunction with our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">Pro plugin</a>.</li> | |
| 537 | 447 | |
| 448 | + <li>You can get nested data from the array using our <a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">Pro Plugin</a> extension using either Shortcode or Template Tag.</li> | |
| 449 | + </ul> | |
| 450 | + </div> | |
| 451 | + | |
| 538 | 452 | </div> |
| 539 | 453 | |
| 540 | 454 | </div> |
| 541 | 455 | |
| @@ -541,214 +455,8 @@ | ||
| 541 | 455 | |
| 542 | 456 | <?php |
| 543 | 457 | |
| 544 | 458 | } |
| 545 | - | |
| 546 | - | |
| 547 | - public function test_the_endpoint() { | |
| 548 | - | |
| 549 | - $api_id = sanitize_text_field( $_POST['api_id'] ); | |
| 550 | - $endpoint_id = sanitize_text_field( $_POST['endpoint_id'] ); | |
| 551 | - $data = wpgetapi_endpoint( $api_id, $endpoint_id, array( 'test_endpoint' => true ) ); | |
| 552 | - | |
| 553 | - $output = array( | |
| 554 | - 'data' => $data, | |
| 555 | - 'endpoint_id' => $endpoint_id | |
| 556 | - ); | |
| 557 | - echo json_encode( $output ); | |
| 558 | - | |
| 559 | - wp_die(); // this is required to terminate immediately and return a proper response | |
| 560 | - | |
| 561 | - } | |
| 562 | - | |
| 563 | - | |
| 564 | - public function load_testing_javascript() { ?> | |
| 565 | - | |
| 566 | - <script type="text/javascript" > | |
| 567 | - | |
| 568 | - jQuery(document).ready(function($) { | |
| 569 | - | |
| 570 | - $('body').on( 'click', '.wpgetapi-test-area .test-button', function(){//delegated | |
| 571 | - | |
| 572 | - var $this = $(this); | |
| 573 | - var area = $this.parents( '.wpgetapi-test-area' ); | |
| 574 | - var api_id = $( area ).data( 'api' ); | |
| 575 | - var endpoint_id = $( area ).data( 'endpoint' ); | |
| 576 | - | |
| 577 | - // disable button | |
| 578 | - $this.attr( 'disabled', true ); | |
| 579 | - | |
| 580 | - var data = { | |
| 581 | - 'action': 'wpgetapi_test_endpoint', | |
| 582 | - 'api_id': api_id, | |
| 583 | - 'endpoint_id': endpoint_id | |
| 584 | - }; | |
| 585 | - | |
| 586 | - // send and get response | |
| 587 | - jQuery.post(ajaxurl, data, function( response ) { | |
| 588 | - | |
| 589 | - var output = JSON.parse( response ); | |
| 590 | - | |
| 591 | - jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .handle' ).show(); | |
| 592 | - | |
| 593 | - jQuery( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .wpgetapi-result' ).html( output.data); | |
| 594 | - | |
| 595 | - // enable button | |
| 596 | - $( '.wpgetapi-test-area[data-endpoint="' + output.endpoint_id + '"] .test-button' ).attr( 'disabled', false ); | |
| 597 | - | |
| 598 | - }); | |
| 599 | - | |
| 600 | - }); | |
| 601 | - | |
| 602 | - $( '.wpgetapi-test-area .handle' ).on('click', function() { | |
| 603 | - $('.wpgetapi-result').toggle(); | |
| 604 | - }); | |
| 605 | - | |
| 606 | - }); | |
| 607 | - | |
| 608 | - </script> <?php | |
| 609 | - | |
| 610 | - } | |
| 611 | - | |
| 612 | - | |
| 613 | - /** | |
| 614 | - * Sidebar markup. | |
| 615 | - * @since 1.4.1 | |
| 616 | - */ | |
| 617 | - public function sidebar_display() { | |
| 618 | - | |
| 619 | - ob_start(); | |
| 620 | - | |
| 621 | - // do our setup page | |
| 622 | - if( isset( $_GET['page'] ) && $_GET['page'] === 'wpgetapi_setup' ) | |
| 623 | - return $this->sidebar_setup_page(); | |
| 624 | - | |
| 625 | - ?> | |
| 626 | - | |
| 627 | - <div class="box"> | |
| 628 | - <strong><?php esc_html_e( 'Endpoint Instructions', 'wpgetapi' ); ?></strong> | |
| 629 | - <ol> | |
| 630 | - <li><?php _e( 'Give your endpoint a <b>Unique ID</b>', 'wpgetapi' ); ?></li> | |
| 631 | - <li><?php _e( 'Add the <b>Endpoint</b> which can be found in your API docs', 'wpgetapi' ); ?></li> | |
| 632 | - <li><?php _e( 'Set the <b>Method</b> - GET for getting data & POST for sending data to the API', 'wpgetapi' ); ?></li> | |
| 633 | - <li><?php _e( 'Set the desired <b>Results Format</b>', 'wpgetapi' ); ?></li> | |
| 634 | - <li><?php _e( 'Other fields are optional & will depend on your API', 'wpgetapi' ); ?></li> | |
| 635 | - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li> | |
| 636 | - <li><?php _e( 'Copy the Template Tag or Shortcode & paste into page, post or theme file', 'wpgetapi' ); ?></li> | |
| 637 | - </ol> | |
| 638 | - </div> | |
| 639 | - | |
| 640 | - <hr> | |
| 641 | - | |
| 642 | - <div class="box"> | |
| 643 | - <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong> | |
| 644 | - <ul> | |
| 645 | - <li><?php | |
| 646 | - printf( | |
| 647 | - esc_html__( 'View the %1$s', 'cmb2' ), | |
| 648 | - '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>' | |
| 649 | - ); | |
| 650 | - ?></li> | |
| 651 | - <li><?php | |
| 652 | - printf( | |
| 653 | - esc_html__( 'View the %1$s', 'cmb2' ), | |
| 654 | - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>' | |
| 655 | - ); | |
| 656 | - ?></li> | |
| 657 | - <li><?php | |
| 658 | - printf( | |
| 659 | - esc_html__( 'Do more with the %1$s', 'cmb2' ), | |
| 660 | - '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>' | |
| 661 | - ); | |
| 662 | - ?></li> | |
| 663 | - </ul> | |
| 664 | - </div> | |
| 665 | - | |
| 666 | - <?php | |
| 667 | - $content = ob_get_contents(); | |
| 668 | - ob_end_clean(); | |
| 669 | - return $content; | |
| 670 | - | |
| 671 | - } | |
| 672 | - | |
| 673 | - | |
| 674 | - /** | |
| 675 | - * Sidebar for our setup page. | |
| 676 | - * @since 1.4.4 | |
| 677 | - */ | |
| 678 | - public function sidebar_setup_page() { | |
| 679 | - | |
| 680 | - ob_start(); | |
| 681 | - ?> | |
| 682 | - | |
| 683 | - <div class="box"> | |
| 684 | - <strong><?php esc_html_e( 'Setup Instructions', 'wpgetapi' ); ?></strong> | |
| 685 | - <ol> | |
| 686 | - <li><?php _e( 'Name your API in the <b>API Name</b> field', 'wpgetapi' ); ?></li> | |
| 687 | - <li><?php _e( 'Give your API a <b>Unique ID</b>', 'wpgetapi' ); ?></li> | |
| 688 | - <li><?php _e( 'Add the <b>Base URL</b> of your API. This can be found in the docs of your API', 'wpgetapi' ); ?></li> | |
| 689 | - <li><?php _e( 'Hit the Save button', 'wpgetapi' ); ?></li> | |
| 690 | - <li><?php _e( 'Visit the new tab that will be created', 'wpgetapi' ); ?></li> | |
| 691 | - </ol> | |
| 692 | - </div> | |
| 693 | - | |
| 694 | - <hr> | |
| 695 | - | |
| 696 | - <div class="box"> | |
| 697 | - <strong><?php esc_html_e( 'Getting Help', 'wpgetapi' ); ?></strong> | |
| 698 | - <ul> | |
| 699 | - <li><?php | |
| 700 | - printf( | |
| 701 | - esc_html__( 'View the %1$s', 'cmb2' ), | |
| 702 | - '<a target="_blank" href="https://wpgetapi.com/docs/quick-start-guide/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">Quick Start Guide</a>' | |
| 703 | - ); | |
| 704 | - ?></li> | |
| 705 | - <li><?php | |
| 706 | - printf( | |
| 707 | - esc_html__( 'View the %1$s', 'cmb2' ), | |
| 708 | - '<a target="_blank" href="https://wpgetapi.com/docs/frequently-asked-questions/?utm_campaign=Docs&utm_medium=Admin&utm_source=User">FAQs</a>' | |
| 709 | - ); | |
| 710 | - ?></li> | |
| 711 | - <li><?php | |
| 712 | - printf( | |
| 713 | - esc_html__( 'Do more with the %1$s', 'cmb2' ), | |
| 714 | - '<a target="_blank" href="https://wpgetapi.com/downloads/pro-plugin/?utm_campaign=Pro&utm_medium=Admin&utm_source=User">PRO Plugin</a>' | |
| 715 | - ); | |
| 716 | - ?></li> | |
| 717 | - </ul> | |
| 718 | - </div> | |
| 719 | - | |
| 720 | - <?php | |
| 721 | - $content = ob_get_contents(); | |
| 722 | - ob_end_clean(); | |
| 723 | - return $content; | |
| 724 | - | |
| 725 | - } | |
| 726 | - | |
| 727 | - | |
| 728 | - /** | |
| 729 | - * Tabs don't immmediately appear on save, so this hack! | |
| 730 | - * @since 0.1.0 | |
| 731 | - */ | |
| 732 | - public function redirect( $object_id, $updated ) { | |
| 733 | - | |
| 734 | - if( strpos( $object_id, 'wpgetapi_' ) !== false ) { | |
| 735 | - | |
| 736 | - add_settings_error( 'wpgetapi-notices', '', 'Saved, reloading page...', 'updated' ); | |
| 737 | - settings_errors( 'wpgetapi-notices' ); | |
| 738 | - ?> | |
| 739 | - | |
| 740 | - <script> | |
| 741 | - setTimeout(function() { | |
| 742 | - location.reload(); | |
| 743 | - }, 200); | |
| 744 | - </script> | |
| 745 | - <?php | |
| 746 | - | |
| 747 | - } | |
| 748 | - | |
| 749 | - } | |
| 750 | - | |
| 751 | 459 | |
| 752 | 460 | /** |
| 753 | 461 | * Public getter method for retrieving protected/private variables |
| 754 | 462 | * @since 0.1.0 |