' . esc_html__( 'WP Activity Log requires Website File Changes Monitor 1.6.0. Please upgrade that plugin.', 'wp-security-audit-log' ) . '
'; } } } /** * Add new view given class name. * * @param string $class Class name. * * @since 5.0.0 */ public static function add_from_class( $class ) { if ( is_subclass_of( $class, '\WSAL_AbstractView' ) ) { self::$views[] = new $class( \WpSecurityAuditLog::get_instance() ); } else { self::$views[] = $class; } } /** * Order views by their declared weight. * * @since 5.0.0 */ public static function reorder_views() { usort( self::$views, array( __CLASS__, 'order_by_weight' ) ); } /** * Get page order by its weight. * * @internal This has to be public for PHP to call it. * @param \WSAL_AbstractView $a - First view. * @param \WSAL_AbstractView $b - Second view. * * @return int * * @since 5.0.0 */ public static function order_by_weight( $a, $b ) { $wa = \call_user_func( array( $a, 'get_weight' ) ); // $a->get_weight(); $wb = \call_user_func( array( $b, 'get_weight' ) ); // $b->get_weight(); switch ( true ) { case $wa < $wb: return -1; case $wa > $wb: return 1; default: return 0; } } /** * WordPress Action * * @since 5.0.0 */ public static function add_admin_menus() { self::reorder_views(); if ( Settings_Helper::current_user_can( 'view' ) && count( self::$views ) ) { // Add main menu. $main_view_menu_slug = \call_user_func( array( self::$views[0], 'get_safe_view_name' ) ); \call_user_func( array( self::$views[0], 'set_hook_suffix' ), add_menu_page( 'WP Activity Log', 'WP Activity Log', 'read', // No capability requirement. $main_view_menu_slug, array( __CLASS__, 'render_view_body' ), self::$views[0]->get_icon(), '2.5' // Right after dashboard. ) ); List_Events::add_screen_options( \call_user_func( array( self::$views[0], 'get_hook_suffix' ) ) ); // Protected views to be displayed only to user with full plugin access. $protected_views = array( 'wsal-togglealerts', 'wsal-usersessions-views', 'wsal-settings', 'wsal-ext-settings', 'wsal-rep-views-main', 'wsal-np-notifications', 'wsal-setup', 'wsal-reports-new', ); // Check edit privileges of the current user. $has_current_user_edit_priv = Settings_Helper::current_user_can( 'edit' ); // Add menu items. foreach ( self::$views as $view ) { if ( \call_user_func( array( $view, 'is_accessible' ) ) ) { $safe_view_name = \call_user_func( array( $view, 'get_safe_view_name' ) ); if ( self::get_class_name_by_view( $safe_view_name ) ) { continue; } if ( in_array( $safe_view_name, $protected_views, true ) && ! $has_current_user_edit_priv ) { continue; } if ( $view instanceof \WSAL_NP_EditNotification || $view instanceof \WSAL_NP_AddNotification ) { $main_view_menu_slug = null; } \call_user_func( array( $view, 'set_hook_suffix' ), add_submenu_page( \call_user_func( array( $view, 'is_visible' ) ) ? $main_view_menu_slug : null, \call_user_func( array( $view, 'get_title' ) ), \call_user_func( array( $view, 'get_name' ) ), 'read', // No capability requirement. $safe_view_name, array( __CLASS__, 'render_view_body' ) ) ); } } // phpcs:disable /* @free:start */ // phpcs:enable // add_submenu_page( // 'wsal-auditlog', // 'Pricing', // '', // 'read', // No capability requirement. // 'pricing', // array(), // 300 // ); add_submenu_page( 'wsal-auditlog', 'Upgrade', '', 'read', // No capability requirement. 'upgrade', array(), 301 ); // phpcs:disable /* @free:end */ // phpcs:enable } } /** * WordPress Filter * * @param array $old_links - Array of old links. * * @since 5.0.0 */ public static function add_plugin_shortcuts( $old_links ) { self::reorder_views(); $new_links = array(); foreach ( self::$views as $view ) { if ( \call_user_func( array( $view, 'has_plugin_shortcut_link' ) ) ) { $new_links[] = '' . \call_user_func( array( $view, 'get_name' ) ) . ''; if ( 1 === count( $new_links ) && ! wsal_freemius()->is__premium_only() ) { // Trial link. $trial_link = 'https://melapress.com/wordpress-activity-log/pricing/?utm_source=plugin&utm_medium=link&utm_campaign=wsal'; $new_links[] = '' . __( 'Get Premium!', 'wp-security-audit-log' ) . ''; } } } return array_merge( $new_links, $old_links ); } /** * Returns page id of current page (or false on error). * * @return int * * @since 5.0.0 */ protected static function get_backend_page_index() { // Get current view via $_GET array. $current_view = ( isset( $_GET['page'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['page'] ) ) : ''; if ( isset( $current_view ) ) { foreach ( self::$views as $i => $view ) { if ( $current_view === \call_user_func( array( $view, 'get_safe_view_name' ) ) ) { return $i; } } } return false; } /** * Returns the current active view or null if none. * * @return WSAL_AbstractView|null * * @since 5.0.0 */ public static function get_active_view() { if ( false === self::$active_view ) { self::$active_view = null; // Get current view via $_GET array. $current_view = ( isset( $_GET['page'] ) ) ? \sanitize_text_field( \wp_unslash( $_GET['page'] ) ) : ''; if ( isset( $current_view ) ) { foreach ( self::$views as $view ) { if ( $current_view === \call_user_func( array( $view, 'get_safe_view_name' ) ) ) { self::$active_view = $view; } } } } return self::$active_view; } /** * Render header of the current view. * * @since 5.0.0 */ public static function render_view_header() { $view = self::get_active_view(); if ( $view ) { \call_user_func( array( $view, 'header' ) ); } } /** * Render footer of the current view. * * @since 5.0.0 */ public static function render_view_footer() { $view = self::get_active_view(); if ( $view ) { \call_user_func( array( $view, 'footer' ) ); } global $pagenow; if ( 'admin.php' === $pagenow && ( isset( $_GET['page'] ) && 'wsal-auditlog-pricing' === $_GET['page'] ) ) { ?>