Plugin Directory

Changeset 2805342


Ignore:
Timestamp:
10/26/2022 08:38:31 PM (3 years ago)
Author:
logtivity
Message:

Release 2.0

Location:
logtivity
Files:
72 added
10 edited

Legend:

Unmodified
Added
Removed
  • logtivity/trunk/Admin/Logtivity_Options.php

    r2744100 r2805342  
    2222        'logtivity_global_disabled_logs',
    2323        'logtivity_enable_white_label_mode',
     24        'logtivity_disable_error_logging',
     25        'logtivity_disabled_error_levels',
    2426    ];
    2527
     
    124126    {
    125127        return $this->getOption('logtivity_should_log_username');
     128    }
     129
     130    /**
     131     * Get the error levels that are disabled
     132     *
     133     * @return array
     134     */
     135    public function disabledErrorLevels()
     136    {
     137        $result = $this->getOption('logtivity_disabled_error_levels');
     138
     139        if (is_array($result)) {
     140            return array_keys(array_filter($result));
     141        }
     142
     143        return [];
    126144    }
    127145
  • logtivity/trunk/Helpers/Helpers.php

    r2682104 r2805342  
    8181    return $hash !== md5(home_url());
    8282}
     83
     84function logtivity_get_error_levels()
     85{
     86    return [
     87        E_ALL => 'E_ALL',
     88        E_USER_DEPRECATED => 'E_USER_DEPRECATED',
     89        E_DEPRECATED => 'E_DEPRECATED',
     90        E_RECOVERABLE_ERROR => 'E_RECOVERABLE_ERROR',
     91        E_STRICT => 'E_STRICT',
     92        E_USER_NOTICE => 'E_USER_NOTICE',
     93        E_USER_WARNING => 'E_USER_WARNING',
     94        E_USER_ERROR => 'E_USER_ERROR',
     95        E_COMPILE_WARNING => 'E_COMPILE_WARNING',
     96        E_COMPILE_ERROR => 'E_COMPILE_ERROR',
     97        E_CORE_WARNING => 'E_CORE_WARNING',
     98        E_CORE_ERROR => 'E_CORE_ERROR',
     99        E_NOTICE => 'E_NOTICE',
     100        E_PARSE => 'E_PARSE',
     101        E_WARNING => 'E_WARNING',
     102        E_ERROR => 'E_ERROR',
     103    ];
     104}
  • logtivity/trunk/Helpers/Logtivity_Wp_User.php

    r2737295 r2805342  
    77    public function __construct($user = null, $field = 'ID')
    88    {
    9         if (is_null($user))
    10         {
    11             $this->user = wp_get_current_user();
    12         }
    13         elseif ($user instanceof WP_User)
    14         {
     9        if (is_null($user)) {
     10            if (function_exists('wp_get_current_user')) {
     11                $this->user = wp_get_current_user();
     12            }
     13        } elseif ($user instanceof WP_User) {
    1514            $this->user = $user;
    16         }
    17         else
    18         {
    19             $this->user = get_user_by($field, $user);
     15        } else {
     16            if (function_exists('get_user_by')) {
     17                $this->user = get_user_by($field, $user);
     18            }
    2019        }
    2120    }
     
    4241    public function id()
    4342    {
     43        if (!$this->user) {
     44            return;
     45        }
     46
    4447        if ($this->user->ID == 0) {
    4548            return;
     
    5154    public function userLogin()
    5255    {
     56        if (!$this->user) {
     57            return;
     58        }
     59
    5360        if ($this->user->ID == 0) {
    5461            return;
     
    6067    public function email()
    6168    {
     69        if (!$this->user) {
     70            return;
     71        }
     72
    6273        return $this->user->user_email;
    6374    }
     
    6576    public function name()
    6677    {
     78        if (!$this->user) {
     79            return;
     80        }
     81
    6782        return $this->firstName() . ' ' . $this->lastName();
    6883    }
     
    7085    public function firstName()
    7186    {
     87        if (!$this->user) {
     88            return;
     89        }
     90
    7291        return $this->meta('first_name');
    7392    }
     
    7594    public function lastName()
    7695    {
     96        if (!$this->user) {
     97            return;
     98        }
     99
    77100        return $this->meta('last_name');
    78101    }
     
    80103    public function displayName()
    81104    {
     105        if (!$this->user) {
     106            return;
     107        }
     108
    82109        return $this->user->display_name;
    83110    }
     
    85112    public function niceName()
    86113    {
     114        if (!$this->user) {
     115            return;
     116        }
     117
    87118        return $this->user->user_nicename;
    88119    }
     
    90121    public function profileLink()
    91122    {
     123        if (!$this->user) {
     124            return;
     125        }
     126
    92127        return add_query_arg( 'user_id', $this->id(), self_admin_url( 'user-edit.php' ) );
    93128    }
     
    102137    public function meta($meta_key, $returnString = true)
    103138    {
     139        if (!$this->user) {
     140            return;
     141        }
     142
    104143        $meta = get_user_meta($this->user->ID, $meta_key, $returnString);
    105144
     
    128167    public function isLoggedIn()
    129168    {
     169        if (!$this->user) {
     170            return;
     171        }
     172
    130173        if ($this->user->ID == 0) {
    131174            return false;
     
    144187    public function hasRole($role)
    145188    {
     189        if (!$this->user) {
     190            return;
     191        }
     192
    146193        if ( in_array($role, $this->getRoles()) ) {
    147194            return true;
     
    158205    public function getRoles()
    159206    {
     207        if (!$this->user) {
     208            return;
     209        }
     210
    160211        return $this->user->roles;
    161212    }
     
    168219    public function getRole()
    169220    {
     221        if (!$this->user) {
     222            return;
     223        }
     224       
    170225        foreach ($this->getRoles() as $role) {
    171226            return $role;
  • logtivity/trunk/Logs/Core/Logtivity_Core.php

    r2744371 r2805342  
    8080    public function optionUpdated($option, $old_value, $value)
    8181    {
     82        if ($this->getRequestMethod() == 'GET') {
     83            return;
     84        }
     85       
    8286        if (!is_admin() || $old_value == $value) {
    8387            return;
     
    9397            'logtivity_global_disabled_logs',
    9498            'logtivity_enable_white_label_mode',
     99            'logtivity_disabled_error_levels',
     100            'logtivity_disable_error_logging',
    95101            'recently_activated',
    96102            'active_plugins',
    97103            'jp_sync_last_success_sync',
     104            'jp_sync_retry_after_sync',
     105            'postman_state',
    98106            'jetpack_sync_settings_dedicated_sync_enabled',
    99107            'jetpack_plugin_api_action_links',
     
    119127            '_edd_table_check',
    120128            'woocommerce_marketplace_suggestions',
     129            'recently_edited',
     130            'rewrite_rules',
     131            'limit_login_retries',
     132            'post_views_count',
    121133        ];
    122134
     
    149161    }
    150162
     163    private function getRequestMethod()
     164    {
     165        return $_SERVER['REQUEST_METHOD'] ?? null;
     166    }
     167
    151168    public function permalinksUpdated($old_permalink_structure, $permalink_structure)
    152169    {
  • logtivity/trunk/Services/Logtivity_Api.php

    r2723235 r2805342  
    1616     */
    1717    public $waitForResponse = true;
     18
     19    /**
     20     * Definitely don't wait for a response.
     21     *
     22     * @var boolean
     23     */
     24    public $asyncOverride = false;
    1825
    1926    /**
     
    5663    }
    5764
     65    public function async()
     66    {
     67        $this->asyncOverride = true;
     68
     69        return $this;
     70    }
     71
    5872    /**
    5973     * Make a request to the Logtivity API
     
    8296        }
    8397
    84         $shouldLogLatestResponse = $this->waitForResponse || $this->options->shouldLogLatestResponse();
     98        $shouldLogLatestResponse = !$this->asyncOverride && ($this->waitForResponse || $this->options->shouldLogLatestResponse());
    8599
    86100        $response = wp_remote_post($this->getEndpoint($url), [
     
    116130                        'logtivity_global_disabled_logs' => $body['settings']['disabled_logs'],
    117131                        'logtivity_enable_white_label_mode' => $body['settings']['enable_white_label_mode'],
     132                        'logtivity_disabled_error_levels' => $body['settings']['disabled_error_levels'],
     133                        'logtivity_disable_error_logging' => $body['settings']['disable_error_logging'],
    118134                    ],
    119135                    false
  • logtivity/trunk/Services/Logtivity_Logger.php

    r2707715 r2805342  
    33class Logtivity_Logger extends Logtivity_Api
    44{
     5    use Logtivity_User_Logger_Trait;
     6   
    57    /**
    68     * Can this instance log something
     
    911     */
    1012    public $active = true;
    11 
    12     /**
    13      * Logtivity_Wp_User
    14      *
    15      * @var object
    16      */
    17     public $user;
    1813
    1914    /**
     
    106101
    107102    /**
    108      * Set the user for the current log instance
    109      *
    110      * @param integer $user_id
    111      */
    112     public function setUser($user_id)
    113     {
    114         $this->user = new Logtivity_Wp_User($user_id);
    115 
    116         return $this;
    117     }
    118 
    119     /**
    120103     * Set the action string before sending
    121104     *
     
    189172     * @param mixed  $value
    190173     */
    191     public function addMetaIf($condition = false, $key, $value)
     174    public function addMetaIf($condition, $key, $value)
    192175    {
    193176        if ($condition) {
     
    275258
    276259    /**
    277      * Protected function to get the User ID if the user is logged in
    278      *
    279      * @return mixed string|integer
    280      */
    281     protected function getUserID()
    282     {
    283         if (!$this->options->shouldStoreUserId()) {
    284             return;
    285         }
    286 
    287         if (!$this->user->isLoggedIn()) {
    288             return;
    289         }
    290 
    291         return $this->user->id();
    292     }
    293 
    294     /**
    295      * Maybe get the users IP address
    296      *
    297      * @return string|false
    298      */
    299     protected function maybeGetUsersIp()
    300     {
    301         if (!$this->options->shouldStoreIp()) {
    302             return;
    303         }
    304 
    305         if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
    306            
    307             //check ip from share internet
    308             return $_SERVER['HTTP_CLIENT_IP'];
    309 
    310         } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
    311        
    312             //to check ip is pass from proxy
    313             return $_SERVER['HTTP_X_FORWARDED_FOR'];
    314 
    315         } else {
    316        
    317             return $_SERVER['REMOTE_ADDR'];
    318 
    319         }
    320     }
    321 
    322     /**
    323260     * Build the user meta array
    324261     *
     
    363300        return $this->addUserMeta('Profile Link', $profileLink);
    364301    }
    365 
    366     /**
    367      * Maybe get the users username
    368      *
    369      * @return string|false
    370      */
    371     protected function maybeGetUsersUsername()
    372     {
    373         if (!$this->options->shouldStoreUsername()) {
    374             return null;
    375         }
    376 
    377         if (!$this->user->isLoggedIn()) {
    378             return;
    379         }
    380 
    381         return $this->user->userLogin();
    382     }
    383 
    384302}
  • logtivity/trunk/logtivity.php

    r2744371 r2805342  
    55 * Plugin URI:  https://logtivity.io
    66 * Description: Dedicated Event Monitoring for WordPress using Logtivity.io.
    7  * Version:     1.20.1
     7 * Version:     2.0
    88 * Author:      Logtivity
    99 * Text Domain: logtivity
     
    1212class Logtivity
    1313{
    14     protected $version = '1.20.1';
     14    protected $version = '2.0';
    1515
    1616    /**
     
    2626        'Admin/Logtivity_Options',
    2727        'Admin/Logtivity_Admin',
     28        'Services/Logtivity_User_Logger_Trait',
    2829        'Services/Logtivity_Api',
    2930        'Services/Logtivity_Logger',
     
    3233        'Logs/Logtivity_Abstract_Logger',
    3334        'Services/Logtivity_Check_For_Disabled_Individual_Logs',
     35        /**
     36         * Error logging
     37         */
     38        'Errors/Logtivity_Stack_Trace_Snippet',
     39        'Errors/Logtivity_Stack_Trace',
     40        'Errors/Logtivity_Error_Logger',
     41        'Errors/Logtivity_Error_Log',
    3442    ];
    3543
     
    4048     */
    4149    private $logClasses = [
     50        /**
     51         * Activity logging
     52         */
    4253        'Logs/Core/Logtivity_Post',
    4354        'Logs/Core/Logtivity_User',
     
    92103        register_activation_hook( __FILE__, [$this, 'activated']);
    93104
     105        add_action( 'upgrader_process_complete', [$this, 'upgradeProcessComplete'], 10, 2);
     106
     107        add_action( 'activated_plugin', [$this, 'setLogtivityToLoadFirst']);
     108
    94109        add_action( 'admin_notices', [$this, 'welcomeMessage']);
    95110       
     
    99114    }
    100115
     116    public function upgradeProcessComplete( $upgrader_object, $options )
     117    {
     118        if ( $options['type'] != 'plugin' ) {
     119            return;
     120        }
     121
     122        if ($options['action'] == 'update') {
     123            return $this->setLogtivityToLoadFirst();
     124        }
     125    }
     126
    101127    public static function log($action = null, $meta = null, $user_id = null)
    102128    {
    103129        return Logtivity_Logger::log($action, $meta, $user_id);
     130    }
     131
     132    public static function logError($error)
     133    {
     134        return new Logtivity_Error_Logger($error);
    104135    }
    105136
     
    180211    }
    181212
     213    public function setLogtivityToLoadFirst()
     214    {
     215        $path = str_replace( WP_PLUGIN_DIR . '/', '', __FILE__ );
     216
     217        if ( $plugins = get_option( 'active_plugins' ) ) {
     218            if ( $key = array_search( $path, $plugins ) ) {
     219                array_splice( $plugins, $key, 1 );
     220                array_unshift( $plugins, $path );
     221                update_option( 'active_plugins', $plugins );
     222            }
     223        }
     224    }
     225
    182226    public function welcomeMessage()
    183227    {
  • logtivity/trunk/readme.md

    r2744371 r2805342  
    55Requires at least: 4.7
    66Tested up to: 6.0
    7 Stable tag: 1.20.1
     7Stable tag: 2.0
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    226226
    227227== Changelog ==
     228
     229= 2.0 =
     230
     231_Release Date – Wednesday 26th October 2022_
     232
     233* Add error logging
     234* Refine Option meta update logging by only logging updates done via a POST request. This avoids logging of less useful updates such as plugins setting last_check/synced timestamps that don't need to be logged.
    228235
    229236= 1.20.1 =
  • logtivity/trunk/readme.txt

    r2744371 r2805342  
    55Requires at least: 4.7
    66Tested up to: 6.0
    7 Stable tag: 1.20.1
     7Stable tag: 2.0
    88Requires PHP: 7.0
    99License: GPLv2 or later
     
    226226
    227227== Changelog ==
     228
     229= 2.0 =
     230
     231_Release Date – Wednesday 26th October 2022_
     232
     233* Add error logging.
     234* Refine Option meta update logging by only logging updates done via a POST request. This avoids logging of less useful updates such as plugins setting last_check/synced timestamps that don't need to be logged.
    228235
    229236= 1.20.1 =
  • logtivity/trunk/views/settings.php

    r2737295 r2805342  
    181181
    182182                <?php if ($latest_response['response']): ?>
    183                     <code style="display: block; padding: 20px;">
     183                    <code style="display: block; padding: 20px; overflow-x: auto;">
    184184                           
    185185                        <?php echo sanitize_text_field($latest_response['response']); ?>
Note: See TracChangeset for help on using the changeset viewer.