| 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 |
add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 30 |
add_action( 'wp_ajax_search_form', array( $this, 'ajax_search_form' ) ); |
| 31 |
|
| 32 |
add_filter( 'plugin_action_links_' . DFRAPI_BASENAME, array( $this, 'action_links' ) ); |
| 33 |
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 ); |
| 34 |
|
| 35 |
do_action( 'dfrapi_loaded' ); |
| 36 |
|
| 37 |
} |
| 38 |
|
| 39 |
function ajax_search_form() { |
| 40 |
$sform = new Dfrapi_SearchForm(); |
| 41 |
echo $sform->ajaxHandler(); |
| 42 |
die; |
| 43 |
} |
| 44 |
|
| 45 |
function admin_menu() { |
| 46 |
add_menu_page( |
| 47 |
__( 'Datafeedr API', DFRAPI_DOMAIN ), |
| 48 |
__( 'Datafeedr API', DFRAPI_DOMAIN ), |
| 49 |
'manage_options', |
| 50 |
'dfrapi', |
| 51 |
'', |
| 52 |
null, |
| 53 |
42 |
| 54 |
); |
| 55 |
} |
| 56 |
|
| 57 |
function initialize_classes() { |
| 58 |
|
| 59 |
new Dfrapi_Configuration(); |
| 60 |
|
| 61 |
// Show "Networks" page if API keys are present. |
| 62 |
if ( Dfrapi_Env::api_keys_exist() ) { |
| 63 |
new Dfrapi_Networks(); |
| 64 |
} |
| 65 |
|
| 66 |
// Show "Merchants" page if API keys are present AND a network is selected. |
| 67 |
if ( Dfrapi_Env::api_keys_exist() && Dfrapi_Env::network_is_selected() ) { |
| 68 |
new Dfrapi_Merchants(); |
| 69 |
} |
| 70 |
|
| 71 |
// Show Tools, Export and Import pages if API keys are present. |
| 72 |
if ( Dfrapi_Env::api_keys_exist() ) { |
| 73 |
new Dfrapi_Tools(); |
| 74 |
new Dfrapi_Export(); |
| 75 |
new Dfrapi_Import(); |
| 76 |
new Dfrapi_Account(); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
function load_css() { |
| 81 |
|
| 82 |
// Basic styling for API pages. |
| 83 |
wp_register_style( 'dfrapi_css', DFRAPI_URL . 'css/style.css', false, DFRAPI_VERSION ); |
| 84 |
wp_enqueue_style( 'dfrapi_css' ); |
| 85 |
|
| 86 |
// Basic styling for API pages. |
| 87 |
wp_register_style( 'dfrapi_searchform', DFRAPI_URL . 'css/searchform.css', false, DFRAPI_VERSION ); |
| 88 |
wp_enqueue_style( 'dfrapi_searchform' ); |
| 89 |
} |
| 90 |
|
| 91 |
function load_js() { |
| 92 |
|
| 93 |
wp_register_script( 'dfrapi_general_js', DFRAPI_URL.'js/general.js', array( 'jquery' ), DFRAPI_VERSION, true ); |
| 94 |
wp_enqueue_script( 'dfrapi_general_js' ); |
| 95 |
|
| 96 |
wp_register_script( 'dfrapi_searchfilter_js', DFRAPI_URL.'js/searchfilter.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 97 |
wp_enqueue_script( 'dfrapi_searchfilter_js' ); |
| 98 |
|
| 99 |
wp_register_script( 'dfrapi_merchants_js', DFRAPI_URL.'js/merchants.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 100 |
wp_enqueue_script( 'dfrapi_merchants_js' ); |
| 101 |
|
| 102 |
wp_register_script( 'dfrapi_searchform_js', DFRAPI_URL.'js/searchform.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 103 |
wp_enqueue_script( 'dfrapi_searchform_js' ); |
| 104 |
|
| 105 |
wp_register_script( 'dfrapi_jquery_reveal_js', DFRAPI_URL.'js/jquery.reveal.js', array( 'jquery' ), DFRAPI_VERSION, false ); |
| 106 |
wp_enqueue_script( 'dfrapi_jquery_reveal_js' ); |
| 107 |
} |
| 108 |
|
| 109 |
function admin_notices() { |
| 110 |
$dfrapi_env = new Dfrapi_Env(); |
| 111 |
if ( $notices = get_option( 'dfrapi_admin_notices' ) ) { |
| 112 |
foreach ( $notices as $key => $message ) { |
| 113 |
$button = ( $message['url'] != '' ) ? dfrapi_fix_button( $message['url'], $message['button_text'] ) : ''; |
| 114 |
$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>' : ''; |
| 115 |
echo '<div class="'.$message['class'].'"><p>'.$message['message'].$button.$upgrade_account.'</p></div>'; |
| 116 |
} |
| 117 |
delete_option( 'dfrapi_admin_notices' ); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
function plugin_row_meta( $links, $plugin_file ) { |
| 122 |
if ( $plugin_file == DFRAPI_BASENAME ) { |
| 123 |
/* $links[] = sprintf( '<a href="' . admin_url( 'plugin-install.php?tab=search&type=tag&s=dfrapi' ) . '">%s</a>', __( 'Integration Plugins', DFRAPI_DOMAIN ) ); */ |
| 124 |
$links[] = sprintf( '<a href="' . DFRAPI_HELP_URL . '">%s</a>', __( 'Support', DFRAPI_DOMAIN ) ); |
| 125 |
return $links; |
| 126 |
} |
| 127 |
return $links; |
| 128 |
} |
| 129 |
|
| 130 |
function action_links( $links ) { |
| 131 |
return array_merge( |
| 132 |
$links, |
| 133 |
array( |
| 134 |
'config' => '<a href="' . admin_url( 'admin.php?page=dfrapi' ) . '">' . __( 'API Settings', DFRAPI_DOMAIN ) . '</a>', |
| 135 |
) |
| 136 |
); |
| 137 |
} |
| 138 |
|
| 139 |
} |
| 140 |
|
| 141 |
$dfrapi_initialize = new Dfrapi_Initialize(); |
| 142 |
|
| 143 |
} // class_exists check |
| 144 |
|