public function log($connector, $message, $args, $object_id, $contexts, $user_id = null) { global $wpdb; if (is_null($user_id)) { $user_id = get_current_user_id(); } require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php'; $user = new WP_User($user_id); $roles = get_option($wpdb->get_blog_prefix() . 'user_roles'); if (!isset($args['author_meta'])) { $args['author_meta'] = array('user_email' => $user->user_email, 'display_name' => defined('WP_CLI') && empty($user->display_name) ? 'WP-CLI' : $user->display_name, 'user_login' => $user->user_login, 'user_role_label' => !empty($user->roles) ? $roles[$user->roles[0]]['name'] : null, 'agent' => MainWP_WP_Stream_Author::get_current_agent()); if (defined('WP_CLI') && function_exists('posix_getuid')) { $uid = posix_getuid(); $user_info = posix_getpwuid($uid); $args['author_meta']['system_user_id'] = $uid; $args['author_meta']['system_user_name'] = $user_info['name']; } } // Remove meta with null values from being logged $meta = array_filter($args, function ($var) { return !is_null($var); }); $recordarr = array('object_id' => $object_id, 'site_id' => is_multisite() ? get_current_site()->id : 1, 'blog_id' => apply_filters('blog_id_logged', is_network_admin() ? 0 : get_current_blog_id()), 'author' => $user_id, 'author_role' => !empty($user->roles) ? $user->roles[0] : null, 'created' => current_time('mysql', 1), 'summary' => vsprintf($message, $args), 'parent' => self::$instance->prev_record, 'connector' => $connector, 'contexts' => $contexts, 'meta' => $meta, 'ip' => mainwp_wp_stream_filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP)); $record_id = MainWP_WP_Stream_DB::get_instance()->insert($recordarr); return $record_id; }
public static function get_instance() { if (!self::$instance) { $class = __CLASS__; self::$instance = new $class(); } return self::$instance; }
public static function uninstall_plugin() { global $wpdb; check_ajax_referer('stream_nonce', 'mainwp_wp_stream_nonce'); if (current_user_can(self::SETTINGS_CAP)) { // Prevent stream action from being fired on plugin remove_action('deactivate_plugin', array('MainWP_WP_Stream_Connector_Installer', 'callback'), null); // Plugin is being uninstalled from only one of the multisite blogs if (is_multisite() && !is_plugin_active_for_network(MAINWP_WP_STREAM_PLUGIN)) { $blog_id = get_current_blog_id(); $wpdb->query("DELETE FROM {$wpdb->base_prefix}stream WHERE blog_id = {$blog_id}"); delete_option(plugin_basename(MAINWP_WP_STREAM_DIR) . '_db'); delete_option(MainWP_WP_Stream_Install::KEY); delete_option(MainWP_WP_Stream_Settings::KEY); } else { // Delete all tables foreach (MainWP_WP_Stream_DB::get_instance()->get_table_names() as $table) { $wpdb->query("DROP TABLE {$table}"); } // Delete database options if (is_multisite()) { $blogs = wp_get_sites(); foreach ($blogs as $blog) { switch_to_blog($blog['blog_id']); delete_option(plugin_basename(MAINWP_WP_STREAM_DIR) . '_db'); delete_option(MainWP_WP_Stream_Install::KEY); delete_option(MainWP_WP_Stream_Settings::KEY); } restore_current_blog(); } // Delete database option delete_site_option(plugin_basename(MAINWP_WP_STREAM_DIR) . '_db'); delete_site_option(MainWP_WP_Stream_Install::KEY); delete_site_option(MainWP_WP_Stream_Settings::KEY); delete_site_option(MainWP_WP_Stream_Settings::DEFAULTS_KEY); delete_site_option(MainWP_WP_Stream_Settings::NETWORK_KEY); delete_site_option('dashboard_mainwp_stream_activity_options'); } // Delete scheduled cron event hooks wp_clear_scheduled_hook('stream_auto_purge'); // Deprecated hook wp_clear_scheduled_hook('mainwp_wp_stream_auto_purge'); // Deactivate the plugin deactivate_plugins(plugin_basename(MAINWP_WP_STREAM_DIR) . '/stream.php'); // Redirect to plugin page wp_redirect(add_query_arg(array('deactivate' => true), self_admin_url('plugins.php'))); exit; } else { wp_die("You don't have sufficient privileges to do this action."); } }