PluginProbe
Datafeedr API / 1.2.12
Datafeedr API v1.2.12
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 1.0.33 All 181 releases
datafeedr-api / classes / class-dfrapi-tools.php

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

125 lines 4.9 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' ), 40 );
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 ?>
45
46 <script>
47 jQuery(function($) {
48
49 $('#dfrapi_delete_cached_api_data').on('click',function(e) {
50 $("#dfrapi_delete_cached_api_data_result").hide();
51 $("#dfrapi_delete_cached_api_data").text('<?php _e("Deleting...", DFRAPI_DOMAIN); ?>').addClass('button-disabled');
52 $.ajax({
53 type: "POST",
54 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
55 data: {
56 action: "dfrapi_delete_cached_api_data",
57 dfrapi_security: "<?php echo wp_create_nonce( 'dfrapi_ajax_nonce' ); ?>"
58 }
59 }).done(function(html) {
60 $("#dfrapi_delete_cached_api_data").text('<?php _e("Delete Cached API Data", DFRAPI_DOMAIN); ?>').removeClass('button-disabled');
61 $("#dfrapi_delete_cached_api_data_result").show().html(html);
62
63 });
64 e.preventDefault();
65 }); // $('#dfrapi_delete_cached_api_data').on('click',function(e) {
66
67 $('#dfrapi_test_api_connection').on('click',function(e) {
68 $("#dfrapi_test_api_connection_result").hide();
69 $("#dfrapi_test_api_connection").text('<?php _e("Testing...", DFRAPI_DOMAIN); ?>').addClass('button-disabled');
70 $.ajax({
71 type: "POST",
72 url: "<?php echo admin_url( 'admin-ajax.php' ); ?>",
73 data: {
74 action: "dfrapi_test_api_connection",
75 dfrapi_security: "<?php echo wp_create_nonce( 'dfrapi_ajax_nonce' ); ?>"
76 }
77 }).done(function(html) {
78 $("#dfrapi_test_api_connection").text('<?php _e("Test Connection", DFRAPI_DOMAIN); ?>').removeClass('button-disabled');
79 $("#dfrapi_test_api_connection_result").show().html(html);
80
81 });
82 e.preventDefault();
83 }); // $('#dfrapi_delete_cached_api_data').on('click',function(e) {
84
85 }); // jQuery(function($) {
86 </script>
87
88 <?php
89
90 settings_fields( $this->page );
91 do_settings_sections( $this->page);
92 echo '</div>';
93 }
94
95 function register_settings() {
96 register_setting( $this->page, $this->key, array( $this, 'validate' ) );
97
98 add_settings_section( 'test_connection', __( 'Test API Connection', DFRAPI_DOMAIN ), array( &$this, 'section_test_connection_desc' ), $this->page );
99 add_settings_section( 'delete_transient_data', __( 'Delete Cached API Data', DFRAPI_DOMAIN ), array( &$this, 'section_delete_transient_data_desc' ), $this->page );
100 }
101
102 function section_delete_transient_data_desc() { ?>
103 <p><?php _e( '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 ); ?></p>
104 <p><a href="#" id="dfrapi_delete_cached_api_data" class="button"><?php _e("Delete Cached API Data", DFRAPI_DOMAIN); ?></a></p>
105 <div id="dfrapi_delete_cached_api_data_result" style="padding: 10px; border: 1px solid silver; display: none; background: #FFF; color: green;"></div>
106 <hr />
107 <?php
108 }
109
110 function section_test_connection_desc() { ?>
111 <p><?php _e( 'Test your web server\'s connection to the Datafeedr API servers. This will not count against your overall API request count.', DFRAPI_DOMAIN ); ?></p>
112 <p><a href="#" id="dfrapi_test_api_connection" class="button"><?php _e("Test Connection", DFRAPI_DOMAIN); ?></a></p>
113 <div id="dfrapi_test_api_connection_result" style="padding: 10px; border: 1px solid silver; display: none; background: #FFF;"></div>
114 <hr />
115 <?php
116 }
117
118 function validate( $input ) {
119 return $input;
120 }
121
122 } // class Dfrapi_Tools
123
124 } // class_exists check
125