PluginProbe
Datafeedr API / 1.1.2
Datafeedr API v1.1.2
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-initialize.php

class-dfrapi-initialize.php in Datafeedr API 1.1.2, at classes/class-dfrapi-initialize.php

219 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
3 if ( ! class_exists( 'Dfrapi_Initialize' ) ) {
4
5
6 class Dfrapi_Initialize {
7
8 public function __construct() {
9
10 // Core admin functions.
11 require_once( DFRAPI_PATH . 'functions/admin-functions.php' );
12
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.
23
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' ) );
29
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 );
33
34 add_action( 'wp_ajax_search_form', array( $this, 'ajax_search_form' ) );
35
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 );
38
39 do_action( 'dfrapi_loaded' );
40
41 }
42
43 function ajax_search_form() {
44 $sform = new Dfrapi_SearchForm();
45 echo $sform->ajaxHandler();
46 die;
47 }
48
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();
127 }
128
129 if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-networks' == $_POST['option_page'] ) ) {
130 new Dfrapi_Networks();
131 }
132 }
133
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();
139 }
140
141 if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' == $_POST['option_page'] ) ) {
142 new Dfrapi_Merchants();
143 }
144 }
145
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();
152 }
153 }
154
155 function load_css() {
156
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' );
160
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 }
165
166 function load_js() {
167
168 wp_register_script( 'dfrapi_general_js', DFRAPI_URL.'js/general.js', array( 'jquery' ), DFRAPI_VERSION, true );
169 wp_enqueue_script( 'dfrapi_general_js' );
170
171 wp_register_script( 'dfrapi_searchfilter_js', DFRAPI_URL.'js/searchfilter.js', array( 'jquery' ), DFRAPI_VERSION, false );
172 wp_enqueue_script( 'dfrapi_searchfilter_js' );
173
174 wp_register_script( 'dfrapi_merchants_js', DFRAPI_URL.'js/merchants.js', array( 'jquery' ), DFRAPI_VERSION, false );
175 wp_enqueue_script( 'dfrapi_merchants_js' );
176
177 wp_register_script( 'dfrapi_searchform_js', DFRAPI_URL.'js/searchform.js', array( 'jquery' ), DFRAPI_VERSION, false );
178 wp_enqueue_script( 'dfrapi_searchform_js' );
179
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>';
191 }
192 delete_option( 'dfrapi_admin_notices' );
193 }
194 }
195
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 }
204
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();
217
218 } // class_exists check
219