PluginProbe
Datafeedr API / 1.0.15
Datafeedr API v1.0.15
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-tools.php

class-dfrapi-tools.php in Datafeedr API 1.0.15, at classes/class-dfrapi-tools.php

102 lines 3.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_Tools' ) ) {
6
7 /**
8 * Configuration page.
9 */
10 class Dfrapi_Tools {
11
12 private $page = 'dfrapi-tools';
13 private $key;
14
15 public function __construct() {
16 $this->key = 'dfrapi_tools';
17 add_action( 'admin_init', array( &$this, 'register_settings' ) );
18 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
19 add_action( 'admin_notices', array( $this, 'admin_notice' ) );
20 }
21
22 function admin_menu() {
23 add_submenu_page(
24 'dfrapi',
25 __( 'Tools &#8212; Datafeedr API', DFRAPI_DOMAIN ),
26 __( 'Tools', DFRAPI_DOMAIN ),
27 'manage_options',
28 $this->key,
29 array( $this, 'output' )
30 );
31 }
32
33 function admin_notice() {
34 if ( isset( $_GET['settings-updated'] ) && $_GET['settings-updated'] == true && isset( $_GET['page'] ) && $this->key == $_GET['page'] ) {
35 echo '<div class="updated"><p>';
36 _e( 'Updated!', DFRAPI_DOMAIN );
37 echo '</p></div>';
38 }
39 }
40
41 function output() {
42 echo '<div class="wrap" id="' . $this->key . '">';
43 echo '<h2>' . dfrapi_setting_pages( $this->page ) . ' &#8212; Datafeedr API</h2>';
44 echo '<form method="post" action="options.php">';
45 wp_nonce_field( 'update-options' );
46 settings_fields( $this->page );
47 do_settings_sections( $this->page);
48 submit_button();
49 echo '</form>';
50 echo '</div>';
51 }
52
53 function register_settings() {
54 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
55
56 // Delete transient data.
57 add_settings_section( 'delete_transient_data', __( 'Delete Cached API Data', DFRAPI_DOMAIN ), array( &$this, 'section_delete_transient_data_desc' ), $this->page );
58 add_settings_field( 'delete_transient_data_checkbox', __( 'Delete Cached API Data', DFRAPI_DOMAIN ), array( &$this, 'field_delete_transient_data_checkbox' ), $this->page, 'delete_transient_data' );
59 }
60
61 function section_delete_transient_data_desc() {
62 echo __( 'Select <strong>Yes</strong> below and click <strong>[Save Changes]</strong> to delete all cached API data. Deleting cached data will not affect your store, however, it will require multiple API requests in order to re-build the data. Typically, you only delete cached data when Datafeedr Support instructs you to do so.', DFRAPI_DOMAIN );
63 }
64
65 function field_delete_transient_data_checkbox() {
66 ?>
67 <input type="checkbox" name="<?php echo $this->key; ?>[delete_transient_data_checkbox]" value="on" /> <?php _e( 'Yes', DFRAPI_DOMAIN ); ?>
68 <?php
69 }
70
71 function validate( $input ) {
72
73 if ( !isset( $input ) || !is_array( $input ) || empty( $input ) ) { return $input; }
74
75 foreach( $input as $key => $value ) {
76
77 // Delete transient data.
78 if ( $key == 'delete_transient_data_checkbox' && $value == 'on' ) {
79 // Only delete if user has API requests remaining. This is because we'll need to make 1 request to rebuild 'dfrapi_account'.
80 $status = dfrapi_api_get_status();
81 if ( !array_key_exists( 'dfrapi_api_error', $status ) ) {
82 delete_option( 'dfrapi_account' );
83 $transient_options = get_option( 'dfrapi_transient_whitelist' );
84 if ( !empty( $transient_options ) ) {
85 foreach ( $transient_options as $name ) {
86 delete_transient( $name );
87 }
88 }
89 // Update account status immediately in case there are not enough API
90 // requests remaining in order to do so later.
91 $status = dfrapi_api_get_status();
92 update_option( 'dfrapi_account', $status );
93 }
94 } // END Delete transient data.
95
96 } // END foreach( $input as $key => $value ) {
97 }
98
99 } // class Dfrapi_Tools
100
101 } // class_exists check
102