| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('WEBTOTEM_INIT') || WEBTOTEM_INIT !== true) { |
| 4 |
if (!headers_sent()) { |
| 5 |
header('HTTP/1.1 403 Forbidden'); |
| 6 |
} |
| 7 |
die("Protected By WebTotem!"); |
| 8 |
} |
| 9 |
|
| 10 |
if (defined('WEBTOTEM')) { |
| 11 |
|
| 12 |
/** |
| 13 |
* Remove the WordPress generator meta-tag from the source code. |
| 14 |
*/ |
| 15 |
remove_action('wp_head', 'wp_generator'); |
| 16 |
|
| 17 |
/** |
| 18 |
* Define which javascript and css files will be loaded in the header of the |
| 19 |
* plugin pages. |
| 20 |
*/ |
| 21 |
add_action('admin_enqueue_scripts', 'WebTotemInterface::enqueueScripts', 1); |
| 22 |
|
| 23 |
/** Login Page */ |
| 24 |
add_action('login_enqueue_scripts', 'WebTotemInterface::loginEnqueueScripts'); |
| 25 |
|
| 26 |
/** Add authenticate filter */ |
| 27 |
add_filter('authenticate', 'WebTotemInterface::wt_authenticate', 25, 3); |
| 28 |
|
| 29 |
/** Add lostpassword filter */ |
| 30 |
add_action('lostpassword_errors', 'WebTotemInterface::wt_lost_password', 1, 2); |
| 31 |
|
| 32 |
/** Execute pre-checks before every page */ |
| 33 |
add_action('init', 'WebTotemInterface::startupChecks'); //wp_loaded |
| 34 |
|
| 35 |
/** Add site or new sites if it is multisite */ |
| 36 |
add_action( 'wp_insert_site', 'WebTotemInterface::addNewSite' ); |
| 37 |
|
| 38 |
/** Attach HTTP request handlers for the AJAX requests */ |
| 39 |
add_action('wp_ajax_nopriv_wtotem_ajax', 'wtotem_public_ajax_callback'); |
| 40 |
add_action('wp_ajax_wtotem_ajax', 'wtotem_ajax_callback'); |
| 41 |
|
| 42 |
/** Hide or show WP version */ |
| 43 |
if (WebTotemOption::getPluginSettings('hide_wp_version')) { |
| 44 |
add_filter('update_feedback', 'WebTotemInterface::restoreReadmeWhenUpdating'); |
| 45 |
} |
| 46 |
|
| 47 |
/** Define role of current user */ |
| 48 |
//add_action('init', 'WebTotem::getUserRole'); |
| 49 |
|
| 50 |
/** */ |
| 51 |
add_action( 'wp', 'webtotem_add_cron' ); |
| 52 |
add_action( 'webtotem_daily_cron', 'dailyCron' ); |
| 53 |
|
| 54 |
function webtotem_add_cron() { |
| 55 |
if( ! wp_next_scheduled( 'webtotem_daily_cron' ) ) { |
| 56 |
wp_schedule_event( time(), 'daily', 'webtotem_daily_cron' ); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/** |
| 61 |
* List an associative array with the sub-pages of this plugin. |
| 62 |
* |
| 63 |
* @return array List of sub-pages of this plugin. |
| 64 |
*/ |
| 65 |
function wtotemPages() { |
| 66 |
if( WebTotem::isMultiSite() ) { |
| 67 |
$pages['wtotem_all_sites'] = [ 'title' => __('All sites', 'wtotem'), 'slug' => 'wtotem']; |
| 68 |
} |
| 69 |
$slug = WebTotem::isMultiSite() ? 'wtotem_' : 'wtotem'; |
| 70 |
|
| 71 |
$pages['wtotem_dashboard'] = [ 'title' => __('Dashboard', 'wtotem'), 'slug' => $slug]; |
| 72 |
$pages['wtotem_firewall'] = [ 'title' => __('Firewall', 'wtotem'), 'slug' => $slug]; |
| 73 |
if(!WebTotem::isMultiSite() or is_super_admin()) { |
| 74 |
$pages['wtotem_antivirus'] = [ 'title' => __('Antivirus', 'wtotem'), 'slug' => $slug]; |
| 75 |
$pages['wtotem_settings'] = [ 'title' => __('Settings', 'wtotem'), 'slug' => $slug]; |
| 76 |
} |
| 77 |
$pages['wtotem_reports'] = [ 'title' => __('Reports', 'wtotem'), 'slug' => $slug]; |
| 78 |
$pages['wtotem_documentation'] = [ 'title' => __('Documentation', 'wtotem'), 'slug' => 'wtotem']; |
| 79 |
|
| 80 |
return $pages; |
| 81 |
} |
| 82 |
|
| 83 |
if (function_exists('add_action')) { |
| 84 |
/** |
| 85 |
* Display extension menu and submenu items in the correct interface. |
| 86 |
* |
| 87 |
* @return void |
| 88 |
*/ |
| 89 |
function wtotemAddMenu() { |
| 90 |
|
| 91 |
$page = ! WebTotemOption::isActivated() ? 'activation' : ( WebTotem::isMultiSite() ? 'all_sites' : 'dashboard' ); |
| 92 |
|
| 93 |
add_menu_page( |
| 94 |
__('WebTotem Security', 'wtotem'), |
| 95 |
__('WebTotem Security', 'wtotem'), |
| 96 |
'manage_options', |
| 97 |
'wtotem', |
| 98 |
'wtotem_' . $page . '_page', |
| 99 |
WebTotem::getImagePath('logo_17x17_w.png') |
| 100 |
); |
| 101 |
|
| 102 |
if(WebTotemOption::isActivated()){ |
| 103 |
$pages = wtotemPages(); |
| 104 |
foreach ($pages as $sub_page_function => $sub_page) { |
| 105 |
add_submenu_page( |
| 106 |
$sub_page['slug'], |
| 107 |
$sub_page['title'], |
| 108 |
$sub_page['title'], |
| 109 |
'manage_options', |
| 110 |
$sub_page_function, |
| 111 |
$sub_page_function . '_page' |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
} else { |
| 116 |
add_submenu_page( |
| 117 |
'wtotem', |
| 118 |
__('Activation', 'wtotem'), |
| 119 |
__('Activation', 'wtotem'), |
| 120 |
'manage_options', |
| 121 |
'wtotem_activation', |
| 122 |
'wtotem_activation_page' |
| 123 |
); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
/* Attach HTTP request handlers for the internal plugin pages */ |
| 128 |
if(WebTotem::isMultiSite()){ |
| 129 |
add_action('network_admin_menu', 'wtotemAddMenu'); |
| 130 |
} |
| 131 |
add_action('admin_menu', 'wtotemAddMenu'); |
| 132 |
|
| 133 |
|
| 134 |
} |
| 135 |
|
| 136 |
} |
| 137 |
|