| Current Path : /home/flapst5/ekmtoronto.com/wp-content/plugins/wp-defender/src/ |
| Current File : /home/flapst5/ekmtoronto.com/wp-content/plugins/wp-defender/src/class-admin.php |
<?php
/**
* Handles WordPress admin page related tasks.
*
* @package WP_Defender
*/
namespace WP_Defender;
use WP_Defender\Component\Rate;
use WP_Defender\Behavior\WPMUDEV;
use WP_Defender\Component\Firewall;
use WP_Defender\Integrations\Dashboard_Whitelabel;
use WP_Defender\Component\Config\Config_Hub_Helper;
use WP_Defender\Helper\Analytics\Deactivation_Survey;
if ( ! defined( 'ABSPATH' ) ) {
die();
}
/**
* Handles WordPress admin page related tasks.
*
* @since 2.4
*/
class Admin {
/**
* Is the Free version?
*
* @var bool
*/
public $is_wp_org_version;
/**
* Constructor for the Admin class.
*/
public function __construct() {
$this->is_wp_org_version = defender_is_wp_org_version();
add_action( 'wp_ajax_defender_ip_detection_notice_dismiss', array( $this, 'dismiss_notice' ) );
add_action( 'wp_ajax_defender_ip_detection_switch_to_xff', array( $this, 'switch_to_xff' ) );
add_action( 'wp_ajax_defender_track_deactivate', array( $this, 'track_deactivate' ) );
add_action( 'admin_head', array( $this, 'add_global_styles' ) );
// Deactivation survey.
add_action( 'admin_footer-plugins.php', array( $this, 'load_deactivation_survey_modal' ) );
}
/**
* Add global styles.
*/
public function add_global_styles() {
echo '<style>
#toplevel_page_wp-defender ul.wp-submenu li a[href="admin.php?page=wdf-ip-lockout"] { display: flex; justify-content: space-between; align-items: center; }
#adminmenu li.wp-has-current-submenu a.wp-has-current-submenu { background-color: #4763E4 !important; }
#adminmenu .toplevel_page_wp-defender div.wp-menu-image.svg { width: 16px; height: 16px; margin-top: 10px; margin-left: 10px; background-size: 16px auto; }
</style>';
if ( ! $this->is_wp_org_version ) {
echo '<style>
#adminmenu .defender-admin-menu-pro-tag {
display: inline-block;
padding: 0;
color: inherit;
border: 1px solid currentColor;
border-radius: 9px;
line-height: 16px;
font-size: 11px;
height: 16px;
width: 28px;
text-align: center;
margin-left: 5px;
}
</style>';
}
}
/**
* Init admin actions.
*/
public function init() {
// Display plugin links.
add_filter( 'network_admin_plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) );
add_filter( 'plugin_action_links_' . DEFENDER_PLUGIN_BASENAME, array( $this, 'settings_link' ) );
add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 3 );
// Only for plugin pages and actions are only for wp.org members.
if ( $this->is_wp_org_version ) {
/**
* Action hook that fires after a scan issue is fixed.
*
* @since 4.4.0
*/
add_action(
'wpdef_fixed_scan_issue',
array( $this, 'after_scan_fix' ),
10
);
// For submenu callout.
add_action( 'admin_head', array( $this, 'retarget_submenu_callout' ) );
if ( ! wd_di()->get( WPMUDEV::class )->is_wpmu_hosting() ) {
$upsell_menu_title = sprintf(
'<span class="defender-upsell-label">%1$s<span class="defender-upsell-pro-tag">%2$s</span></span><svg class="defender-upsell-arrow" width="9" height="9" viewBox="0 0 9 9" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0.225625 8.7625C0.0881251 8.62917 0.013125 8.47083 0.000624999 8.2875C-0.00770833 8.10417 0.0672918 7.93125 0.225625 7.76875L5.86313 2.125L7.16313 0.93125C7.31313 0.789584 7.47146 0.722917 7.63812 0.73125C7.80479 0.739583 7.94854 0.804167 8.06938 0.925C8.19021 1.04583 8.25062 1.18958 8.25062 1.35625C8.25479 1.52292 8.18812 1.67708 8.05062 1.81875L6.85063 3.11875L1.21313 8.75C1.05896 8.90417 0.890209 8.97917 0.706875 8.975C0.527709 8.975 0.367292 8.90417 0.225625 8.7625ZM7.61938 4.4625L7.76312 1.24375L4.43188 1.3625H2.30687C2.11521 1.3625 1.94854 1.29792 1.80688 1.16875C1.66521 1.03542 1.59438 0.875 1.59438 0.6875C1.59438 0.5 1.66104 0.339584 1.79438 0.20625C1.93188 0.0687502 2.10688 0 2.31938 0H8.25688C8.48188 0 8.66104 0.0687502 8.79437 0.20625C8.92771 0.34375 8.99438 0.520834 8.99438 0.7375V6.66875C8.99438 6.87292 8.92563 7.04583 8.78813 7.1875C8.65063 7.325 8.48812 7.39375 8.30062 7.39375C8.10896 7.39375 7.94646 7.325 7.81313 7.1875C7.68396 7.04583 7.61938 6.87708 7.61938 6.68125V4.4625Z" fill="white"/></svg>',
esc_html__( 'Upgrade', 'wpdef' ),
esc_html__( 'Pro', 'wpdef' )
);
add_submenu_page(
'wp-defender',
esc_html__( 'Upgrade to Pro', 'wpdef' ),
$upsell_menu_title,
is_multisite() ? 'manage_network_options' : 'manage_options',
$this->get_link( 'upsell', 'defender_new-submenu_upsell' )
);
global $submenu;
if ( isset( $submenu['wp-defender'] ) && is_array( $submenu['wp-defender'] ) && array() !== $submenu['wp-defender'] ) {
$last = array_key_last( $submenu['wp-defender'] );
$submenu['wp-defender'][ $last ][4] = 'defender-menu-upsell'; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
}
}
}
// Display IP detection notice.
if ( is_multisite() ) {
add_action( 'network_admin_notices', array( $this, 'admin_notices' ) );
} else {
add_action( 'admin_notices', array( $this, 'admin_notices' ) );
}
}
/**
* Initialize the deactivation survey modal.
*/
public function init_deactivation_survey() {
global $pagenow;
if ( 'plugins.php' !== $pagenow ) {
return;
}
wp_enqueue_style( 'def-sui' );
wp_enqueue_style( 'def-admin' );
if ( ! wp_script_is( 'clipboard', 'enqueued' ) ) {
wp_enqueue_script( 'clipboard' );
}
wp_enqueue_script( 'wpmudev-sui' );
wp_enqueue_script( 'def-deactivation-survey' );
wp_enqueue_script( 'def-admin' );
}
/**
* Retrieves the display name of the plugin.
*
* @return string The display name of the plugin with a trailing hyphen.
*/
public function get_plugin_display_name(): string {
// Check if the plugin is the WordPress.org version (i.e., the free version) and set the label accordingly.
$plugin_label = $this->is_wp_org_version
? esc_html__( 'Defender', 'wpdef' )
: esc_html__( 'Defender Pro', 'wpdef' );
// Instantiate the Dashboard_Whitelabel class only if necessary.
$whitelabel = new Dashboard_Whitelabel();
// If whitelabeling is enabled and a custom name is provided, use it.
if ( $whitelabel->can_whitelabel() ) {
$custom_label = $whitelabel->get_plugin_name( Config_Hub_Helper::WDP_ID );
if ( is_string( $custom_label ) && '' !== trim( $custom_label ) ) {
$plugin_label = $custom_label;
}
}
// Return the final plugin label with the appended dash.
return $plugin_label . ' - ';
}
/**
* Generates the submenu callout for the WP Defender plugin.
*
* @return void
*/
public function retarget_submenu_callout(): void {
?>
<style>
#adminmenu .wp-submenu li.defender-menu-upsell > a,
#adminmenu .wp-submenu li.defender-menu-upsell > a:hover,
#adminmenu .wp-submenu li.defender-menu-upsell > a:active,
#adminmenu .wp-submenu li.defender-menu-upsell > a:focus {
display: flex;
align-items: center;
justify-content: space-between;
height: 32px;
padding: 7px 12px;
box-sizing: border-box;
background: #571EE7;
color: #ffffff;
font-size: 14px;
font-weight: 400;
line-height: 18px;
}
#adminmenu .wp-submenu li.defender-menu-upsell > a .defender-upsell-label {
display: inline-flex;
align-items: center;
}
#adminmenu .wp-submenu li.defender-menu-upsell > a .defender-upsell-pro-tag {
display: inline-flex;
align-items: center;
justify-content: center;
margin-left: 6px;
padding: 0 5px;
border: 1px solid #ffffff;
border-radius: 9px;
width: 30px;
height: 18px;
box-sizing: border-box;
font-family: 'Roboto', Arial, sans-serif;
font-size: 12px;
font-weight: 400;
line-height: 20px;
letter-spacing: 0.1px;
}
#adminmenu .wp-submenu li.defender-menu-upsell > a .defender-upsell-arrow {
margin-right: 4px;
}
#toplevel_page_wp-defender.wp-not-current-submenu .wp-submenu li.defender-menu-upsell > a,
#toplevel_page_wp-defender.wp-not-current-submenu .wp-submenu li.defender-menu-upsell > a:hover,
#toplevel_page_wp-defender.wp-not-current-submenu .wp-submenu li.defender-menu-upsell > a:active,
#toplevel_page_wp-defender.wp-not-current-submenu .wp-submenu li.defender-menu-upsell > a:focus {
margin-left: -4px;
}
</style>
<script type='text/javascript'>
jQuery(function ($) {
$('#adminmenu li.defender-menu-upsell > a').attr("target", "_blank");
});
</script>
<?php
}
/**
* Fired when the scan issue is fixed.
*
* @return void
*/
public function after_scan_fix(): void {
Rate::run_counter_of_fixed_scans();
}
/**
* Return URL link.
*
* @param string $link_for Accepts: 'docs', 'plugin', 'rate' and etc.
* @param string $campaign Utm campaign tag to be used in link. Default: ''.
* @param string $adv_path Advanced path. Default: ''.
* @param string $source UTM source. Default: 'defender'.
*
* @return string
*/
public function get_link( $link_for, $campaign = '', $adv_path = '', $source = 'defender' ): string {
$domain = 'https://wpmudev.com';
$wp_org = 'https://wordpress.org';
$utm_tags = "?utm_source={$source}&utm_medium=plugin&utm_campaign={$campaign}";
switch ( $link_for ) {
case 'docs':
$link = "{$domain}/docs/wpmu-dev-plugins/defender/{$utm_tags}";
break;
case 'plugin':
case 'upsell':
$link = "{$domain}/project/wp-defender/{$utm_tags}";
break;
case 'rate':
$link = "{$wp_org}/support/plugin/defender-security/reviews/#new-post";
break;
case 'support':
$link = $this->is_wp_org_version
? "{$wp_org}/support/plugin/defender-security/"
: "{$domain}/get-support/";
break;
case 'support_with_utm':
$link = "{$domain}/hub2/support/{$utm_tags}";
break;
case 'roadmap':
$link = "{$domain}/roadmap/";
break;
case 'pro_link':
$link = "{$domain}/$adv_path";
break;
default:
$link = '';
break;
}
return $link;
}
/**
* Adds a settings link on plugin page.
*
* @param array $links Current links.
*
* @return array
*/
public function settings_link( $links ) {
$action_links = array();
$wpmu_dev = new WPMUDEV();
// Dashboard-link.
$action_links['dashboard'] = '<a href="' . network_admin_url( 'admin.php?page=wp-defender' ) . '" aria-label="' . esc_attr(
esc_html__(
'Go to Defender Dashboard',
'wpdef'
)
) . '">' . esc_html__( 'Dashboard', 'wpdef' ) . '</a>';
// Documentation-link.
$action_links['docs'] = '<a target="_blank" href="' . $this->get_link(
'docs',
'defender_pluginlist_docs'
) . '" aria-label="' . esc_attr(
esc_html__(
'Docs',
'wpdef'
)
) . '">' . esc_html__( 'Docs', 'wpdef' ) . '</a>';
if ( ! $wpmu_dev->is_member() ) {
if ( WP_DEFENDER_PRO_PATH !== DEFENDER_PLUGIN_BASENAME ) {
if ( ! wd_di()->get( WPMUDEV::class )->is_wpmu_hosting() ) {
$action_links['upgrade'] = '<a style="color: #8D00B1;" target="_blank" href="' . $this->get_link(
'plugin',
'defender_pluginlist_upgrade'
) . '" aria-label="' . esc_attr(
esc_html__(
'Upgrade to Defender Pro',
'wpdef'
)
) . '">' . esc_html__( 'Get Defender Pro', 'wpdef' ) . '</a>';
}
} elseif ( ! $wpmu_dev->is_hosted_site_connected_to_tfh() ) {
$action_links['renew'] = '<a style="color: #8D00B1;" target="_blank" href="' . $this->get_link(
'plugin',
'defender_pluginlist_renew'
) . '" aria-label="' . esc_attr(
esc_html__(
'Renew Your Membership',
'wpdef'
)
) . '">' . esc_html__( 'Renew Membership', 'wpdef' ) . '</a>';
}
}
return array_merge( $action_links, $links );
}
/**
* Show row meta on the plugin screen.
*
* @param string[] $links Plugin Row Meta.
* @param string $file Plugin Base file.
* @param array $plugin_data Plugin data.
*
* @return array
*/
public function plugin_row_meta( $links, $file, $plugin_data ) {
$row_meta = array();
if ( ! defined( 'DEFENDER_PLUGIN_BASENAME' ) || DEFENDER_PLUGIN_BASENAME !== $file ) {
return $links;
}
// Change AuthorURI link.
if ( isset( $links[1] ) ) {
$author_uri = $this->is_wp_org_version ? 'https://profiles.wordpress.org/wpmudev/' : 'https://wpmudev.com/';
$author_uri = sprintf(
'<a href="%s" target="_blank">%s</a>',
$author_uri,
esc_html__( 'WPMU DEV', 'wpdef' )
);
$links[1] = sprintf(
/* translators: %s: Author URI. */
esc_html__( 'By %s', 'wpdef' ),
$author_uri
);
}
if ( $this->is_wp_org_version ) {
// Change AuthorURI link.
if ( isset( $links[2] ) && false === strpos( $links[2], 'target="_blank"' ) ) {
if ( ! isset( $plugin_data['slug'] ) && $plugin_data['Name'] ) {
$links[2] = sprintf(
'<a href="%s" class="thickbox open-plugin-details-modal" aria-label="%s" data-title="%s">%s</a>',
esc_url(
network_admin_url(
'plugin-install.php?tab=plugin-information&plugin=defender-security&TB_iframe=true&width=600&height=550'
)
),
/* translators: %s: Plugin name. */
esc_attr( sprintf( esc_html__( 'More information about %s', 'wpdef' ), $plugin_data['Name'] ) ),
esc_attr( $plugin_data['Name'] ),
esc_html__( 'View details', 'wpdef' )
);
} else {
$links[2] = str_replace( 'href=', 'target="_blank" href=', $links[2] );
}
}
$row_meta['rate'] = '<a href="' . esc_url( $this->get_link( 'rate' ) ) . '" aria-label="' . esc_attr__(
'Rate Defender',
'wpdef'
) . '" target="_blank">' . Rate::get_rate_button_title() . '</a>';
$row_meta['support'] = '<a href="' . esc_url( $this->get_link( 'support' ) ) . '" aria-label="' . esc_attr__(
'Support',
'wpdef'
) . '" target="_blank">' . esc_html__( 'Support', 'wpdef' ) . '</a>';
} else {
// Change 'Visit plugins' link to 'View details'.
if ( isset( $links[2] ) && false !== strpos( $links[2], 'project/wp-defender' ) ) {
$links[2] = sprintf(
'<a href="%s" target="_blank">%s</a>',
esc_url( $this->get_link( 'pro_link', '', 'project/wp-defender/' ) ),
esc_html__( 'View details', 'wpdef' )
);
}
$row_meta['support'] = '<a href="' . esc_url( $this->get_link( 'support' ) ) . '" aria-label="' . esc_attr__(
'Premium Support',
'wpdef'
) . '" target="_blank">' . esc_html__( 'Premium Support', 'wpdef' ) . '</a>';
}
$row_meta['roadmap'] = '<a href="' . esc_url( $this->get_link( 'roadmap' ) ) . '" aria-label="' . esc_attr__(
'Roadmap',
'wpdef'
) . '" target="_blank">' . esc_html__( 'Roadmap', 'wpdef' ) . '</a>';
return array_merge( $links, $row_meta );
}
/**
* Display IP detection notices:
* - if user site is behind proxy, e.g. Cloudflare or something else, and only for admins,
* - only on the plugin's pages.
*
* @return void
*/
public function admin_notices(): void {
if ( ! current_user_can( 'manage_options' ) || ! is_defender_page() ) {
return;
}
$header = $this->get_plugin_display_name();
if ( Firewall::is_cf_notice_ready() ) {
$is_show = 'cf';
$class_notice = 'notice-info';
$header .= esc_html__(
'Cloudflare Usage Detected: Switched to CF-Connecting-IP for Better Compatibility',
'wpdef'
);
} elseif ( Firewall::is_xff_notice_ready() ) {
$is_show = 'xff';
$class_notice = 'notice-warning';
$header .= esc_html__(
'Improve IP Detection: We suggest Switching to X-Forward-For IP Detection Method',
'wpdef'
);
} else {
return;
}
?>
<div class="defender_ip_detection_notice notice <?php echo esc_attr( $class_notice ); ?> is-dismissible"
data-nonce="<?php echo esc_attr( wp_create_nonce( 'defender_ip_detection_notice_dismiss' ) ); ?>"
data-prop="notice-for-<?php echo esc_attr( $is_show ); ?>">
<h3 style="margin-bottom:0;">
<?php echo esc_html( $header ); ?>
</h3>
<?php if ( 'cf' === $is_show ) { ?>
<p style="color: #72777C; line-height: 22px;">
<?php
printf(
/* translators: %s: Link. */
esc_html__(
'We have switched to using the CF-Connecting-IP HTTP header for IP detection, offering enhanced compatibility for users behind Cloudflare Proxy. If you wish to change this setting, you can do so from %s.',
'wpdef'
),
'<a style="font-weight:bold;" href="' . esc_url_raw( network_admin_url( 'admin.php?page=wdf-ip-lockout&view=settings#detect-ip-addresses' ) ) . '">' . esc_html__( 'here', 'wpdef' ) . '</a>'
);
?>
</p>
<p>
<button type="button" class="button button-primary button-large defender_ip_detection_action_hide"
data-prop="defender_ip_detection_notice_success">
<?php
esc_html_e(
'Ok, I understand',
'wpdef'
);
?>
</button>
</p>
<?php } elseif ( 'xff' === $is_show ) { ?>
<p style="color: #72777C; line-height: 22px;">
<?php
printf(
/* translators: %s: Link. */
esc_html__(
'Based on your server configuration, we recommend switching to the X-Forwarded-For method for accurate IP detection and to prevent firewall blocks. Easily modify your settings %s.',
'wpdef'
),
'<a style="font-weight:bold;" href="' . esc_url_raw( network_admin_url( 'admin.php?page=wdf-ip-lockout&view=settings#detect-ip-addresses' ) ) . '">' . esc_html__( 'here', 'wpdef' ) . '</a>'
);
?>
</p>
<p>
<button type="button" class="button button-primary button-large"
id="defender_ip_detection_action_switch"
data-prop="defender_ip_detection_notice_success">
<?php esc_html_e( 'Switch to X-Forwarded-For', 'wpdef' ); ?>
</button>
<a href="#" class="defender_ip_detection_action_hide"
style="margin-left: 11px; line-height: 16px; text-decoration: none; font-weight: bold;"
data-prop="defender_ip_detection_notice_dismiss"><?php esc_html_e( 'Dismiss', 'wpdef' ); ?></a>
</p>
<?php } ?>
</div>
<script type="text/javascript">
//Switch.
jQuery('#defender_ip_detection_action_switch').on('click', function (e) {
e.preventDefault();
var $notice = jQuery(e.currentTarget).closest('.defender_ip_detection_notice'),
ajaxUrl = '<?php echo esc_url_raw( admin_url( 'admin-ajax.php' ) ); ?>';
jQuery.post(
ajaxUrl,
{
action: 'defender_ip_detection_switch_to_xff',
_ajax_nonce: $notice.data('nonce')
}
).always(function () {
$notice.hide();
});
});
//Hide.
jQuery('body').on('click', '.defender_ip_detection_notice .notice-dismiss, .defender_ip_detection_action_hide', function (e) {
e.preventDefault();
var $notice = jQuery(e.currentTarget).closest('.defender_ip_detection_notice'),
ajaxUrl = '<?php echo esc_url_raw( admin_url( 'admin-ajax.php' ) ); ?>';
jQuery.post(
ajaxUrl,
{
action: 'defender_ip_detection_notice_dismiss',
prop: $notice.data('prop'),
_ajax_nonce: $notice.data('nonce')
}
).always(function () {
$notice.hide();
});
});
</script>
<?php
}
/**
* Dismiss notice.
*
* @return void
*/
public function dismiss_notice(): void {
if (
! current_user_can( 'manage_options' ) ||
! check_ajax_referer( 'defender_ip_detection_notice_dismiss' )
) {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid request, you are not allowed to do that action.', 'wpdef' ) )
);
}
$prop = defender_get_data_from_request( 'prop', 'p' );
$notice_type = '' !== trim( $prop ) ? $prop : false;
if ( 'notice-for-cf' === $notice_type ) {
update_site_option( Firewall::IP_DETECTION_CF_DISMISS_SLUG, true );
wp_send_json_success();
} elseif ( 'notice-for-xff' === $notice_type ) {
update_site_option( Firewall::IP_DETECTION_XFF_DISMISS_SLUG, true );
wp_send_json_success();
} else {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid request, allowed data not provided.', 'wpdef' ) )
);
}
}
/**
* Switch to XFF option.
*
* @return void
*/
public function switch_to_xff(): void {
if (
! current_user_can( 'manage_options' ) ||
! check_ajax_referer( 'defender_ip_detection_notice_dismiss' )
) {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid request, you are not allowed to do that action.', 'wpdef' ) )
);
}
// Change model's data.
$model_firewall = wd_di()->get( Model\Setting\Firewall::class );
$model_firewall->http_ip_header = 'HTTP_X_FORWARDED_FOR';
$xff_ip = defender_get_data_from_request( 'HTTP_X_FORWARDED_FOR', 's' );
$xff_parts = preg_split( '/\s*,\s*/', $xff_ip );
$xff_parts = is_array( $xff_parts ) ? $xff_parts : array();
$xff_parts = array_map( 'trim', $xff_parts );
$xff_parts = array_filter(
$xff_parts,
static function ( $ip ) {
return false !== filter_var( $ip, FILTER_VALIDATE_IP );
}
);
$separator = "\r\n";
$xff_parts = array_unique( $xff_parts );
$xff_ip = implode( $separator, $xff_parts );
if ( '' === $xff_ip ) {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid trusted proxy IP(s) detected in X-Forwarded-For header.', 'wpdef' ) )
);
}
if ( '' === $model_firewall->trusted_proxies_ip ) {
$model_firewall->trusted_proxies_ip = $xff_ip;
} else {
// Todo: improve the code using a separate method. This will be useful when the user switches between different proxy headeres (IP detection options).
$model_firewall->trusted_proxies_ip = $model_firewall->trusted_proxies_ip . $separator . $xff_ip;
}
$model_firewall->save();
// Save Dismiss slug.
update_site_option( Firewall::IP_DETECTION_XFF_DISMISS_SLUG, true );
wp_send_json_success();
}
/**
* Load deactivation survey modal.
*/
public function load_deactivation_survey_modal() {
$deactivation_survey_template_file = WP_DEFENDER_DIR .
'src' . DIRECTORY_SEPARATOR .
'view' . DIRECTORY_SEPARATOR .
'modal' . DIRECTORY_SEPARATOR .
'deactivation-survey.php';
if ( ! file_exists( $deactivation_survey_template_file ) ) {
return;
}
// Data to be passed to the template file.
$is_pro = wd_di()->get( WPMUDEV::class )->is_pro();
$docs_link = $this->get_link(
'support_with_utm',
'defender_deactivation_survey_help',
'',
$is_pro ? 'defender-pro' : 'defender'
);
ob_start();
require_once $deactivation_survey_template_file;
// Everything escaped in all template files.
echo ob_get_clean(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
/**
* Track deactivation.
*/
public function track_deactivate() {
if (
! current_user_can( 'manage_options' ) ||
! check_ajax_referer( 'defender_deactivation_survey_modal' )
) {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid request, you are not allowed to do that action.', 'wpdef' ) )
);
}
$posted_data = defender_get_data_from_request( null, 'p' );
if ( ! is_array( $posted_data['properties'] ) ) {
wp_send_json_error(
array( 'message' => esc_html__( 'Invalid request, allowed data not provided.', 'wpdef' ) )
);
}
$properties = $posted_data['properties'];
if (
! isset(
$properties['Reason'],
$properties['Message'],
$properties['Modal Action'],
$properties['Requested Assistance'],
$properties['Tracking Status']
)
) {
wp_send_json_error(
array( 'message' => esc_html__( 'Missing field(s).', 'wpdef' ) )
);
}
wd_di()->get( Deactivation_Survey::class )->track_deactivation_survey( $properties );
wp_send_json_success();
}
}