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
datafeedr-api / classes / class-dfrapi-initialize.php

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

159 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 defined( 'ABSPATH' ) || exit;
4
5 if ( ! class_exists( 'Dfrapi_Initialize' ) ) {
6
7 class Dfrapi_Initialize {
8
9 public function __construct() {
10
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' ] );
17
18 // Datafeedr Admin Pages have been loaded. Broadcast "loaded" action.
19 do_action( 'dfrapi_loaded' );
20 }
21
22 function ajax_search_form() {
23
24 check_ajax_referer( 'dfrapi_search_form', 'dfrapi_security' );
25
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' );
34
35 if ( ! current_user_can( $capability ) ) {
36 wp_die( -1, 403 );
37 }
38
39 $sform = new Dfrapi_SearchForm();
40 echo $sform->ajaxHandler();
41 die;
42 }
43
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 }
55
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 );
66 }
67 }
68
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>';
85 }
86
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 );
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', 'datafeedr-api' ) . '</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_datafeedr_api_keys_exist() ) {
123
124 if ( isset( $_GET['page'] ) && 'dfrapi_networks' === $_GET['page'] && is_admin() ) {
125 new Dfrapi_Networks();
126 }
127
128 if ( isset( $_POST['option_page'] ) && ( 'dfrapi-networks' === $_POST['option_page'] ) && is_admin() ) {
129 new Dfrapi_Networks();
130 }
131 }
132
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() ) {
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_datafeedr_api_keys_exist() ) {
147 new Dfrapi_Tools();
148 new Dfrapi_Export();
149 new Dfrapi_Import();
150 new Dfrapi_Account();
151 }
152 }
153
154 }
155
156 $dfrapi_initialize = new Dfrapi_Initialize();
157
158 } // class_exists check
159