version = WSAL_VERSION;
// Set adverts array.
$this->adverts = array(
0 => array(
'head' => esc_html__( 'Upgrade to Premium and enable search filters so you can find the events you need within seconds, get notified via email or SMS about critical website changes, see who is logged-in to your website in real time, manage user sessions, create detailed reports, and much more!', 'wp-security-audit-log' ),
'desc' => esc_html__( '', 'wp-security-audit-log' ),
),
1 => array(
'head' => esc_html__( 'Instant SMS & email alerts, search & filters, reports, users sessions management and much more!', 'wp-security-audit-log' ),
'desc' => esc_html__( 'Upgrade to premium to get more out of your activity logs!', 'wp-security-audit-log' ),
),
2 => array(
'head' => esc_html__( 'See who logged in on your site in real-time, generate reports, get SMS & email alerts of critical changes and more!', 'wp-security-audit-log' ),
'desc' => esc_html__( 'Unlock these and other powerful features with WP Activity Log Premium.', 'wp-security-audit-log' ),
),
);
}
/**
* Add premium extensions notice.
*
* Notices:
* 1. Plugin advert.
* 2. DB disconnection notice.
* 3. Freemius opt-in/out notice.
*/
public function admin_notices() {
$is_current_view = View_Manager::get_active_view() == $this; // phpcs:ignore
// Check if any of the extensions are activated.
if (
! class_exists( 'WSAL_NP_Plugin' )
&& ! class_exists( 'WSAL_Ext_Plugin' )
&& ! class_exists( 'WSAL_Rep_Plugin' )
&& ! class_exists( 'WSAL_SearchExtension' )
&& ! class_exists( 'WSAL_UserSessions_Plugin' )
&& ( 'anonymous' === \WSAL\Helpers\Settings_Helper::get_option_value( 'freemius_state', 'anonymous' ) || // Anonymous mode option.
'skipped' === \WSAL\Helpers\Settings_Helper::get_option_value( 'freemius_state', 'anonymous' ) )
) {
$wsal_premium_advert = \WSAL\Helpers\Settings_Helper::get_option_value( 'premium-advert', false ); // Get the advert to display.
$wsal_premium_advert = false !== $wsal_premium_advert ? (int) $wsal_premium_advert : 0; // Set the default.
$more_info = add_query_arg(
array(
'utm_source' => 'plugin',
'utm_medium' => 'banner',
'utm_campaign' => 'wsal',
'utm_content' => 'tell+me+more',
),
'https://melapress.com/features/'
);
if ( current_user_can( 'manage_options' ) && $is_current_view ) : ?>
adverts[ $wsal_premium_advert ]['head'] ) ? esc_html( $this->adverts[ $wsal_premium_advert ]['head'] ) : false; ?>
adverts[ $wsal_premium_advert ]['desc'] ) && ! empty( $this->adverts[ $wsal_premium_advert ]['desc'] ) ? esc_html( $this->adverts[ $wsal_premium_advert ]['desc'] ) : false; ?> adverts[ $wsal_premium_advert ]['desc'] ) && ! empty( $this->adverts[ $wsal_premium_advert ]['desc'] ) ) { ?>-
'plugin',
'utm_medium' => 'banner',
'utm_campaign' => 'wsal',
),
'https://melapress.com/wordpress-activity-log/pricing/'
);
$buy_now = add_query_arg(
array(
'utm_source' => 'plugin',
'utm_medium' => 'banner',
'utm_campaign' => 'wsal',
),
'https://melapress.com/wordpress-activity-log/features/'
);
?>
is_anonymous() // Anonymous mode option.
&& wsal_freemius()->is_not_paying() // Not paying customer.
&& wsal_freemius()->has_api_connectivity() // Check API connectivity.
&& $is_current_view
&& Settings_Helper::current_user_can( 'edit' ) // Have permission to edit plugin settings.
) {
if ( ! WP_Helper::is_multisite() || ( WP_Helper::is_multisite() && is_network_admin() ) ) :
?>
' . esc_html__( 'Read more about what data we collect and how.', 'wp-security-audit-log' ) . ''; ?>
view ) ) {
$this->view = new List_Events( self::get_page_arguments() );
}
return $this->view;
}
/**
* Helper to store the views that are supported for the plugins lists.
*
* @method supported_view_types
* @since 4.0.0
* @return array
*/
public function supported_view_types() {
return array(
'list',
);
}
/**
* Handle Audit Log Form Submission
*
* @since 3.2.3
*/
public function handle_form_submission() {
// Global WP page now variable.
global $pagenow;
// Only run the function on audit log custom page.
$page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : false;
if ( 'admin.php' !== $pagenow ) {
return;
}
if ( ! in_array( $page, ['wsal-auditlog', 'Extensions-Wp-Security-Audit-Log-Premium', 'Extensions-Wp-Security-Audit-Log'] ) ) { // Page is admin.php, now check auditlog page.
return; // Return if the current page is not auditlog's.
}
// Verify nonce for security.
if ( isset( $_GET['_wpnonce'] ) ) {
check_admin_referer( 'bulk-logs' );
}
$wpnonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : false; // View nonce.
$search = isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : false; // Search.
$site_id = isset( $_GET['wsal-cbid'] ) ? (int) sanitize_text_field( wp_unslash( $_GET['wsal-cbid'] ) ) : false; // Site id.
$search_save = ( isset( $_REQUEST['wsal-save-search-name'] ) && ! empty( $_REQUEST['wsal-save-search-name'] ) ) ? trim( sanitize_text_field( wp_unslash( $_REQUEST['wsal-save-search-name'] ) ) ) : false;
if ( ! empty( $_GET['_wp_http_referer'] ) ) {
// Remove args array.
$remove_args = array(
'_wp_http_referer',
// '_wpnonce',
'wsal_as_widget_ip',
'load_saved_search_field',
'view',
);
if ( false === $site_id ) {
$remove_args[] = 'wsal-cbid';
}
if ( empty( $search_save ) ) {
$remove_args[] = 'wsal-save-search-name';
}
if ( empty( $search ) ) {
$remove_args[] = 's';
}
wp_safe_redirect( remove_query_arg( $remove_args ) );
exit();
}
}
/**
* Render view table of Audit Log.
*
* @since 1.0.0
*/
public function render() {
if ( ! Settings_Helper::current_user_can( 'view' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'wp-security-audit-log' ) );
}
// Verify nonce for security.
if ( isset( $_GET['_wpnonce'] ) ) {
check_admin_referer( 'bulk-logs' );
}
$this->get_view()->prepare_items();
$view_input_value = self::$default_view;
?>
';
//wsal_r( $alert_meta );
foreach ( $alert_meta as $item => $value ) {
if ( $value ) {
if ( is_array( $value ) || is_object( $value ) ) {
$value = var_export( $value, true );
}
echo '' . $item . ': ' . $value . ' ';
}
}
echo '';
wp_die();
}
/**
* Ajax callback to search.
*/
public function ajax_search_site() {
if ( ! Settings_Helper::current_user_can( 'view' ) ) {
die( 'Access Denied.' );
}
// Filter $_POST array for security.
$post_array = filter_input_array( INPUT_POST );
if ( ! isset( $post_array['search'] ) ) {
die( 'Search parameter expected.' );
}
$grp1 = array();
$grp2 = array();
$search = $post_array['search'];
foreach ( WP_Helper::get_sites() as $site ) {
if ( stripos( $site->blogname, $search ) !== false ) {
$grp1[] = $site;
} elseif ( stripos( $site->domain, $search ) !== false ) {
$grp2[] = $site;
}
}
die( json_encode( array_slice( $grp1 + $grp2, 0, 7 ) ) ); // phpcs:ignore
}
// phpcs:disable
// phpcs:enable
/**
* Ajax callback to download failed login log.
*/
public function wsal_download_failed_login_log() {
if ( ! isset( $_POST['download_nonce'] ) ) {
echo esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' );
die();
}
// Get post array through filter.
$download_nonce = \sanitize_text_field( \wp_unslash( $_POST['download_nonce'] ) );
// Verify nonce.
if ( empty( $download_nonce ) || ! wp_verify_nonce( $download_nonce, 'wsal-download-failed-logins' ) ) {
echo esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' );
die();
}
// Get alert by id.
$alert_id = filter_input( INPUT_POST, 'alert_id', FILTER_SANITIZE_NUMBER_INT );
// Get users using alert meta.
$users = Occurrences_Entity::get_meta_value( array( 'id' => (int) $alert_id ), 'Users', array() );
// Check if there are any users.
if ( ! empty( $users ) && is_array( $users ) ) {
// Prepare content.
$content = implode( ',', $users );
echo esc_html( $content );
} else {
echo esc_html__( 'No users found.', 'wp-security-audit-log' );
}
die();
}
/**
* Ajax callback to handle Freemius opt in/out.
*/
public function wsal_freemius_opt_in() {
// Die if not have access.
if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
die( 'Access Denied.' );
}
// Get post array through filter.
$nonce = \sanitize_text_field( \wp_unslash( $_POST['opt_nonce'] ) ); // Nonce.
$choice = \sanitize_text_field( \wp_unslash( $_POST['choice'] ) ); // Choice selected by user.
// Verify nonce.
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'wsal-freemius-opt' ) ) {
// Nonce verification failed.
echo wp_json_encode(
array(
'success' => false,
'message' => esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' ),
)
);
exit();
}
// Check if choice is not empty.
if ( ! empty( $choice ) ) {
if ( 'yes' === $choice ) {
if ( ! WP_Helper::is_multisite() ) {
wsal_freemius()->opt_in(); // Opt in.
} else {
// Get sites.
$sites = Freemius::get_sites();
$sites_data = array();
if ( ! empty( $sites ) ) {
foreach ( $sites as $site ) {
$sites_data[] = wsal_freemius()->get_site_info( $site );
}
}
wsal_freemius()->opt_in( false, false, false, false, false, false, false, false, $sites_data );
}
// Update Freemius state.
\WSAL\Helpers\Settings_Helper::set_option_value( 'freemius_state', 'in', true );
} elseif ( 'no' === $choice ) {
if ( ! WP_Helper::is_multisite() ) {
wsal_freemius()->skip_connection(); // Opt out.
} else {
wsal_freemius()->skip_connection( null, true ); // Opt out for all websites.
}
// Update Freemius state.
\WSAL\Helpers\Settings_Helper::set_option_value( 'freemius_state', 'skipped', true );
}
echo wp_json_encode(
array(
'success' => true,
'message' => esc_html__( 'Freemius opt choice selected.', 'wp-security-audit-log' ),
)
);
} else {
echo wp_json_encode(
array(
'success' => false,
'message' => esc_html__( 'Freemius opt choice not found.', 'wp-security-audit-log' ),
)
);
}
exit();
}
/**
* Method: Render header of the view.
*/
public static function header() {
add_thickbox();
// Darktooltip styles.
wp_enqueue_style(
'darktooltip',
WSAL_BASE_URL . '/css/darktooltip.css',
array(),
'0.4.0'
);
// Remodal styles.
wp_enqueue_style( 'wsal-remodal', WSAL_BASE_URL . '/css/remodal.css', array(), WSAL_VERSION );
wp_enqueue_style( 'wsal-remodal-theme', WSAL_BASE_URL . '/css/remodal-default-theme.css', array(), WSAL_VERSION );
// Audit log styles.
wp_enqueue_style(
'auditlog',
WSAL_BASE_URL . '/css/auditlog.css',
array(),
WSAL_VERSION
);
// Admin notices styles.
wp_enqueue_style(
'wsal_admin_notices',
WSAL_BASE_URL . '/css/admin-notices.css',
array(),
WSAL_VERSION
);
}
/**
* {@inheritDoc}
*/
public static function footer() {
wp_enqueue_script( 'jquery' );
// Darktooltip js.
wp_enqueue_script(
'darktooltip', // Identifier.
WSAL_BASE_URL . '/js/jquery.darktooltip.js', // Script location.
array( 'jquery' ), // Depends on jQuery.
WSAL_VERSION, // Script version.
true
);
// Remodal script.
wp_enqueue_script(
'wsal-remodal-js',
WSAL_BASE_URL . '/js/remodal.min.js',
array(),
WSAL_VERSION,
true
);
// WP Suggest Script.
wp_enqueue_script( 'suggest' );
// Audit log script.
wp_register_script(
'auditlog',
WSAL_BASE_URL . '/js/auditlog.js',
array(),
WSAL_VERSION,
true
);
$audit_log_data = array(
'page' => isset( self::get_page_arguments()['page'] ) ? self::get_page_arguments()['page']: false,
'siteId' => isset( self::get_page_arguments()['site_id'] ) ? self::get_page_arguments()['site_id'] : false,
'orderBy' => isset( self::get_page_arguments()['order_by'] ) ? self::get_page_arguments()['order_by'] : false,
'order' => isset( self::get_page_arguments()['order'] ) ? self::get_page_arguments()['order'] : false,
'searchTerm' => isset( self::get_page_arguments()['search_term'] ) ? self::get_page_arguments()['search_term'] : false,
'searchFilters' => isset( self::get_page_arguments()['search_filters'] ) ? self::get_page_arguments()['search_filters'] : false,
'closeInspectorString' => esc_html__( 'Close inspector', 'wp-security-audit-log' ),
'viewerNonce' => wp_create_nonce( 'wsal_auditlog_viewer_nonce' ),
'installAddonStrings' => array(
'defaultButton' => esc_html__( 'Install and activate extension', 'wp-security-audit-log' ),
'installingText' => esc_html__( 'Installing extension', 'wp-security-audit-log' ),
'otherInstalling' => esc_html__( 'Other extension installing', 'wp-security-audit-log' ),
'addonInstalled' => esc_html__( 'Installed', 'wp-security-audit-log' ),
'installedReload' => esc_html__( 'Installed... reloading page', 'wp-security-audit-log' ),
'buttonError' => esc_html__( 'Problem enabling', 'wp-security-audit-log' ),
),
);
wp_localize_script( 'auditlog', 'wsalAuditLogArgs', $audit_log_data );
wp_enqueue_script( 'auditlog' );
}
/**
* Method: Load WSAL Notice Pointer.
*
* @param string $hook_suffix - Current hook suffix.
* @since 3.2
*/
public static function load_pointers( $hook_suffix ) {
// Don't run on WP < 3.3.
if ( get_bloginfo( 'version' ) < '3.3' ) {
return;
}
// Don't display notice if the wizard notice is showing.
if (
! \WSAL\Helpers\Settings_Helper::get_boolean_option_value( 'setup-complete', false )
&& ! \WSAL\Helpers\Settings_Helper::get_boolean_option_value( 'setup-modal-dismissed', false )
) {
return;
}
// Get screen id.
$screen = get_current_screen();
$screen_id = $screen->id;
// Get pointers for this screen.
$pointers = apply_filters( 'wsal_pointers_' . $screen_id, array() );
if ( ! $pointers || ! is_array( $pointers ) ) {
return;
}
// Get dismissed pointers.
$dismissed = explode( ',', (string) \WSAL\Helpers\Settings_Helper::get_option_value( 'dismissed-privacy-notice', true ) );
$valid_pointers = array();
// Check pointers and remove dismissed ones.
foreach ( $pointers as $pointer_id => $pointer ) {
// Sanity check.
if (
in_array( $pointer_id, $dismissed ) // phpcs:ignore
|| empty( $pointer )
|| empty( $pointer_id )
|| empty( $pointer['target'] )
|| empty( $pointer['options'] )
) {
continue;
}
$pointer['pointer_id'] = $pointer_id;
// Add the pointer to $valid_pointers array.
$valid_pointers['pointers'][] = $pointer;
}
// No valid pointers? Stop here.
if ( empty( $valid_pointers ) ) {
return;
}
// Add pointers style to queue.
wp_enqueue_style( 'wp-pointer' );
// Add pointers script to queue. Add custom script.
wp_enqueue_script(
'auditlog-pointer',
WSAL_BASE_URL . '/js/auditlog-pointer.js',
array( 'wp-pointer' ),
WSAL_VERSION,
true
);
// Add pointer options to script.
wp_localize_script( 'auditlog-pointer', 'wsalPointer', $valid_pointers );
}
/**
* Method: Register privacy pointer for WSAL.
*
* @param array $pointer - Current screen pointer array.
* @return array
* @since 3.2
*/
public function register_privacy_pointer( $pointer ) {
$is_current_view = View_Manager::get_active_view() == $this; // phpcs:ignore
if ( current_user_can( 'manage_options' ) && $is_current_view && ! isset( $pointer['wsal_privacy'] ) ) {
$pointer['wsal_privacy'] = array(
'target' => '#toplevel_page_wsal-auditlog .wp-first-item',
'options' => array(
'content' => sprintf(
' %s %s
%s
',
esc_html__( 'WordPress Activity Log', 'wp-security-audit-log' ),
esc_html__( 'When a user makes a change on your website the plugin will keep a record of that event here. Right now there is nothing because this is a new install.', 'wp-security-audit-log' ),
esc_html__( 'Thank you for using WP Activity Log', 'wp-security-audit-log' )
),
'position' => array(
'edge' => 'left',
'align' => 'top',
),
),
);
}
return $pointer;
}
/**
* Method: Ajax request handler to dismiss pointers.
*
* @since 3.2.4
*/
public static function dismiss_wp_pointer() {
if ( isset( $_POST['pointer'] ) ) {
$pointer = sanitize_text_field( wp_unslash( $_POST['pointer'] ) );
if ( sanitize_key( $pointer ) !== $pointer ) {
wp_die( 0 );
}
$dismissed = array_filter( explode( ',', (string) \WSAL\Helpers\Settings_Helper::get_option_value( 'dismissed-privacy-notice', true ) ) );
if ( in_array( $pointer, $dismissed, true ) ) {
wp_die( 0 );
}
$dismissed[] = $pointer;
$dismissed = implode( ',', $dismissed );
\WSAL\Helpers\Settings_Helper::set_option_value( 'dismissed-privacy-notice', $dismissed );
wp_die( 1 );
}
}
/**
* Method: Ajax request handler to dismiss setup modal.
*
* @since 4.1.4
*/
public static function dismiss_setup_modal() {
// Die if user does not have permission to dismiss.
if ( ! Settings_Helper::current_user_can( 'edit' ) ) {
echo wp_json_encode(
array(
'success' => false,
'message' => esc_html__( 'You do not have sufficient permissions to dismiss this notice.', 'wp-security-audit-log' ),
)
);
die();
}
// Filter $_POST array for security.
$nonce = isset( $_POST['nonce'] ) ? \sanitize_text_field( \wp_unslash( $_POST['nonce'] ) ) : false;
if ( empty( $nonce ) || ! wp_verify_nonce( $nonce, 'wsal_dismiss_setup_modal' ) ) {
// Nonce verification failed.
echo wp_json_encode(
array(
'success' => false,
'message' => esc_html__( 'Nonce verification failed.', 'wp-security-audit-log' ),
)
);
die();
}
\WSAL\Helpers\Settings_Helper::set_boolean_option_value( 'setup-modal-dismissed', true, true );
wp_send_json_success();
}
// phpcs:disable
// phpcs:enable
}