Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/wordfenc.../lib
File: wfOnboardingController.php
<?php
[0] Fix | Delete
[1] Fix | Delete
class wfOnboardingController {
[2] Fix | Delete
const ONBOARDING_EMAILS = 'emails'; //New install, part 1 completed
[3] Fix | Delete
const ONBOARDING_LICENSE = 'license'; //New install, part 2 completed
[4] Fix | Delete
const ONBOARDING_SKIPPED = 'skipped'; //New install, onboarding attempt was skipped
[5] Fix | Delete
[6] Fix | Delete
const TOUR_DASHBOARD = 'dashboard';
[7] Fix | Delete
const TOUR_FIREWALL = 'firewall';
[8] Fix | Delete
const TOUR_SCAN = 'scan';
[9] Fix | Delete
const TOUR_BLOCKING = 'blocking';
[10] Fix | Delete
const TOUR_LIVE_TRAFFIC = 'livetraffic';
[11] Fix | Delete
const TOUR_LOGIN_SECURITY = 'loginsecurity';
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* Sets the appropriate initial settings for an existing install so it's not forced through onboarding.
[15] Fix | Delete
*/
[16] Fix | Delete
public static function migrateOnboarding() {
[17] Fix | Delete
$alertEmails = wfConfig::getAlertEmails();
[18] Fix | Delete
$onboardingAttempt1 = wfConfig::get('onboardingAttempt1');
[19] Fix | Delete
if (!empty($alertEmails) && empty($onboardingAttempt1)) {
[20] Fix | Delete
wfConfig::set('onboardingAttempt1', self::ONBOARDING_LICENSE); //Mark onboarding as done
[21] Fix | Delete
[22] Fix | Delete
$keys = array(self::TOUR_DASHBOARD, self::TOUR_FIREWALL, self::TOUR_SCAN, self::TOUR_BLOCKING, self::TOUR_LIVE_TRAFFIC);
[23] Fix | Delete
foreach ($keys as $k) {
[24] Fix | Delete
wfConfig::set('needsNewTour_' . $k, 0);
[25] Fix | Delete
wfConfig::set('needsUpgradeTour_' . $k, 1);
[26] Fix | Delete
}
[27] Fix | Delete
}
[28] Fix | Delete
}
[29] Fix | Delete
[30] Fix | Delete
/**
[31] Fix | Delete
* Initializes the onboarding hooks.
[32] Fix | Delete
*
[33] Fix | Delete
* Only called if (is_admin() && wfUtils::isAdmin()) is true.
[34] Fix | Delete
*/
[35] Fix | Delete
public static function initialize() {
[36] Fix | Delete
$willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) ||
[37] Fix | Delete
self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) ||
[38] Fix | Delete
self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) ||
[39] Fix | Delete
self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) ||
[40] Fix | Delete
self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) ||
[41] Fix | Delete
self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY));
[42] Fix | Delete
if (!self::shouldShowAnyAttempt() && !$willShowAnyTour) {
[43] Fix | Delete
return;
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
add_action('in_admin_header', 'wfOnboardingController::_admin_header'); //Called immediately after <div id="wpcontent">
[47] Fix | Delete
add_action('pre_current_active_plugins', 'wfOnboardingController::_pre_plugins'); //Called immediately after <hr class="wp-header-end">
[48] Fix | Delete
add_action('admin_enqueue_scripts', 'wfOnboardingController::_enqueue_scripts');
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Enqueues the scripts and styles we need globally on the backend for onboarding.
[53] Fix | Delete
*/
[54] Fix | Delete
public static function _enqueue_scripts() {
[55] Fix | Delete
$willShowAnyPluginOnboarding = (self::shouldShowAttempt1() || self::shouldShowAttempt2());
[56] Fix | Delete
$willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) ||
[57] Fix | Delete
self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) ||
[58] Fix | Delete
self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) ||
[59] Fix | Delete
self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) ||
[60] Fix | Delete
self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) ||
[61] Fix | Delete
self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY));
[62] Fix | Delete
[63] Fix | Delete
if (wfUtils::isAdmin() &&
[64] Fix | Delete
(($willShowAnyPluginOnboarding && preg_match('~(?:^|/)wp-admin(?:/network)?/plugins\.php~i', $_SERVER['REQUEST_URI'])) ||
[65] Fix | Delete
(isset($_GET['page']) &&
[66] Fix | Delete
(preg_match('/^Wordfence/', @$_GET['page']) || preg_match('/^WFLS/', @$_GET['page']))
[67] Fix | Delete
)
[68] Fix | Delete
)
[69] Fix | Delete
) {
[70] Fix | Delete
self::enqueue_assets();
[71] Fix | Delete
}
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
public static function enqueue_assets() {
[75] Fix | Delete
wp_enqueue_style('wordfence-font', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-roboto-font.css'), '', WORDFENCE_VERSION);
[76] Fix | Delete
wp_enqueue_style('wordfence-ionicons-style', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-ionicons.css'), '', WORDFENCE_VERSION);
[77] Fix | Delete
wp_enqueue_style('wordfenceOnboardingCSS', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-onboarding.css'), '', WORDFENCE_VERSION);
[78] Fix | Delete
wp_enqueue_style('wordfence-colorbox-style', wfUtils::getBaseURL() . wfUtils::versionedAsset('css/wf-colorbox.css'), '', WORDFENCE_VERSION);
[79] Fix | Delete
wp_enqueue_script('jquery.wfcolorbox', wfUtils::getBaseURL() . wfUtils::versionedAsset('js/jquery.colorbox-min.js'), array('jquery'), WORDFENCE_VERSION);
[80] Fix | Delete
}
[81] Fix | Delete
[82] Fix | Delete
/**
[83] Fix | Delete
* Outputs the onboarding overlay if it needs to be shown on the plugins page.
[84] Fix | Delete
*/
[85] Fix | Delete
public static function _admin_header() {
[86] Fix | Delete
$willShowAnyTour = (self::shouldShowNewTour(self::TOUR_DASHBOARD) || self::shouldShowUpgradeTour(self::TOUR_DASHBOARD) ||
[87] Fix | Delete
self::shouldShowNewTour(self::TOUR_FIREWALL) || self::shouldShowUpgradeTour(self::TOUR_FIREWALL) ||
[88] Fix | Delete
self::shouldShowNewTour(self::TOUR_SCAN) || self::shouldShowUpgradeTour(self::TOUR_SCAN) ||
[89] Fix | Delete
self::shouldShowNewTour(self::TOUR_BLOCKING) || self::shouldShowUpgradeTour(self::TOUR_BLOCKING) ||
[90] Fix | Delete
self::shouldShowNewTour(self::TOUR_LIVE_TRAFFIC) || self::shouldShowUpgradeTour(self::TOUR_LIVE_TRAFFIC) ||
[91] Fix | Delete
self::shouldShowNewTour(self::TOUR_LOGIN_SECURITY) || self::shouldShowUpgradeTour(self::TOUR_LOGIN_SECURITY));
[92] Fix | Delete
[93] Fix | Delete
$screen = get_current_screen();
[94] Fix | Delete
if ($screen->base == 'plugins' && self::shouldShowAttempt1()) {
[95] Fix | Delete
register_shutdown_function('wfOnboardingController::_markAttempt1Shown');
[96] Fix | Delete
$freshInstall = wfView::create('onboarding/fresh-install')->render();
[97] Fix | Delete
[98] Fix | Delete
echo wfView::create('onboarding/overlay', array(
[99] Fix | Delete
'contentHTML' => $freshInstall,
[100] Fix | Delete
))->render();
[101] Fix | Delete
}
[102] Fix | Delete
else if (preg_match('/wordfence/i', $screen->base) && $willShowAnyTour) {
[103] Fix | Delete
echo wfView::create('onboarding/tour-overlay')->render();
[104] Fix | Delete
}
[105] Fix | Delete
}
[106] Fix | Delete
[107] Fix | Delete
public static function _markAttempt1Shown() {
[108] Fix | Delete
wfConfig::set('onboardingAttempt1', self::ONBOARDING_SKIPPED); //Only show it once, default to skipped after outputting the first time
[109] Fix | Delete
}
[110] Fix | Delete
[111] Fix | Delete
public static function shouldShowAttempt1() { //Overlay on plugin page
[112] Fix | Delete
if (wfConfig::get('onboardingAttempt3') == self::ONBOARDING_LICENSE) {
[113] Fix | Delete
return false;
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
switch (wfConfig::get('onboardingAttempt1')) {
[117] Fix | Delete
case self::ONBOARDING_LICENSE:
[118] Fix | Delete
case self::ONBOARDING_SKIPPED:
[119] Fix | Delete
return false;
[120] Fix | Delete
}
[121] Fix | Delete
return true;
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
public static function _pre_plugins() {
[125] Fix | Delete
if (self::shouldShowAttempt2()) {
[126] Fix | Delete
echo wfView::create('onboarding/plugin-header')->render();
[127] Fix | Delete
}
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
private static function needsApiKey() {
[131] Fix | Delete
$key = wfConfig::get('apiKey');
[132] Fix | Delete
return empty($key);
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
public static function shouldShowAttempt2() { //Header on plugin page
[136] Fix | Delete
if (wfConfig::get('onboardingAttempt3') == self::ONBOARDING_LICENSE) {
[137] Fix | Delete
return false;
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
return !wfConfig::get('onboardingAttempt2') && self::needsApiKey();
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
public static function shouldShowAttempt3($dismissable = false) {
[144] Fix | Delete
if (self::needsApiKey()) {
[145] Fix | Delete
if (!$dismissable)
[146] Fix | Delete
return true;
[147] Fix | Delete
$delayedAt = (int) wfConfig::get('onboardingDelayedAt', 0);
[148] Fix | Delete
if (time() - $delayedAt > 43200 /*12 hours in seconds*/)
[149] Fix | Delete
return true;
[150] Fix | Delete
}
[151] Fix | Delete
return false;
[152] Fix | Delete
}
[153] Fix | Delete
[154] Fix | Delete
/**
[155] Fix | Delete
* Whether or not to pop up attempt 3 at page load or wait for user interaction.
[156] Fix | Delete
*
[157] Fix | Delete
* @return bool
[158] Fix | Delete
*/
[159] Fix | Delete
public static function shouldShowAttempt3Automatically() {
[160] Fix | Delete
static $_shouldShowAttempt3Automatically = null;
[161] Fix | Delete
if ($_shouldShowAttempt3Automatically !== null) { //We cache this so the answer remains the same for the whole request
[162] Fix | Delete
return $_shouldShowAttempt3Automatically;
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
if (!self::shouldShowAttempt3()) {
[166] Fix | Delete
$_shouldShowAttempt3Automatically = false;
[167] Fix | Delete
return false;
[168] Fix | Delete
}
[169] Fix | Delete
[170] Fix | Delete
return $_shouldShowAttempt3Automatically = self::shouldShowAttempt3();
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
public static function willShowNewTour($page) {
[174] Fix | Delete
$key = 'needsNewTour_' . $page;
[175] Fix | Delete
return wfConfig::get($key);
[176] Fix | Delete
}
[177] Fix | Delete
[178] Fix | Delete
public static function shouldShowNewTour($page) {
[179] Fix | Delete
$key = 'needsNewTour_' . $page;
[180] Fix | Delete
return (!self::shouldShowAttempt3Automatically() && !wfConfig::get('touppPromptNeeded') && wfConfig::get($key));
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
public static function willShowUpgradeTour($page) {
[184] Fix | Delete
$key = 'needsUpgradeTour_' . $page;
[185] Fix | Delete
return wfConfig::get($key);
[186] Fix | Delete
}
[187] Fix | Delete
[188] Fix | Delete
public static function shouldShowUpgradeTour($page) {
[189] Fix | Delete
$key = 'needsUpgradeTour_' . $page;
[190] Fix | Delete
return (!self::shouldShowAttempt3Automatically() && !wfConfig::get('touppPromptNeeded') && wfConfig::get($key));
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
public static function shouldShowAnyAttempt() {
[194] Fix | Delete
return self::shouldShowAttempt1() || self::shouldShowAttempt2() || self::shouldShowAttempt3();
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
}
[198] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function