PluginProbe
Datafeedr API / 1.4.3
Datafeedr API v1.4.3
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
← All changes | classes/class-dfrapi-initialize.php +120 -180 1.0.125 → 1.4.3 View file →
@@ -1,218 +1,158 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 -if ( ! class_exists( 'Dfrapi_Initialize' ) ) {
4 2
3 +defined( 'ABSPATH' ) || exit;
5 4
6 -class Dfrapi_Initialize {
5 +if ( ! class_exists( 'Dfrapi_Initialize' ) ) {
7 6
8 - public function __construct() {
7 + class Dfrapi_Initialize {
9 8
10 - // Core admin functions.
11 - require_once( DFRAPI_PATH . 'functions/admin-functions.php' );
9 + public function __construct() {
12 10
13 - // Load required classes.
14 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-env.php' ); // Checks environment for any problems.
15 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-configuration.php' ); // Configuration page.
16 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-networks.php' ); // Networks page.
17 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-merchants.php' ); // Merchants page.
18 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-tools.php' ); // Tools page.
19 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-export.php' ); // Export page.
20 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-import.php' ); // Import page.
21 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-account.php' ); // Account page.
22 - require_once( DFRAPI_PATH . 'classes/class-dfrapi-help.php' ); // Help tabs.
11 + // Actions
12 + add_action( 'plugins_loaded', [ $this, 'initialize_classes' ] );
13 + add_action( 'admin_menu', [ $this, 'admin_menu' ] );
14 + add_action( 'admin_menu', [ $this, 'networks_menu' ], 20 );
15 + add_action( 'admin_menu', [ $this, 'merchants_menu' ], 30 );
16 + add_action( 'wp_ajax_search_form', [ $this, 'ajax_search_form' ] );
23 17
24 - // Hooks
25 - add_action( 'admin_enqueue_scripts', array( $this, 'load_css' ) );
26 - add_action( 'admin_enqueue_scripts', array( $this, 'load_js' ) );
27 - add_action( 'plugins_loaded', array( $this, 'initialize_classes' ) );
28 - add_action( 'admin_notices', array( $this, 'admin_notices' ) );
18 + // Datafeedr Admin Pages have been loaded. Broadcast "loaded" action.
19 + do_action( 'dfrapi_loaded' );
20 + }
29 21
30 - add_action( 'admin_menu', array( $this, 'admin_menu' ) );
31 - add_action( 'admin_menu', array( $this, 'networks_menu' ), 20 );
32 - add_action( 'admin_menu', array( $this, 'merchants_menu' ), 30 );
22 + function ajax_search_form() {
33 23
34 - add_action( 'wp_ajax_search_form', array( $this, 'ajax_search_form' ) );
24 + check_ajax_referer( 'dfrapi_search_form', 'dfrapi_security' );
35 25
36 - add_filter( 'plugin_action_links_' . DFRAPI_BASENAME, array( $this, 'action_links' ) );
37 - add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
26 + /**
27 + * Filters the capability required to use the search form's AJAX handler.
28 + *
29 + * @since 1.4.3
30 + *
31 + * @param string $capability Default 'edit_posts'.
32 + */
33 + $capability = apply_filters( 'dfrapi_search_form_capability', 'edit_posts' );
38 34
39 - do_action( 'dfrapi_loaded' );
35 + if ( ! current_user_can( $capability ) ) {
36 + wp_die( -1, 403 );
37 + }
40 38
41 - }
39 + $sform = new Dfrapi_SearchForm();
40 + echo $sform->ajaxHandler();
41 + die;
42 + }
42 43
43 - function ajax_search_form() {
44 - $sform = new Dfrapi_SearchForm();
45 - echo $sform->ajaxHandler();
46 - die;
47 - }
44 + function admin_menu() {
45 + add_menu_page(
46 + __( 'Datafeedr API', 'datafeedr-api' ),
47 + __( 'Datafeedr API', 'datafeedr-api' ),
48 + 'manage_options',
49 + 'dfrapi',
50 + '',
51 + null,
52 + 42
53 + );
54 + }
48 55
49 - function admin_menu() {
50 - add_menu_page(
51 - __( 'Datafeedr API', DFRAPI_DOMAIN ),
52 - __( 'Datafeedr API', DFRAPI_DOMAIN ),
53 - 'manage_options',
54 - 'dfrapi',
55 - '',
56 - null,
57 - 42
58 - );
59 - }
60 -
61 - function networks_menu() {
62 - add_submenu_page(
63 - 'dfrapi',
64 - __( 'Networks &#8212; Datafeedr API', DFRAPI_DOMAIN ),
65 - __( 'Networks', DFRAPI_DOMAIN ),
66 - 'manage_options',
67 - 'dfrapi_networks',
68 - array( $this, 'networks_output' )
69 - );
70 - }
71 -
72 - public function networks_output() {
73 - $key = 'dfrapi_networks';
74 - $page = 'dfrapi-networks';
75 - echo '<div class="wrap" id="' . $key . '">';
76 - echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
77 - echo '<form method="post" action="options.php">';
78 - submit_button();
79 - wp_nonce_field( 'update-options' );
80 - settings_fields( $page );
81 - do_settings_sections( $page );
82 - submit_button();
83 - echo '</form>';
84 - echo '<div id="dfr_unload_message" style="display:none">' .
85 - __( 'You have unsaved changes', DFRAPI_DOMAIN ) .
86 - '</div>';
87 - echo '</div>';
88 - }
89 -
90 - function merchants_menu() {
91 - add_submenu_page(
92 - 'dfrapi',
93 - __( 'Merchants &#8212; Datafeedr API', DFRAPI_DOMAIN ),
94 - __( 'Merchants', DFRAPI_DOMAIN ),
95 - 'manage_options',
96 - 'dfrapi_merchants',
97 - array( $this, 'merchants_output' )
98 - );
99 - }
100 -
101 - function merchants_output() {
102 - $key = 'dfrapi_merchants';
103 - $page = 'dfrapi-merchants';
104 - echo '<div class="wrap" id="' . $key . '">';
105 - echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
106 - echo '<form method="post" action="options.php">';
107 - submit_button();
108 - wp_nonce_field( 'update-options' );
109 - settings_fields( $page );
110 - do_settings_sections( $page );
111 - submit_button();
112 - echo '</form>';
113 - echo '<div id="dfr_unload_message" style="display:none">' .
114 - __( 'You have unsaved changes', DFRAPI_DOMAIN ) . '</div>';
115 - echo '</div>';
116 - }
117 -
118 - function initialize_classes() {
119 -
120 - new Dfrapi_Configuration();
121 -
122 - // Show "Networks" page if API keys are present.
123 - if ( Dfrapi_Env::api_keys_exist() ) {
124 -
125 - if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_networks' == $_GET['page'] ) {
126 - new Dfrapi_Networks();
56 + public function networks_menu() {
57 + if ( dfrapi_datafeedr_api_keys_exist() ) {
58 + add_submenu_page(
59 + 'dfrapi',
60 + __( 'Networks &#8212; Datafeedr API', 'datafeedr-api' ),
61 + __( 'Networks', 'datafeedr-api' ),
62 + 'manage_options',
63 + 'dfrapi_networks',
64 + array( $this, 'networks_output' )
65 + );
127 66 }
67 + }
128 68
129 - if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-networks' == $_POST['option_page'] ) ) {
130 - new Dfrapi_Networks();
131 - }
69 + public function networks_output() {
70 + $key = 'dfrapi_networks';
71 + $page = 'dfrapi-networks';
72 + echo '<div class="wrap" id="' . $key . '">';
73 + echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
74 + echo '<form method="post" action="options.php">';
75 + submit_button();
76 + wp_nonce_field( 'update-options' );
77 + settings_fields( $page );
78 + do_settings_sections( $page );
79 + submit_button();
80 + echo '</form>';
81 + echo '<div id="dfr_unload_message" style="display:none">' .
82 + __( 'You have unsaved changes', 'datafeedr-api' ) .
83 + '</div>';
84 + echo '</div>';
132 85 }
133 86
134 - // Show "Merchants" page if API keys are present AND a network is selected.
135 - if ( Dfrapi_Env::api_keys_exist() && Dfrapi_Env::network_is_selected() ) {
136 -
137 - if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_merchants' == $_GET['page'] ) {
138 - new Dfrapi_Merchants();
87 + public function merchants_menu() {
88 + if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_selected_network_count() > 0 ) {
89 + add_submenu_page(
90 + 'dfrapi',
91 + __( 'Merchants &#8212; Datafeedr API', 'datafeedr-api' ),
92 + __( 'Merchants', 'datafeedr-api' ),
93 + 'manage_options',
94 + 'dfrapi_merchants',
95 + array( $this, 'merchants_output' )
96 + );
139 97 }
140 -
141 - if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' == $_POST['option_page'] ) ) {
142 - new Dfrapi_Merchants();
143 - }
144 98 }
145 99
146 - // Show Tools, Export and Import pages if API keys are present.
147 - if ( Dfrapi_Env::api_keys_exist() ) {
148 - new Dfrapi_Tools();
149 - new Dfrapi_Export();
150 - new Dfrapi_Import();
151 - new Dfrapi_Account();
100 + function merchants_output() {
101 + $key = 'dfrapi_merchants';
102 + $page = 'dfrapi-merchants';
103 + echo '<div class="wrap" id="' . $key . '">';
104 + echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
105 + echo '<form method="post" action="options.php">';
106 + submit_button();
107 + wp_nonce_field( 'update-options' );
108 + settings_fields( $page );
109 + do_settings_sections( $page );
110 + submit_button();
111 + echo '</form>';
112 + echo '<div id="dfr_unload_message" style="display:none">' .
113 + __( 'You have unsaved changes', 'datafeedr-api' ) . '</div>';
114 + echo '</div>';
152 115 }
153 - }
154 116
155 - function load_css() {
117 + function initialize_classes() {
156 118
157 - // Basic styling for API pages.
158 - wp_register_style( 'dfrapi_css', DFRAPI_URL . 'css/style.css', false, DFRAPI_VERSION );
159 - wp_enqueue_style( 'dfrapi_css' );
119 + new Dfrapi_Configuration();
160 120
161 - // Basic styling for API pages.
162 - wp_register_style( 'dfrapi_searchform', DFRAPI_URL . 'css/searchform.css', false, DFRAPI_VERSION );
163 - wp_enqueue_style( 'dfrapi_searchform' );
164 - }
121 + // Show "Networks" page if API keys are present.
122 + if ( dfrapi_datafeedr_api_keys_exist() ) {
165 123
166 - function load_js() {
124 + if ( isset( $_GET['page'] ) && 'dfrapi_networks' === $_GET['page'] && is_admin() ) {
125 + new Dfrapi_Networks();
126 + }
167 127
168 - wp_register_script( 'dfrapi_general_js', DFRAPI_URL.'js/general.js', array( 'jquery' ), DFRAPI_VERSION, true );
169 - wp_enqueue_script( 'dfrapi_general_js' );
128 + if ( isset( $_POST['option_page'] ) && ( 'dfrapi-networks' === $_POST['option_page'] ) && is_admin() ) {
129 + new Dfrapi_Networks();
130 + }
131 + }
170 132
171 - wp_register_script( 'dfrapi_searchfilter_js', DFRAPI_URL.'js/searchfilter.js', array( 'jquery' ), DFRAPI_VERSION, false );
172 - wp_enqueue_script( 'dfrapi_searchfilter_js' );
133 + // Show "Merchants" page if API keys are present AND a network is selected.
134 + if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_user_has_selected_networks() ) {
173 135
174 - wp_register_script( 'dfrapi_merchants_js', DFRAPI_URL.'js/merchants.js', array( 'jquery' ), DFRAPI_VERSION, false );
175 - wp_enqueue_script( 'dfrapi_merchants_js' );
136 + if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_merchants' === $_GET['page'] ) {
137 + new Dfrapi_Merchants();
138 + }
176 139
177 - wp_register_script( 'dfrapi_searchform_js', DFRAPI_URL.'js/searchform.js', array( 'jquery' ), DFRAPI_VERSION, false );
178 - wp_enqueue_script( 'dfrapi_searchform_js' );
140 + if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' === $_POST['option_page'] ) ) {
141 + new Dfrapi_Merchants();
142 + }
143 + }
179 144
180 - wp_register_script( 'dfrapi_jquery_reveal_js', DFRAPI_URL.'js/jquery.reveal.js', array( 'jquery' ), DFRAPI_VERSION, false );
181 - wp_enqueue_script( 'dfrapi_jquery_reveal_js' );
182 - }
183 -
184 - function admin_notices() {
185 - $dfrapi_env = new Dfrapi_Env();
186 - if ( $notices = get_option( 'dfrapi_admin_notices' ) ) {
187 - foreach ( $notices as $key => $message ) {
188 - $button = ( $message['url'] != '' ) ? dfrapi_fix_button( $message['url'], $message['button_text'] ) : '';
189 - $upgrade_account = ( $key == 'usage_over_90_percent' ) ? ' | <a href="' . dfrapi_user_pages( 'change' ) . '?utm_source=plugin&utm_medium=link&utm_campaign=upgradenag">' . __( 'Upgrade', DFRAPI_DOMAIN ) . '</a>' : '';
190 - echo '<div class="'.$message['class'].'"><p>'.$message['message'].$button.$upgrade_account.'</p></div>';
145 + // Show Tools, Export and Import pages if API keys are present.
146 + if ( dfrapi_datafeedr_api_keys_exist() ) {
147 + new Dfrapi_Tools();
148 + new Dfrapi_Export();
149 + new Dfrapi_Import();
150 + new Dfrapi_Account();
191 151 }
192 - delete_option( 'dfrapi_admin_notices' );
193 152 }
194 - }
195 153
196 - function plugin_row_meta( $links, $plugin_file ) {
197 - if ( $plugin_file == DFRAPI_BASENAME ) {
198 - /* $links[] = sprintf( '<a href="' . admin_url( 'plugin-install.php?tab=search&type=tag&s=dfrapi' ) . '">%s</a>', __( 'Integration Plugins', DFRAPI_DOMAIN ) ); */
199 - $links[] = sprintf( '<a href="' . DFRAPI_HELP_URL . '">%s</a>', __( 'Support', DFRAPI_DOMAIN ) );
200 - return $links;
201 - }
202 - return $links;
203 154 }
204 155
205 - function action_links( $links ) {
206 - return array_merge(
207 - $links,
208 - array(
209 - 'config' => '<a href="' . admin_url( 'admin.php?page=dfrapi' ) . '">' . __( 'API Settings', DFRAPI_DOMAIN ) . '</a>',
210 - )
211 - );
212 - }
213 -
214 -}
215 -
216 -$dfrapi_initialize = new Dfrapi_Initialize();
156 + $dfrapi_initialize = new Dfrapi_Initialize();
217 157
218 158 } // class_exists check