PluginProbe
Datafeedr API / 1.0.74
Datafeedr API v1.0.74
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.0.74, at classes/class-dfrapi-initialize.php

218 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="' . admin_url( 'options.php' ) . '">';
78 wp_nonce_field( 'update-options' );
79 settings_fields( $page );
80 do_settings_sections( $page );
81 submit_button();
82 echo '</form>';
83 echo '<div id="dfr_unload_message" style="display:none">' .
84 __( 'You have unsaved changes', DFRAPI_DOMAIN ) .
85 '</div>';
86 echo '</div>';
87 }
88
89 function merchants_menu() {
90 add_submenu_page(
91 'dfrapi',
92 __( 'Merchants &#8212; Datafeedr API', DFRAPI_DOMAIN ),
93 __( 'Merchants', DFRAPI_DOMAIN ),
94 'manage_options',
95 'dfrapi_merchants',
96 array( $this, 'merchants_output' )
97 );
98 }
99
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', DFRAPI_DOMAIN ) . '</div>';
114 echo '</div>';
115 }
116
117 function initialize_classes() {
118
119 new Dfrapi_Configuration();
120
121 // Show "Networks" page if API keys are present.
122 if ( Dfrapi_Env::api_keys_exist() ) {
123
124 if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_networks' == $_GET['page'] ) {
125 new Dfrapi_Networks();
126 }
127
128 if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-networks' == $_POST['option_page'] ) ) {
129 new Dfrapi_Networks();
130 }
131 }
132
133 // Show "Merchants" page if API keys are present AND a network is selected.
134 if ( Dfrapi_Env::api_keys_exist() && Dfrapi_Env::network_is_selected() ) {
135
136 if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_merchants' == $_GET['page'] ) {
137 new Dfrapi_Merchants();
138 }
139
140 if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' == $_POST['option_page'] ) ) {
141 new Dfrapi_Merchants();
142 }
143 }
144
145 // Show Tools, Export and Import pages if API keys are present.
146 if ( Dfrapi_Env::api_keys_exist() ) {
147 new Dfrapi_Tools();
148 new Dfrapi_Export();
149 new Dfrapi_Import();
150 new Dfrapi_Account();
151 }
152 }
153
154 function load_css() {
155
156 // Basic styling for API pages.
157 wp_register_style( 'dfrapi_css', DFRAPI_URL . 'css/style.css', false, DFRAPI_VERSION );
158 wp_enqueue_style( 'dfrapi_css' );
159
160 // Basic styling for API pages.
161 wp_register_style( 'dfrapi_searchform', DFRAPI_URL . 'css/searchform.css', false, DFRAPI_VERSION );
162 wp_enqueue_style( 'dfrapi_searchform' );
163 }
164
165 function load_js() {
166
167 wp_register_script( 'dfrapi_general_js', DFRAPI_URL.'js/general.js', array( 'jquery' ), DFRAPI_VERSION, true );
168 wp_enqueue_script( 'dfrapi_general_js' );
169
170 wp_register_script( 'dfrapi_searchfilter_js', DFRAPI_URL.'js/searchfilter.js', array( 'jquery' ), DFRAPI_VERSION, false );
171 wp_enqueue_script( 'dfrapi_searchfilter_js' );
172
173 wp_register_script( 'dfrapi_merchants_js', DFRAPI_URL.'js/merchants.js', array( 'jquery' ), DFRAPI_VERSION, false );
174 wp_enqueue_script( 'dfrapi_merchants_js' );
175
176 wp_register_script( 'dfrapi_searchform_js', DFRAPI_URL.'js/searchform.js', array( 'jquery' ), DFRAPI_VERSION, false );
177 wp_enqueue_script( 'dfrapi_searchform_js' );
178
179 wp_register_script( 'dfrapi_jquery_reveal_js', DFRAPI_URL.'js/jquery.reveal.js', array( 'jquery' ), DFRAPI_VERSION, false );
180 wp_enqueue_script( 'dfrapi_jquery_reveal_js' );
181 }
182
183 function admin_notices() {
184 $dfrapi_env = new Dfrapi_Env();
185 if ( $notices = get_option( 'dfrapi_admin_notices' ) ) {
186 foreach ( $notices as $key => $message ) {
187 $button = ( $message['url'] != '' ) ? dfrapi_fix_button( $message['url'], $message['button_text'] ) : '';
188 $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>' : '';
189 echo '<div class="'.$message['class'].'"><p>'.$message['message'].$button.$upgrade_account.'</p></div>';
190 }
191 delete_option( 'dfrapi_admin_notices' );
192 }
193 }
194
195 function plugin_row_meta( $links, $plugin_file ) {
196 if ( $plugin_file == DFRAPI_BASENAME ) {
197 /* $links[] = sprintf( '<a href="' . admin_url( 'plugin-install.php?tab=search&type=tag&s=dfrapi' ) . '">%s</a>', __( 'Integration Plugins', DFRAPI_DOMAIN ) ); */
198 $links[] = sprintf( '<a href="' . DFRAPI_HELP_URL . '">%s</a>', __( 'Support', DFRAPI_DOMAIN ) );
199 return $links;
200 }
201 return $links;
202 }
203
204 function action_links( $links ) {
205 return array_merge(
206 $links,
207 array(
208 'config' => '<a href="' . admin_url( 'admin.php?page=dfrapi' ) . '">' . __( 'API Settings', DFRAPI_DOMAIN ) . '</a>',
209 )
210 );
211 }
212
213 }
214
215 $dfrapi_initialize = new Dfrapi_Initialize();
216
217 } // class_exists check
218