| @@ -7,10 +7,10 @@ | ||
| 7 | 7 | |
| 8 | 8 | public function __construct() { |
| 9 | 9 | |
| 10 | 10 | // Core admin functions. |
| 11 | - require_once( DFRAPI_PATH . 'functions/admin-functions.php' ); | |
| 12 | - | |
| 11 | + require_once( DFRAPI_PATH . 'functions/admin-functions.php' ); | |
| 12 | + | |
| 13 | 13 | // Load required classes. |
| 14 | 14 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-env.php' ); // Checks environment for any problems. |
| 15 | 15 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-configuration.php' ); // Configuration page. |
| 16 | 16 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-networks.php' ); // Networks page. |
| @@ -19,15 +19,19 @@ | ||
| 19 | 19 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-export.php' ); // Export page. |
| 20 | 20 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-import.php' ); // Import page. |
| 21 | 21 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-account.php' ); // Account page. |
| 22 | 22 | require_once( DFRAPI_PATH . 'classes/class-dfrapi-help.php' ); // Help tabs. |
| 23 | - | |
| 23 | + | |
| 24 | 24 | // Hooks |
| 25 | 25 | add_action( 'admin_enqueue_scripts', array( $this, 'load_css' ) ); |
| 26 | 26 | add_action( 'admin_enqueue_scripts', array( $this, 'load_js' ) ); |
| 27 | 27 | add_action( 'plugins_loaded', array( $this, 'initialize_classes' ) ); |
| 28 | 28 | add_action( 'admin_notices', array( $this, 'admin_notices' ) ); |
| 29 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); | |
| 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 | + | |
| 30 | 34 | add_action( 'wp_ajax_search_form', array( $this, 'ajax_search_form' ) ); |
| 31 | 35 | |
| 32 | 36 | add_filter( 'plugin_action_links_' . DFRAPI_BASENAME, array( $this, 'action_links' ) ); |
| 33 | 37 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| @@ -32,9 +36,9 @@ | ||
| 32 | 36 | add_filter( 'plugin_action_links_' . DFRAPI_BASENAME, array( $this, 'action_links' ) ); |
| 33 | 37 | add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| 34 | 38 | |
| 35 | 39 | do_action( 'dfrapi_loaded' ); |
| 36 | - | |
| 40 | + | |
| 37 | 41 | } |
| 38 | 42 | |
| 39 | 43 | function ajax_search_form() { |
| 40 | 44 | $sform = new Dfrapi_SearchForm(); |
| @@ -41,34 +45,105 @@ | ||
| 41 | 45 | echo $sform->ajaxHandler(); |
| 42 | 46 | die; |
| 43 | 47 | } |
| 44 | 48 | |
| 45 | - function admin_menu() { | |
| 46 | - add_menu_page( | |
| 47 | - __( 'Datafeedr API', DFRAPI_DOMAIN ), | |
| 48 | - __( 'Datafeedr API', DFRAPI_DOMAIN ), | |
| 49 | - 'manage_options', | |
| 49 | + function admin_menu() { | |
| 50 | + add_menu_page( | |
| 51 | + __( 'Datafeedr API', DFRAPI_DOMAIN ), | |
| 52 | + __( 'Datafeedr API', DFRAPI_DOMAIN ), | |
| 53 | + 'manage_options', | |
| 50 | 54 | 'dfrapi', |
| 51 | - '', | |
| 52 | - null, | |
| 53 | - 42 | |
| 55 | + '', | |
| 56 | + null, | |
| 57 | + 42 | |
| 54 | 58 | ); |
| 55 | 59 | } |
| 56 | - | |
| 60 | + | |
| 61 | + function networks_menu() { | |
| 62 | + add_submenu_page( | |
| 63 | + 'dfrapi', | |
| 64 | + __( 'Networks — 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 ) . ' — 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 — 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 ) . ' — 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 | + | |
| 57 | 118 | function initialize_classes() { |
| 58 | - | |
| 119 | + | |
| 59 | 120 | new Dfrapi_Configuration(); |
| 60 | - | |
| 121 | + | |
| 61 | 122 | // Show "Networks" page if API keys are present. |
| 62 | 123 | if ( Dfrapi_Env::api_keys_exist() ) { |
| 63 | - new Dfrapi_Networks(); | |
| 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 | + } | |
| 64 | 132 | } |
| 65 | - | |
| 133 | + | |
| 66 | 134 | // Show "Merchants" page if API keys are present AND a network is selected. |
| 67 | 135 | if ( Dfrapi_Env::api_keys_exist() && Dfrapi_Env::network_is_selected() ) { |
| 68 | - new Dfrapi_Merchants(); | |
| 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 | + } | |
| 69 | 144 | } |
| 70 | - | |
| 145 | + | |
| 71 | 146 | // Show Tools, Export and Import pages if API keys are present. |
| 72 | 147 | if ( Dfrapi_Env::api_keys_exist() ) { |
| 73 | 148 | new Dfrapi_Tools(); |
| 74 | 149 | new Dfrapi_Export(); |
| @@ -75,31 +150,31 @@ | ||
| 75 | 150 | new Dfrapi_Import(); |
| 76 | 151 | new Dfrapi_Account(); |
| 77 | 152 | } |
| 78 | 153 | } |
| 79 | - | |
| 154 | + | |
| 80 | 155 | function load_css() { |
| 81 | - | |
| 156 | + | |
| 82 | 157 | // Basic styling for API pages. |
| 83 | 158 | wp_register_style( 'dfrapi_css', DFRAPI_URL . 'css/style.css', false, DFRAPI_VERSION ); |
| 84 | 159 | wp_enqueue_style( 'dfrapi_css' ); |
| 85 | - | |
| 160 | + | |
| 86 | 161 | // Basic styling for API pages. |
| 87 | 162 | wp_register_style( 'dfrapi_searchform', DFRAPI_URL . 'css/searchform.css', false, DFRAPI_VERSION ); |
| 88 | 163 | wp_enqueue_style( 'dfrapi_searchform' ); |
| 89 | 164 | } |
| 90 | - | |
| 165 | + | |
| 91 | 166 | function load_js() { |
| 92 | - | |
| 167 | + | |
| 93 | 168 | wp_register_script( 'dfrapi_general_js', DFRAPI_URL.'js/general.js', array( 'jquery' ), DFRAPI_VERSION, true ); |
| 94 | 169 | wp_enqueue_script( 'dfrapi_general_js' ); |
| 95 | - | |
| 170 | + | |
| 96 | 171 | wp_register_script( 'dfrapi_searchfilter_js', DFRAPI_URL.'js/searchfilter.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 97 | 172 | wp_enqueue_script( 'dfrapi_searchfilter_js' ); |
| 98 | - | |
| 173 | + | |
| 99 | 174 | wp_register_script( 'dfrapi_merchants_js', DFRAPI_URL.'js/merchants.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 100 | 175 | wp_enqueue_script( 'dfrapi_merchants_js' ); |
| 101 | - | |
| 176 | + | |
| 102 | 177 | wp_register_script( 'dfrapi_searchform_js', DFRAPI_URL.'js/searchform.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 103 | 178 | wp_enqueue_script( 'dfrapi_searchform_js' ); |
| 104 | 179 | |
| 105 | 180 | wp_register_script( 'dfrapi_jquery_reveal_js', DFRAPI_URL.'js/jquery.reveal.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| @@ -116,9 +191,9 @@ | ||
| 116 | 191 | } |
| 117 | 192 | delete_option( 'dfrapi_admin_notices' ); |
| 118 | 193 | } |
| 119 | 194 | } |
| 120 | - | |
| 195 | + | |
| 121 | 196 | function plugin_row_meta( $links, $plugin_file ) { |
| 122 | 197 | if ( $plugin_file == DFRAPI_BASENAME ) { |
| 123 | 198 | /* $links[] = sprintf( '<a href="' . admin_url( 'plugin-install.php?tab=search&type=tag&s=dfrapi' ) . '">%s</a>', __( 'Integration Plugins', DFRAPI_DOMAIN ) ); */ |
| 124 | 199 | $links[] = sprintf( '<a href="' . DFRAPI_HELP_URL . '">%s</a>', __( 'Support', DFRAPI_DOMAIN ) ); |