Plugin Directory

Changeset 3219912


Ignore:
Timestamp:
01/09/2025 11:32:10 PM (15 months ago)
Author:
logtivity
Message:

Release 3.1.4

Location:
logtivity
Files:
4 added
10 edited
1 copied

Legend:

Unmodified
Added
Removed
  • logtivity/tags/3.1.4/Admin/Logtivity_Admin.php

    r3160076 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     26// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     27// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     28
    2529class Logtivity_Admin
    2630{
    27     protected $options;
    28 
    29     protected static $shouldHidePluginFromUI = false;
    30    
    31     public function __construct()
    32     {
    33         add_action( 'admin_menu', [$this, 'registerOptionsPage'] );
    34 
    35         add_action( 'wp_ajax_logtivity_update_settings', [$this, 'update']);
    36         add_action( 'wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
    37 
    38         add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
    39         add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
    40 
    41         $this->options = new Logtivity_Options;
    42     }
    43 
    44     public function maybeHideFromMenu($plugins)
    45     {
    46         if ($name = (new Logtivity_Options)->customPluginName()) {
    47             if (isset($plugins['logtivity/logtivity.php'])) {
    48                 $plugins['logtivity/logtivity.php']['Name'] = $name;
    49             }
    50         }
    51 
    52         if (!$this->shouldHidePluginFromUI(false)) {
    53             return $plugins;
    54         }
    55 
    56         $shouldHide = ! array_key_exists( 'show_all', $_GET );
    57 
    58         if ( $shouldHide ) {
    59             $hiddenPlugins = [
    60                 'logtivity/logtivity.php',
    61             ];
    62 
    63             foreach ( $hiddenPlugins as $hiddenPlugin ) {
    64                 unset( $plugins[ $hiddenPlugin ] );
    65             }
    66         }
    67         return $plugins;
    68     }
    69 
    70     public function shouldHidePluginFromUI($value)
    71     {
    72         if (self::$shouldHidePluginFromUI = (new Logtivity_Options)->isPluginHiddenFromUI()) {
    73             return self::$shouldHidePluginFromUI;
    74         }
    75         return $value;
    76     }
    77 
    78     /**
    79      * Register the settings page
    80      */
    81     public function registerOptionsPage()
    82     {
    83         if (!apply_filters('logtivity_hide_from_menu', false)) {
    84             add_menu_page(
    85                 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
    86                 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
    87                 'manage_options',
    88                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
    89                 [$this, 'showLogIndexPage'],
    90                 'dashicons-chart-area',
    91                 26
    92             );
    93         }
    94        
    95         if (!apply_filters('logtivity_hide_settings_page', false)) {
    96             add_submenu_page(
    97                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
    98                 'Logtivity Settings',
    99                 'Settings',
    100                 'manage_options',
    101                 'logtivity'.'-settings',
    102                 [$this, 'showLogtivitySettingsPage']
    103             );
    104         }
    105     }
    106 
    107     /**
    108      * Show the admin log index
    109      *
    110      * @return void
    111      */
    112     public function showLogIndexPage()
    113     {
    114         if ( !current_user_can( 'manage_options' ) )  {
    115             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    116         }
    117 
    118         $options = $this->options->getOptions();
    119 
    120         echo logtivity_view('log-index', compact('options'));
    121     }
    122 
    123     /**
    124      * Show the admin settings template
    125      *
    126      * @return void
    127      */
    128     public function showLogtivitySettingsPage()
    129     {
    130         if ( !current_user_can( 'manage_options' ) )  {
    131             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    132         }
    133 
    134         $options = $this->options->getOptions();
    135 
    136         echo logtivity_view('settings', compact('options'));
    137     }
    138 
    139     /**
    140      * Update the settings
    141      *
    142      * @return WP_Redirect
    143      */
    144     public function update()
    145     {
    146         if (!wp_verify_nonce( $_POST['logtivity_update_settings'], 'logtivity_update_settings' ))
    147         {
    148             wp_safe_redirect( $this->settingsPageUrl() );
    149             exit;
    150             return;
    151         }
    152 
    153         $user = new Logtivity_Wp_User;
    154 
    155         if (!$user->hasRole('administrator')) {
    156             wp_safe_redirect( $this->settingsPageUrl() );
    157             exit;
    158             return;
    159         }
    160 
    161         $this->options->update([
    162                 'logtivity_url_hash' => md5(home_url()),
    163             ],
    164             false
    165         );
    166 
    167         delete_transient( 'dismissed-logtivity-site-url-has-changed-notice' );
    168 
    169         $this->options->update();
    170 
    171         (new Logtivity_Check_For_New_Settings)->checkForNewSettings();
    172        
    173         wp_safe_redirect( $this->settingsPageUrl() );
    174         exit;
    175     }
    176 
    177     /**
    178      * Get the url to the settings page
    179      *
    180      * @return string
    181      */
    182     public function settingsPageUrl()
    183     {
    184         return admin_url('admin.php?page=logtivity-settings');
    185     }
    186 
     31    /**
     32     * @var Logtivity_Options
     33     */
     34    protected Logtivity_Options $options;
     35
     36    /**
     37     * @var bool
     38     */
     39    protected static bool $shouldHidePluginFromUI = false;
     40
     41    public function __construct()
     42    {
     43        add_action('admin_menu', [$this, 'registerOptionsPage']);
     44
     45        add_action('wp_ajax_logtivity_update_settings', [$this, 'update']);
     46        add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
     47
     48        add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
     49        add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
     50
     51        $this->options = new Logtivity_Options();
     52    }
     53
     54    /**
     55     * @param array $plugins
     56     *
     57     * @return array
     58     */
     59    public function maybeHideFromMenu(array $plugins): array
     60    {
     61        if ($name = (new Logtivity_Options())->customPluginName()) {
     62            if (isset($plugins['logtivity/logtivity.php'])) {
     63                $plugins['logtivity/logtivity.php']['Name'] = $name;
     64            }
     65        }
     66
     67        if (!$this->shouldHidePluginFromUI()) {
     68            return $plugins;
     69        }
     70
     71        $shouldHide = !array_key_exists('show_all', $_GET);
     72
     73        if ($shouldHide) {
     74            $hiddenPlugins = [
     75                'logtivity/logtivity.php',
     76            ];
     77
     78            foreach ($hiddenPlugins as $hiddenPlugin) {
     79                unset($plugins[$hiddenPlugin]);
     80            }
     81        }
     82        return $plugins;
     83    }
     84
     85    /**
     86     * @param bool $value
     87     *
     88     * @return bool
     89     */
     90    public function shouldHidePluginFromUI(bool $value = false): bool
     91    {
     92        if (static::$shouldHidePluginFromUI = (new Logtivity_Options())->isPluginHiddenFromUI()) {
     93            return static::$shouldHidePluginFromUI;
     94        }
     95
     96        return $value;
     97    }
     98
     99    /**
     100     * Register the settings page
     101     */
     102    public function registerOptionsPage()
     103    {
     104        if (!apply_filters('logtivity_hide_from_menu', false)) {
     105            add_menu_page(
     106                ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
     107                ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
     108                'manage_options',
     109                ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     110                [$this, 'showLogIndexPage'],
     111                'dashicons-chart-area',
     112                26
     113            );
     114        }
     115
     116        if (!apply_filters('logtivity_hide_settings_page', false)) {
     117            add_submenu_page(
     118                ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     119                'Logtivity Settings',
     120                'Settings',
     121                'manage_options',
     122                'logtivity' . '-settings',
     123                [$this, 'showLogtivitySettingsPage']
     124            );
     125        }
     126    }
     127
     128    /**
     129     * Show the admin log index
     130     *
     131     * @return void
     132     */
     133    public function showLogIndexPage()
     134    {
     135        if (!current_user_can('manage_options')) {
     136            wp_die(__('You do not have sufficient permissions to access this page.'));
     137        }
     138
     139        $options = $this->options->getOptions();
     140
     141        echo logtivity_view('log-index', compact('options'));
     142    }
     143
     144    /**
     145     * Show the admin settings template
     146     *
     147     * @return void
     148     */
     149    public function showLogtivitySettingsPage()
     150    {
     151        if (!current_user_can('manage_options')) {
     152            wp_die(__('You do not have sufficient permissions to access this page.'));
     153        }
     154
     155        $options = $this->options->getOptions();
     156
     157        echo logtivity_view('settings', compact('options'));
     158    }
     159
     160    /**
     161     * Update the settings
     162     *
     163     * @return void
     164     */
     165    public function update(): void
     166    {
     167        if (!wp_verify_nonce($_POST['logtivity_update_settings'], 'logtivity_update_settings')) {
     168            wp_safe_redirect($this->settingsPageUrl());
     169            exit;
     170        }
     171
     172        $user = new Logtivity_Wp_User();
     173
     174        if (!$user->hasRole('administrator')) {
     175            wp_safe_redirect($this->settingsPageUrl());
     176            exit;
     177        }
     178
     179        $this->options->update(
     180            [
     181                'logtivity_url_hash' => md5(home_url()),
     182            ],
     183            false
     184        );
     185
     186        delete_transient('dismissed-logtivity-site-url-has-changed-notice');
     187
     188        $this->options->update();
     189
     190        (new Logtivity_Check_For_New_Settings())->checkForNewSettings();
     191
     192        wp_safe_redirect($this->settingsPageUrl());
     193        exit;
     194    }
     195
     196    /**
     197     * @return string
     198     */
     199    public function settingsPageUrl(): string
     200    {
     201        return admin_url('admin.php?page=logtivity-settings');
     202    }
    187203}
    188204
    189 $Logtivity_Admin = new Logtivity_Admin;
    190 
     205new Logtivity_Admin();
  • logtivity/tags/3.1.4/Admin/Logtivity_Dismiss_Notice_Controller.php

    r3160076 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     26// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     27// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     28
    2529class Logtivity_Dismiss_Notice_Controller
    2630{
    27     protected $notices = [
    28         'logtivity-site-url-has-changed-notice'
    29     ];
     31    /**
     32     * @var string[]
     33     */
     34    protected array $notices = [
     35        'logtivity-site-url-has-changed-notice',
     36    ];
    3037
    31     public function __construct()
    32     {
    33         add_action("wp_ajax_nopriv_logtivity_dismiss_notice", [$this, 'dismiss']);
    34         add_action("wp_ajax_logtivity_dismiss_notice", [$this, 'dismiss']);
    35     }
     38    public function __construct()
     39    {
     40        add_action('wp_ajax_nopriv_logtivity_dismiss_notice', [$this, 'dismiss']);
     41        add_action('wp_ajax_logtivity_dismiss_notice', [$this, 'dismiss']);
     42    }
    3643
    37     public function dismiss()
    38     {
    39         if ( !current_user_can( 'manage_options' ) )  {
    40             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    41         }
     44    /**
     45     * @return void
     46     */
     47    public function dismiss(): void
     48    {
     49        if (!current_user_can('manage_options')) {
     50            wp_die(__('You do not have sufficient permissions to access this page.'));
     51        }
    4252
    43         if (!in_array($_POST['type'], $this->notices)) {
    44             return;
    45         }
     53        $postType = sanitize_text_field($_POST['postType'] ?? null);
     54        if (in_array($postType, $this->notices)) {
     55            $dismissUntil = sanitize_text_field($_POST['dismissUntil'] ?? null);
    4656
    47         if (isset($_POST['dismiss_until']) && $_POST['dismiss_until']) {
    48             set_transient(
    49                 'dismissed-' . $_POST['type'],
    50                 true,
    51                 (isset($_POST['dismiss_until']) ? intval($_POST['dismiss_until']) : 0)
    52             );
    53         } else {
    54             update_option('dismissed-' . $_POST['type'], true);
    55         }
     57            if ($dismissUntil) {
     58                set_transient(
     59                    'dismissed-' . $postType,
     60                    true,
     61                    (int)$dismissUntil
     62                );
     63            } else {
     64                update_option('dismissed-' . $postType, true);
     65            }
    5666
    57         wp_send_json(['message' => 'success']);
    58     }
     67            wp_send_json(['message' => 'success']);
     68        }
     69    }
    5970}
    6071
    61 new Logtivity_Dismiss_Notice_Controller;
     72new Logtivity_Dismiss_Notice_Controller();
  • logtivity/tags/3.1.4/Admin/Logtivity_Options.php

    r3194447 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     26// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     27
    2528class Logtivity_Options
    2629{
     
    190193    }
    191194
    192     public function urlHash()
    193     {
    194         return $this->getOption('logtivity_url_hash');
    195     }
    196 
    197195    /**
    198196     * @return string
    199197     */
     198    public function urlHash(): string
     199    {
     200        return (string)$this->getOption('logtivity_url_hash');
     201    }
     202
     203    /**
     204     * @return string
     205     */
    200206    public function disabledLogs(): string
    201207    {
     
    203209    }
    204210
    205     public function isWhiteLabelMode()
    206     {
    207         return $this->getOption('logtivity_enable_white_label_mode');
    208     }
    209 
    210     public function isPluginHiddenFromUI()
    211     {
    212         return $this->getOption('logtivity_hide_plugin_from_ui');
    213     }
    214 
    215     public function customPluginName()
    216     {
    217         return $this->getOption('logtivity_custom_plugin_name');
     211    /**
     212     * @return bool
     213     */
     214    public function isWhiteLabelMode(): bool
     215    {
     216        return (bool)$this->getOption('logtivity_enable_white_label_mode');
     217    }
     218
     219    /**
     220     * @return bool
     221     */
     222    public function isPluginHiddenFromUI(): bool
     223    {
     224        return (bool)$this->getOption('logtivity_hide_plugin_from_ui');
     225    }
     226
     227    /**
     228     * @return string
     229     */
     230    public function customPluginName(): string
     231    {
     232        return (string)$this->getOption('logtivity_custom_plugin_name');
    218233    }
    219234
     
    283298    protected function validateSetting(string $setting, $value): bool
    284299    {
    285         $method = $this->rules[$setting] ?? null;
    286         switch ($method) {
    287             case 'is_bool':
    288                 $value = (bool)$value;
    289                 break;
    290 
    291             default:
    292                 if (function_exists($method)) {
    293                     $value = $method($value);
    294 
    295                 } else {
    296                     $value = true;
    297                 }
    298                 break;
    299         }
    300 
    301         return $value;
     300        if (isset($this->rules[$setting])) {
     301            $method = $this->rules[$setting];
     302
     303            if ($method == 'is_bool') {
     304                return $method((bool)$value);
     305            }
     306
     307            return $method($value);
     308        }
     309
     310        return true;
    302311    }
    303312}
  • logtivity/tags/3.1.4/logtivity.php

    r3194447 r3219912  
    55 * Plugin URI:  https://logtivity.io
    66 * Description: Record activity logs and errors logs across all your WordPress sites.
    7  * Version:     3.1.3
     7 * Version:     3.1.4
    88 * Author:      Logtivity
    99 * Text Domain: logtivity
     
    3131 * along with Logtivity.  If not, see <https://www.gnu.org/licenses/>.
    3232 */
     33
     34// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     35// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     36
    3337class Logtivity
    3438{
    35     protected $version = '3.1.3';
     39    /**
     40     * @var string
     41     */
     42    protected string $version = '3.1.4';
    3643
    3744    /**
    3845     * List all classes here with their file paths. Keep class names the same as filenames.
    3946     *
    40      * @var array
    41      */
    42     private $dependancies = [
     47     * @var string[]
     48     */
     49    private array $dependencies = [
    4350        'Helpers/Helpers',
    4451        'Helpers/Logtivity_Wp_User',
     
    6572
    6673    /**
    67      *
    68      *    Log classes
    69      *
    70      */
    71     private $logClasses = [
     74     * @var string[]
     75     */
     76    private array $logClasses = [
    7277        /**
    7378         * Activity logging
     
    8489
    8590    /**
    86      * List all integration dependancies
    87      *
    88      * @var array
    89      */
    90     private $integrationDependancies = [
     91     * List all integration dependencies
     92     *
     93     * @var array[]
     94     */
     95    private array $integrationDependencies = [
    9196        'WP_DLM'                 => [
    9297            'Logs/Download_Monitor/Logtivity_Download_Monitor',
     
    119124    public function __construct()
    120125    {
    121         $this->loadDependancies();
     126        $this->loadDependencies();
    122127
    123128        add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage']);
     
    136141    }
    137142
    138     public function loadDependancies()
    139     {
    140         foreach ($this->dependancies as $filePath) {
     143    public function loadDependencies()
     144    {
     145        foreach ($this->dependencies as $filePath) {
    141146            $this->loadFile($filePath);
    142147        }
     
    149154            $this->maybeLoadLogClasses();
    150155
    151             $this->loadIntegrationDependancies();
     156            $this->loadIntegrationDependencies();
    152157        });
    153158    }
     
    163168     * @return bool
    164169     */
    165     public function defaultLoggingDisabled()
    166     {
    167         return (new Logtivity_Options)->getOption('logtivity_disable_default_logging');
     170    public function defaultLoggingDisabled(): bool
     171    {
     172        return (bool)(new Logtivity_Options())->getOption('logtivity_disable_default_logging');
    168173    }
    169174
     
    175180    }
    176181
    177     public function loadIntegrationDependancies()
    178     {
    179         foreach ($this->integrationDependancies as $key => $value) {
     182    public function loadIntegrationDependencies()
     183    {
     184        foreach ($this->integrationDependencies as $key => $value) {
    180185            if (class_exists($key)) {
    181186                foreach ($value as $filePath) {
     
    191196    }
    192197
    193     public static function logError($error)
     198    /**
     199     * @param array $error
     200     *
     201     * @return Logtivity_Error_Logger
     202     */
     203    public static function logError(array $error): Logtivity_Error_Logger
    194204    {
    195205        return new Logtivity_Error_Logger($error);
    196206    }
    197207
    198     public function upgradeProcessComplete($upgrader_object, $options)
    199     {
    200         if ($options['type'] != 'plugin') {
    201             return;
    202         }
    203 
    204         if ($options['action'] == 'update') {
    205             return $this->setLogtivityToLoadFirst();
    206         }
    207     }
    208 
    209     public function setLogtivityToLoadFirst()
     208    /**
     209     * @param $upgraderObject
     210     * @param $options
     211     *
     212     * @return null|void
     213     */
     214    public function upgradeProcessComplete($upgraderObject, $options)
     215    {
     216        $type   = $options['type'] ?? null;
     217        $action = $options['action'] ?? null;
     218
     219        if ($type == 'plugin' && $action == 'update') {
     220            $this->setLogtivityToLoadFirst();
     221        }
     222    }
     223
     224    /**
     225     * @return void
     226     */
     227    public function setLogtivityToLoadFirst(): void
    210228    {
    211229        $path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__);
     
    220238    }
    221239
    222     public function addSettingsLinkFromPluginsPage($links)
     240    /**
     241     * @param array $links
     242     *
     243     * @return string[]
     244     */
     245    public function addSettingsLinkFromPluginsPage(array $links): array
    223246    {
    224247        if (apply_filters('logtivity_hide_settings_page', false)) {
     
    226249        }
    227250
    228         $settings_links = [
    229             '<a href="' . admin_url('admin.php?page=logtivity-settings') . '">Settings</a>',
    230         ];
    231 
    232         return array_merge($settings_links, $links);
    233     }
    234 
    235     public function activated()
     251        return array_merge(
     252            [
     253                sprintf('<a href="%s">Settings</a>', admin_url('admin.php?page=logtivity-settings')),
     254            ],
     255            $links
     256        );
     257    }
     258
     259    /**
     260     * @return void
     261     */
     262    public function activated(): void
    236263    {
    237264        if (apply_filters('logtivity_hide_settings_page', false)) {
     
    242269    }
    243270
    244     public function welcomeMessage()
     271    /**
     272     * @return void
     273     */
     274    public function welcomeMessage(): void
    245275    {
    246276        if (get_transient('logtivity-welcome-notice')) {
     
    251281    }
    252282
    253     public function checkForSiteUrlChange()
    254     {
    255         if (!current_user_can('manage_options')) {
    256             return;
    257         }
    258 
    259         if (logtivity_has_site_url_changed() && !get_transient('dismissed-logtivity-site-url-has-changed-notice')) {
     283    /**
     284     * @return void
     285     */
     286    public function checkForSiteUrlChange(): void
     287    {
     288        if (
     289            current_user_can('manage_options')
     290            && logtivity_has_site_url_changed()
     291            && !get_transient('dismissed-logtivity-site-url-has-changed-notice')
     292        ) {
    260293            echo logtivity_view('site-url-changed-notice');
    261294        }
    262295    }
    263296
    264     public function loadScripts()
     297    /**
     298     * @return void
     299     */
     300    public function loadScripts(): void
    265301    {
    266302        wp_enqueue_style(
     
    285321}
    286322
    287 $logtivity = new Logtivity;
     323$logtivity = new Logtivity();
  • logtivity/tags/3.1.4/readme.txt

    r3194447 r3219912  
    55Requires at least: 4.7
    66Tested up to: 6.6.2
    7 Stable tag: 3.1.3
     7Stable tag: 3.1.4
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    262262
    263263== Changelog ==
     264
     265= 3.1.4 =
     266
     267_Release Date - TBD
     268
     269* Fix: Deprecation warning, #50
     270* Fix: Unable to uncheck settings
    264271
    265272= 3.1.3 =
  • logtivity/trunk/Admin/Logtivity_Admin.php

    r3160076 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     26// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     27// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     28
    2529class Logtivity_Admin
    2630{
    27     protected $options;
    28 
    29     protected static $shouldHidePluginFromUI = false;
    30    
    31     public function __construct()
    32     {
    33         add_action( 'admin_menu', [$this, 'registerOptionsPage'] );
    34 
    35         add_action( 'wp_ajax_logtivity_update_settings', [$this, 'update']);
    36         add_action( 'wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
    37 
    38         add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
    39         add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
    40 
    41         $this->options = new Logtivity_Options;
    42     }
    43 
    44     public function maybeHideFromMenu($plugins)
    45     {
    46         if ($name = (new Logtivity_Options)->customPluginName()) {
    47             if (isset($plugins['logtivity/logtivity.php'])) {
    48                 $plugins['logtivity/logtivity.php']['Name'] = $name;
    49             }
    50         }
    51 
    52         if (!$this->shouldHidePluginFromUI(false)) {
    53             return $plugins;
    54         }
    55 
    56         $shouldHide = ! array_key_exists( 'show_all', $_GET );
    57 
    58         if ( $shouldHide ) {
    59             $hiddenPlugins = [
    60                 'logtivity/logtivity.php',
    61             ];
    62 
    63             foreach ( $hiddenPlugins as $hiddenPlugin ) {
    64                 unset( $plugins[ $hiddenPlugin ] );
    65             }
    66         }
    67         return $plugins;
    68     }
    69 
    70     public function shouldHidePluginFromUI($value)
    71     {
    72         if (self::$shouldHidePluginFromUI = (new Logtivity_Options)->isPluginHiddenFromUI()) {
    73             return self::$shouldHidePluginFromUI;
    74         }
    75         return $value;
    76     }
    77 
    78     /**
    79      * Register the settings page
    80      */
    81     public function registerOptionsPage()
    82     {
    83         if (!apply_filters('logtivity_hide_from_menu', false)) {
    84             add_menu_page(
    85                 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
    86                 ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
    87                 'manage_options',
    88                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
    89                 [$this, 'showLogIndexPage'],
    90                 'dashicons-chart-area',
    91                 26
    92             );
    93         }
    94        
    95         if (!apply_filters('logtivity_hide_settings_page', false)) {
    96             add_submenu_page(
    97                 ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
    98                 'Logtivity Settings',
    99                 'Settings',
    100                 'manage_options',
    101                 'logtivity'.'-settings',
    102                 [$this, 'showLogtivitySettingsPage']
    103             );
    104         }
    105     }
    106 
    107     /**
    108      * Show the admin log index
    109      *
    110      * @return void
    111      */
    112     public function showLogIndexPage()
    113     {
    114         if ( !current_user_can( 'manage_options' ) )  {
    115             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    116         }
    117 
    118         $options = $this->options->getOptions();
    119 
    120         echo logtivity_view('log-index', compact('options'));
    121     }
    122 
    123     /**
    124      * Show the admin settings template
    125      *
    126      * @return void
    127      */
    128     public function showLogtivitySettingsPage()
    129     {
    130         if ( !current_user_can( 'manage_options' ) )  {
    131             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    132         }
    133 
    134         $options = $this->options->getOptions();
    135 
    136         echo logtivity_view('settings', compact('options'));
    137     }
    138 
    139     /**
    140      * Update the settings
    141      *
    142      * @return WP_Redirect
    143      */
    144     public function update()
    145     {
    146         if (!wp_verify_nonce( $_POST['logtivity_update_settings'], 'logtivity_update_settings' ))
    147         {
    148             wp_safe_redirect( $this->settingsPageUrl() );
    149             exit;
    150             return;
    151         }
    152 
    153         $user = new Logtivity_Wp_User;
    154 
    155         if (!$user->hasRole('administrator')) {
    156             wp_safe_redirect( $this->settingsPageUrl() );
    157             exit;
    158             return;
    159         }
    160 
    161         $this->options->update([
    162                 'logtivity_url_hash' => md5(home_url()),
    163             ],
    164             false
    165         );
    166 
    167         delete_transient( 'dismissed-logtivity-site-url-has-changed-notice' );
    168 
    169         $this->options->update();
    170 
    171         (new Logtivity_Check_For_New_Settings)->checkForNewSettings();
    172        
    173         wp_safe_redirect( $this->settingsPageUrl() );
    174         exit;
    175     }
    176 
    177     /**
    178      * Get the url to the settings page
    179      *
    180      * @return string
    181      */
    182     public function settingsPageUrl()
    183     {
    184         return admin_url('admin.php?page=logtivity-settings');
    185     }
    186 
     31    /**
     32     * @var Logtivity_Options
     33     */
     34    protected Logtivity_Options $options;
     35
     36    /**
     37     * @var bool
     38     */
     39    protected static bool $shouldHidePluginFromUI = false;
     40
     41    public function __construct()
     42    {
     43        add_action('admin_menu', [$this, 'registerOptionsPage']);
     44
     45        add_action('wp_ajax_logtivity_update_settings', [$this, 'update']);
     46        add_action('wp_ajax_nopriv_logtivity_update_settings', [$this, 'update']);
     47
     48        add_filter('logtivity_hide_from_menu', [$this, 'shouldHidePluginFromUI']);
     49        add_filter('all_plugins', [$this, 'maybeHideFromMenu']);
     50
     51        $this->options = new Logtivity_Options();
     52    }
     53
     54    /**
     55     * @param array $plugins
     56     *
     57     * @return array
     58     */
     59    public function maybeHideFromMenu(array $plugins): array
     60    {
     61        if ($name = (new Logtivity_Options())->customPluginName()) {
     62            if (isset($plugins['logtivity/logtivity.php'])) {
     63                $plugins['logtivity/logtivity.php']['Name'] = $name;
     64            }
     65        }
     66
     67        if (!$this->shouldHidePluginFromUI()) {
     68            return $plugins;
     69        }
     70
     71        $shouldHide = !array_key_exists('show_all', $_GET);
     72
     73        if ($shouldHide) {
     74            $hiddenPlugins = [
     75                'logtivity/logtivity.php',
     76            ];
     77
     78            foreach ($hiddenPlugins as $hiddenPlugin) {
     79                unset($plugins[$hiddenPlugin]);
     80            }
     81        }
     82        return $plugins;
     83    }
     84
     85    /**
     86     * @param bool $value
     87     *
     88     * @return bool
     89     */
     90    public function shouldHidePluginFromUI(bool $value = false): bool
     91    {
     92        if (static::$shouldHidePluginFromUI = (new Logtivity_Options())->isPluginHiddenFromUI()) {
     93            return static::$shouldHidePluginFromUI;
     94        }
     95
     96        return $value;
     97    }
     98
     99    /**
     100     * Register the settings page
     101     */
     102    public function registerOptionsPage()
     103    {
     104        if (!apply_filters('logtivity_hide_from_menu', false)) {
     105            add_menu_page(
     106                ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
     107                ($this->options->isWhiteLabelMode() ? 'Logs' : 'Logtivity'),
     108                'manage_options',
     109                ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     110                [$this, 'showLogIndexPage'],
     111                'dashicons-chart-area',
     112                26
     113            );
     114        }
     115
     116        if (!apply_filters('logtivity_hide_settings_page', false)) {
     117            add_submenu_page(
     118                ($this->options->isWhiteLabelMode() ? 'lgtvy-logs' : 'logtivity'),
     119                'Logtivity Settings',
     120                'Settings',
     121                'manage_options',
     122                'logtivity' . '-settings',
     123                [$this, 'showLogtivitySettingsPage']
     124            );
     125        }
     126    }
     127
     128    /**
     129     * Show the admin log index
     130     *
     131     * @return void
     132     */
     133    public function showLogIndexPage()
     134    {
     135        if (!current_user_can('manage_options')) {
     136            wp_die(__('You do not have sufficient permissions to access this page.'));
     137        }
     138
     139        $options = $this->options->getOptions();
     140
     141        echo logtivity_view('log-index', compact('options'));
     142    }
     143
     144    /**
     145     * Show the admin settings template
     146     *
     147     * @return void
     148     */
     149    public function showLogtivitySettingsPage()
     150    {
     151        if (!current_user_can('manage_options')) {
     152            wp_die(__('You do not have sufficient permissions to access this page.'));
     153        }
     154
     155        $options = $this->options->getOptions();
     156
     157        echo logtivity_view('settings', compact('options'));
     158    }
     159
     160    /**
     161     * Update the settings
     162     *
     163     * @return void
     164     */
     165    public function update(): void
     166    {
     167        if (!wp_verify_nonce($_POST['logtivity_update_settings'], 'logtivity_update_settings')) {
     168            wp_safe_redirect($this->settingsPageUrl());
     169            exit;
     170        }
     171
     172        $user = new Logtivity_Wp_User();
     173
     174        if (!$user->hasRole('administrator')) {
     175            wp_safe_redirect($this->settingsPageUrl());
     176            exit;
     177        }
     178
     179        $this->options->update(
     180            [
     181                'logtivity_url_hash' => md5(home_url()),
     182            ],
     183            false
     184        );
     185
     186        delete_transient('dismissed-logtivity-site-url-has-changed-notice');
     187
     188        $this->options->update();
     189
     190        (new Logtivity_Check_For_New_Settings())->checkForNewSettings();
     191
     192        wp_safe_redirect($this->settingsPageUrl());
     193        exit;
     194    }
     195
     196    /**
     197     * @return string
     198     */
     199    public function settingsPageUrl(): string
     200    {
     201        return admin_url('admin.php?page=logtivity-settings');
     202    }
    187203}
    188204
    189 $Logtivity_Admin = new Logtivity_Admin;
    190 
     205new Logtivity_Admin();
  • logtivity/trunk/Admin/Logtivity_Dismiss_Notice_Controller.php

    r3160076 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     26// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     27// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     28
    2529class Logtivity_Dismiss_Notice_Controller
    2630{
    27     protected $notices = [
    28         'logtivity-site-url-has-changed-notice'
    29     ];
     31    /**
     32     * @var string[]
     33     */
     34    protected array $notices = [
     35        'logtivity-site-url-has-changed-notice',
     36    ];
    3037
    31     public function __construct()
    32     {
    33         add_action("wp_ajax_nopriv_logtivity_dismiss_notice", [$this, 'dismiss']);
    34         add_action("wp_ajax_logtivity_dismiss_notice", [$this, 'dismiss']);
    35     }
     38    public function __construct()
     39    {
     40        add_action('wp_ajax_nopriv_logtivity_dismiss_notice', [$this, 'dismiss']);
     41        add_action('wp_ajax_logtivity_dismiss_notice', [$this, 'dismiss']);
     42    }
    3643
    37     public function dismiss()
    38     {
    39         if ( !current_user_can( 'manage_options' ) )  {
    40             wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    41         }
     44    /**
     45     * @return void
     46     */
     47    public function dismiss(): void
     48    {
     49        if (!current_user_can('manage_options')) {
     50            wp_die(__('You do not have sufficient permissions to access this page.'));
     51        }
    4252
    43         if (!in_array($_POST['type'], $this->notices)) {
    44             return;
    45         }
     53        $postType = sanitize_text_field($_POST['postType'] ?? null);
     54        if (in_array($postType, $this->notices)) {
     55            $dismissUntil = sanitize_text_field($_POST['dismissUntil'] ?? null);
    4656
    47         if (isset($_POST['dismiss_until']) && $_POST['dismiss_until']) {
    48             set_transient(
    49                 'dismissed-' . $_POST['type'],
    50                 true,
    51                 (isset($_POST['dismiss_until']) ? intval($_POST['dismiss_until']) : 0)
    52             );
    53         } else {
    54             update_option('dismissed-' . $_POST['type'], true);
    55         }
     57            if ($dismissUntil) {
     58                set_transient(
     59                    'dismissed-' . $postType,
     60                    true,
     61                    (int)$dismissUntil
     62                );
     63            } else {
     64                update_option('dismissed-' . $postType, true);
     65            }
    5666
    57         wp_send_json(['message' => 'success']);
    58     }
     67            wp_send_json(['message' => 'success']);
     68        }
     69    }
    5970}
    6071
    61 new Logtivity_Dismiss_Notice_Controller;
     72new Logtivity_Dismiss_Notice_Controller();
  • logtivity/trunk/Admin/Logtivity_Options.php

    r3194447 r3219912  
    2323 */
    2424
     25// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     26// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
     27
    2528class Logtivity_Options
    2629{
     
    190193    }
    191194
    192     public function urlHash()
    193     {
    194         return $this->getOption('logtivity_url_hash');
    195     }
    196 
    197195    /**
    198196     * @return string
    199197     */
     198    public function urlHash(): string
     199    {
     200        return (string)$this->getOption('logtivity_url_hash');
     201    }
     202
     203    /**
     204     * @return string
     205     */
    200206    public function disabledLogs(): string
    201207    {
     
    203209    }
    204210
    205     public function isWhiteLabelMode()
    206     {
    207         return $this->getOption('logtivity_enable_white_label_mode');
    208     }
    209 
    210     public function isPluginHiddenFromUI()
    211     {
    212         return $this->getOption('logtivity_hide_plugin_from_ui');
    213     }
    214 
    215     public function customPluginName()
    216     {
    217         return $this->getOption('logtivity_custom_plugin_name');
     211    /**
     212     * @return bool
     213     */
     214    public function isWhiteLabelMode(): bool
     215    {
     216        return (bool)$this->getOption('logtivity_enable_white_label_mode');
     217    }
     218
     219    /**
     220     * @return bool
     221     */
     222    public function isPluginHiddenFromUI(): bool
     223    {
     224        return (bool)$this->getOption('logtivity_hide_plugin_from_ui');
     225    }
     226
     227    /**
     228     * @return string
     229     */
     230    public function customPluginName(): string
     231    {
     232        return (string)$this->getOption('logtivity_custom_plugin_name');
    218233    }
    219234
     
    283298    protected function validateSetting(string $setting, $value): bool
    284299    {
    285         $method = $this->rules[$setting] ?? null;
    286         switch ($method) {
    287             case 'is_bool':
    288                 $value = (bool)$value;
    289                 break;
    290 
    291             default:
    292                 if (function_exists($method)) {
    293                     $value = $method($value);
    294 
    295                 } else {
    296                     $value = true;
    297                 }
    298                 break;
    299         }
    300 
    301         return $value;
     300        if (isset($this->rules[$setting])) {
     301            $method = $this->rules[$setting];
     302
     303            if ($method == 'is_bool') {
     304                return $method((bool)$value);
     305            }
     306
     307            return $method($value);
     308        }
     309
     310        return true;
    302311    }
    303312}
  • logtivity/trunk/logtivity.php

    r3194447 r3219912  
    55 * Plugin URI:  https://logtivity.io
    66 * Description: Record activity logs and errors logs across all your WordPress sites.
    7  * Version:     3.1.3
     7 * Version:     3.1.4
    88 * Author:      Logtivity
    99 * Text Domain: logtivity
     
    3131 * along with Logtivity.  If not, see <https://www.gnu.org/licenses/>.
    3232 */
     33
     34// phpcs:disable PSR1.Files.SideEffects.FoundWithSymbols
     35// phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
     36
    3337class Logtivity
    3438{
    35     protected $version = '3.1.3';
     39    /**
     40     * @var string
     41     */
     42    protected string $version = '3.1.4';
    3643
    3744    /**
    3845     * List all classes here with their file paths. Keep class names the same as filenames.
    3946     *
    40      * @var array
    41      */
    42     private $dependancies = [
     47     * @var string[]
     48     */
     49    private array $dependencies = [
    4350        'Helpers/Helpers',
    4451        'Helpers/Logtivity_Wp_User',
     
    6572
    6673    /**
    67      *
    68      *    Log classes
    69      *
    70      */
    71     private $logClasses = [
     74     * @var string[]
     75     */
     76    private array $logClasses = [
    7277        /**
    7378         * Activity logging
     
    8489
    8590    /**
    86      * List all integration dependancies
    87      *
    88      * @var array
    89      */
    90     private $integrationDependancies = [
     91     * List all integration dependencies
     92     *
     93     * @var array[]
     94     */
     95    private array $integrationDependencies = [
    9196        'WP_DLM'                 => [
    9297            'Logs/Download_Monitor/Logtivity_Download_Monitor',
     
    119124    public function __construct()
    120125    {
    121         $this->loadDependancies();
     126        $this->loadDependencies();
    122127
    123128        add_filter('plugin_action_links_' . plugin_basename(__FILE__), [$this, 'addSettingsLinkFromPluginsPage']);
     
    136141    }
    137142
    138     public function loadDependancies()
    139     {
    140         foreach ($this->dependancies as $filePath) {
     143    public function loadDependencies()
     144    {
     145        foreach ($this->dependencies as $filePath) {
    141146            $this->loadFile($filePath);
    142147        }
     
    149154            $this->maybeLoadLogClasses();
    150155
    151             $this->loadIntegrationDependancies();
     156            $this->loadIntegrationDependencies();
    152157        });
    153158    }
     
    163168     * @return bool
    164169     */
    165     public function defaultLoggingDisabled()
    166     {
    167         return (new Logtivity_Options)->getOption('logtivity_disable_default_logging');
     170    public function defaultLoggingDisabled(): bool
     171    {
     172        return (bool)(new Logtivity_Options())->getOption('logtivity_disable_default_logging');
    168173    }
    169174
     
    175180    }
    176181
    177     public function loadIntegrationDependancies()
    178     {
    179         foreach ($this->integrationDependancies as $key => $value) {
     182    public function loadIntegrationDependencies()
     183    {
     184        foreach ($this->integrationDependencies as $key => $value) {
    180185            if (class_exists($key)) {
    181186                foreach ($value as $filePath) {
     
    191196    }
    192197
    193     public static function logError($error)
     198    /**
     199     * @param array $error
     200     *
     201     * @return Logtivity_Error_Logger
     202     */
     203    public static function logError(array $error): Logtivity_Error_Logger
    194204    {
    195205        return new Logtivity_Error_Logger($error);
    196206    }
    197207
    198     public function upgradeProcessComplete($upgrader_object, $options)
    199     {
    200         if ($options['type'] != 'plugin') {
    201             return;
    202         }
    203 
    204         if ($options['action'] == 'update') {
    205             return $this->setLogtivityToLoadFirst();
    206         }
    207     }
    208 
    209     public function setLogtivityToLoadFirst()
     208    /**
     209     * @param $upgraderObject
     210     * @param $options
     211     *
     212     * @return null|void
     213     */
     214    public function upgradeProcessComplete($upgraderObject, $options)
     215    {
     216        $type   = $options['type'] ?? null;
     217        $action = $options['action'] ?? null;
     218
     219        if ($type == 'plugin' && $action == 'update') {
     220            $this->setLogtivityToLoadFirst();
     221        }
     222    }
     223
     224    /**
     225     * @return void
     226     */
     227    public function setLogtivityToLoadFirst(): void
    210228    {
    211229        $path = str_replace(WP_PLUGIN_DIR . '/', '', __FILE__);
     
    220238    }
    221239
    222     public function addSettingsLinkFromPluginsPage($links)
     240    /**
     241     * @param array $links
     242     *
     243     * @return string[]
     244     */
     245    public function addSettingsLinkFromPluginsPage(array $links): array
    223246    {
    224247        if (apply_filters('logtivity_hide_settings_page', false)) {
     
    226249        }
    227250
    228         $settings_links = [
    229             '<a href="' . admin_url('admin.php?page=logtivity-settings') . '">Settings</a>',
    230         ];
    231 
    232         return array_merge($settings_links, $links);
    233     }
    234 
    235     public function activated()
     251        return array_merge(
     252            [
     253                sprintf('<a href="%s">Settings</a>', admin_url('admin.php?page=logtivity-settings')),
     254            ],
     255            $links
     256        );
     257    }
     258
     259    /**
     260     * @return void
     261     */
     262    public function activated(): void
    236263    {
    237264        if (apply_filters('logtivity_hide_settings_page', false)) {
     
    242269    }
    243270
    244     public function welcomeMessage()
     271    /**
     272     * @return void
     273     */
     274    public function welcomeMessage(): void
    245275    {
    246276        if (get_transient('logtivity-welcome-notice')) {
     
    251281    }
    252282
    253     public function checkForSiteUrlChange()
    254     {
    255         if (!current_user_can('manage_options')) {
    256             return;
    257         }
    258 
    259         if (logtivity_has_site_url_changed() && !get_transient('dismissed-logtivity-site-url-has-changed-notice')) {
     283    /**
     284     * @return void
     285     */
     286    public function checkForSiteUrlChange(): void
     287    {
     288        if (
     289            current_user_can('manage_options')
     290            && logtivity_has_site_url_changed()
     291            && !get_transient('dismissed-logtivity-site-url-has-changed-notice')
     292        ) {
    260293            echo logtivity_view('site-url-changed-notice');
    261294        }
    262295    }
    263296
    264     public function loadScripts()
     297    /**
     298     * @return void
     299     */
     300    public function loadScripts(): void
    265301    {
    266302        wp_enqueue_style(
     
    285321}
    286322
    287 $logtivity = new Logtivity;
     323$logtivity = new Logtivity();
  • logtivity/trunk/readme.txt

    r3194447 r3219912  
    55Requires at least: 4.7
    66Tested up to: 6.6.2
    7 Stable tag: 3.1.3
     7Stable tag: 3.1.4
    88Requires PHP: 7.4
    99License: GPLv2 or later
     
    262262
    263263== Changelog ==
     264
     265= 3.1.4 =
     266
     267_Release Date - TBD
     268
     269* Fix: Deprecation warning, #50
     270* Fix: Unable to uncheck settings
    264271
    265272= 3.1.3 =
Note: See TracChangeset for help on using the changeset viewer.