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

143 lines 3.9 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 $sform = new Dfrapi_SearchForm();
24 echo $sform->ajaxHandler();
25 die;
26 }
27
28 function admin_menu() {
29 add_menu_page(
30 __( 'Datafeedr API', 'datafeedr-api' ),
31 __( 'Datafeedr API', 'datafeedr-api' ),
32 'manage_options',
33 'dfrapi',
34 '',
35 null,
36 42
37 );
38 }
39
40 public function networks_menu() {
41 if ( dfrapi_datafeedr_api_keys_exist() ) {
42 add_submenu_page(
43 'dfrapi',
44 __( 'Networks &#8212; Datafeedr API', 'datafeedr-api' ),
45 __( 'Networks', 'datafeedr-api' ),
46 'manage_options',
47 'dfrapi_networks',
48 array( $this, 'networks_output' )
49 );
50 }
51 }
52
53 public function networks_output() {
54 $key = 'dfrapi_networks';
55 $page = 'dfrapi-networks';
56 echo '<div class="wrap" id="' . $key . '">';
57 echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
58 echo '<form method="post" action="options.php">';
59 submit_button();
60 wp_nonce_field( 'update-options' );
61 settings_fields( $page );
62 do_settings_sections( $page );
63 submit_button();
64 echo '</form>';
65 echo '<div id="dfr_unload_message" style="display:none">' .
66 __( 'You have unsaved changes', 'datafeedr-api' ) .
67 '</div>';
68 echo '</div>';
69 }
70
71 public function merchants_menu() {
72 if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_selected_network_count() > 0 ) {
73 add_submenu_page(
74 'dfrapi',
75 __( 'Merchants &#8212; Datafeedr API', 'datafeedr-api' ),
76 __( 'Merchants', 'datafeedr-api' ),
77 'manage_options',
78 'dfrapi_merchants',
79 array( $this, 'merchants_output' )
80 );
81 }
82 }
83
84 function merchants_output() {
85 $key = 'dfrapi_merchants';
86 $page = 'dfrapi-merchants';
87 echo '<div class="wrap" id="' . $key . '">';
88 echo '<h2>' . dfrapi_setting_pages( $page ) . ' &#8212; Datafeedr API</h2>';
89 echo '<form method="post" action="options.php">';
90 submit_button();
91 wp_nonce_field( 'update-options' );
92 settings_fields( $page );
93 do_settings_sections( $page );
94 submit_button();
95 echo '</form>';
96 echo '<div id="dfr_unload_message" style="display:none">' .
97 __( 'You have unsaved changes', 'datafeedr-api' ) . '</div>';
98 echo '</div>';
99 }
100
101 function initialize_classes() {
102
103 new Dfrapi_Configuration();
104
105 // Show "Networks" page if API keys are present.
106 if ( dfrapi_datafeedr_api_keys_exist() ) {
107
108 if ( isset( $_GET['page'] ) && 'dfrapi_networks' === $_GET['page'] && is_admin() ) {
109 new Dfrapi_Networks();
110 }
111
112 if ( isset( $_POST['option_page'] ) && ( 'dfrapi-networks' === $_POST['option_page'] ) && is_admin() ) {
113 new Dfrapi_Networks();
114 }
115 }
116
117 // Show "Merchants" page if API keys are present AND a network is selected.
118 if ( dfrapi_datafeedr_api_keys_exist() && dfrapi_user_has_selected_networks() ) {
119
120 if ( is_admin() && isset( $_GET['page'] ) && 'dfrapi_merchants' === $_GET['page'] ) {
121 new Dfrapi_Merchants();
122 }
123
124 if ( is_admin() && isset( $_POST['option_page'] ) && ( 'dfrapi-merchants' === $_POST['option_page'] ) ) {
125 new Dfrapi_Merchants();
126 }
127 }
128
129 // Show Tools, Export and Import pages if API keys are present.
130 if ( dfrapi_datafeedr_api_keys_exist() ) {
131 new Dfrapi_Tools();
132 new Dfrapi_Export();
133 new Dfrapi_Import();
134 new Dfrapi_Account();
135 }
136 }
137
138 }
139
140 $dfrapi_initialize = new Dfrapi_Initialize();
141
142 } // class_exists check
143