From fda53325dc4eb7d46f7ba673d606d7be9a24ff8f Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 14 Jan 2014 13:49:38 -0600 Subject: [PATCH 001/123] Issue 65 Enable stream network - Added check for is_multisite() to db $prefix definition to use base_prefix - Updated install $sql to include blog_id column - Added update function to run install() and alter the column order - Added site_id and blog_id values to query defaults - Run install check method on plugins_loaded. plugin_activation_hook doesn't run when updating --- includes/db-actions.php | 2 +- includes/install.php | 13 +++++++++++-- includes/log.php | 1 + includes/query.php | 18 +++++++++++++++--- stream.php | 5 +++-- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/includes/db-actions.php b/includes/db-actions.php index 3d08e6dbd..8f7021853 100644 --- a/includes/db-actions.php +++ b/includes/db-actions.php @@ -13,7 +13,7 @@ class WP_Stream_DB { public function __construct() { global $wpdb; // Allow devs to alter the tables prefix, default to base_prefix - $prefix = apply_filters( 'wp_stream_db_tables_prefix', $wpdb->prefix ); + $prefix = apply_filters( 'wp_stream_db_tables_prefix', is_multisite() ? $wpdb->base_prefix : $wpdb->prefix ); self::$table = $prefix . 'stream'; self::$table_meta = $prefix . 'stream_meta'; self::$table_context = $prefix . 'stream_context'; diff --git a/includes/install.php b/includes/install.php index da794910d..5aa0d86b0 100644 --- a/includes/install.php +++ b/includes/install.php @@ -51,6 +51,7 @@ public static function install() { $sql = "CREATE TABLE {$prefix}stream ( ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, site_id bigint(20) unsigned NOT NULL DEFAULT '1', + blog_id bigint(20) unsigned NOT NULL DEFAULT '1', object_id bigint(20) unsigned NULL, author bigint(20) unsigned NOT NULL DEFAULT '0', summary longtext NOT NULL, @@ -61,6 +62,7 @@ public static function install() { ip varchar(20) NOT NULL, PRIMARY KEY (ID), KEY site_id (site_id), + KEY blog_id (blog_id), KEY parent (parent), KEY author (author), KEY created (created) @@ -96,8 +98,15 @@ public static function install() { dbDelta( $sql ); } - public static function update() { - // Reserved for future + public static function update( $db_version, $current ) { + global $wpdb; + $prefix = self::$table_prefix; + + self::install(); + + // Manually alter the column order. Not possible using dbDelta alone. + $v = $wpdb->query( "ALTER TABLE {$prefix}stream MODIFY blog_id bigint(20) AFTER site_id" ); + } } diff --git a/includes/log.php b/includes/log.php index f4a1182e5..b7f0d5fce 100644 --- a/includes/log.php +++ b/includes/log.php @@ -56,6 +56,7 @@ public function log( $connector, $message, $args, $object_id, $contexts, $user_i $recordarr = array( 'object_id' => $object_id, + 'blog_id' => get_current_blog_id(), 'author' => $user_id, 'created' => current_time( 'mysql', 1 ), 'summary' => vsprintf( $message, $args ), diff --git a/includes/query.php b/includes/query.php index ae5fa4b49..6e2e5755b 100644 --- a/includes/query.php +++ b/includes/query.php @@ -31,6 +31,8 @@ public function query( $args ) { 'type' => 'stream', 'object_id' => null, 'ip' => null, + 'site_id' => get_current_site()->id, + 'blog_id' => get_current_blog_id(), // Author param 'author' => null, // Date-based filters @@ -53,7 +55,6 @@ public function query( $args ) { // Fields selection 'fields' => '', ); - $args = wp_parse_args( $args, $defaults ); $args = apply_filters( 'stream_query_args', $args ); @@ -81,6 +82,17 @@ public function query( $args ) { $where .= $wpdb->prepare( " AND $wpdb->stream.ip = %s", filter_var( $args['ip'], FILTER_VALIDATE_IP ) ); } + if ( is_multisite() ) { + if ( $args['site_id'] ) { + $where .= $wpdb->prepare( " AND $wpdb->stream.site_id = %d", $args['site_id'] ); + } + + if ( $args['blog_id'] ) { + $where .= $wpdb->prepare( " AND $wpdb->stream.blog_id = %d", $args['blog_id'] ); + } + + } + if ( $args['search'] ) { $where .= $wpdb->prepare( " AND $wpdb->stream.summary LIKE %s", "%{$args['search']}%" ); } @@ -178,7 +190,7 @@ public function query( $args ) { if ( in_array( $orderby, - array( 'ID', 'site_id', 'object_id', 'author', 'summary', 'visibility', 'parent', 'type', 'created' ) + array( 'ID', 'blog_id', 'object_id', 'author', 'summary', 'visibility', 'parent', 'type', 'created' ) ) ) { $orderby = $wpdb->stream . '.' . $orderby; } @@ -217,7 +229,7 @@ public function query( $args ) { WHERE 1=1 $where $orderby $limits"; - + var_dump( $sql ); if ( ! empty( $fields ) ) { $results = $wpdb->get_col( $sql ); } else { diff --git a/stream.php b/stream.php index e7ac423e5..ae478115e 100644 --- a/stream.php +++ b/stream.php @@ -3,7 +3,7 @@ * Plugin Name: Stream * Plugin URI: http://wordpress.org/plugins/stream/ * Description: Stream tracks logged-in user activity so you can monitor every change made on your WordPress site in beautifully organized detail. All activity is organized by context, action and IP address for easy filtering. Developers can extend Stream with custom connectors to log any kind of action. - * Version: 1.0 + * Version: 1.1 * Author: X-Team * Author URI: http://x-team.com/wordpress/ * License: GPLv2+ @@ -37,7 +37,7 @@ class WP_Stream { * * @const string */ - const VERSION = '1.0'; + const VERSION = '1.1'; /** * Hold Stream instance @@ -221,3 +221,4 @@ public static function get_instance() { $GLOBALS['wp_stream'] = WP_Stream::get_instance(); register_activation_hook( __FILE__, array( 'WP_Stream', 'install' ) ); +add_action( 'plugins_loaded', array( 'WP_Stream', 'install' ) ); From cefde8e9bb1cdac9d7aad27761158475ee1882ca Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 14 Jan 2014 14:03:30 -0600 Subject: [PATCH 002/123] Network logging - Added blog_id and site_id to fields array - Added blog_id and site_id values to $recordarr - Removed debugging statement from query --- includes/db-actions.php | 2 +- includes/log.php | 1 + includes/query.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/db-actions.php b/includes/db-actions.php index 8f7021853..bbd7a6c96 100644 --- a/includes/db-actions.php +++ b/includes/db-actions.php @@ -57,7 +57,7 @@ public function insert( $recordarr ) { return; } - $fields = array( 'object_id', 'author', 'created', 'summary', 'parent', 'visibility', 'ip' ); + $fields = array( 'object_id', 'site_id', 'blog_id', 'author', 'created', 'summary', 'parent', 'visibility', 'ip' ); $data = array_intersect_key( $recordarr, array_flip( $fields ) ); $data = array_filter( $data ); diff --git a/includes/log.php b/includes/log.php index b7f0d5fce..ef77b05c6 100644 --- a/includes/log.php +++ b/includes/log.php @@ -56,6 +56,7 @@ public function log( $connector, $message, $args, $object_id, $contexts, $user_i $recordarr = array( 'object_id' => $object_id, + 'site_id' => get_current_site()->id, 'blog_id' => get_current_blog_id(), 'author' => $user_id, 'created' => current_time( 'mysql', 1 ), diff --git a/includes/query.php b/includes/query.php index 6e2e5755b..8c7f762fa 100644 --- a/includes/query.php +++ b/includes/query.php @@ -229,7 +229,7 @@ public function query( $args ) { WHERE 1=1 $where $orderby $limits"; - var_dump( $sql ); + if ( ! empty( $fields ) ) { $results = $wpdb->get_col( $sql ); } else { From 46526d8ef36edff2e2301b9bdfa671b8b8fac6cb Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 14 Jan 2014 16:22:47 -0600 Subject: [PATCH 003/123] Network Admin List Table - Add stream page to network admin screen if if plugin is network activated - Add WP_STREAM_PLUGIN const to use for checking if plugin is network activated --- includes/admin.php | 9 ++++++++- stream.php | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/includes/admin.php b/includes/admin.php index 7e9c12235..1e5d26189 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -29,6 +29,10 @@ public static function load() { // Register settings page add_action( 'admin_menu', array( __CLASS__, 'register_menu' ) ); + // Register settings page for network admin + if ( is_multisite() ) { + add_action( 'network_admin_menu', array( __CLASS__, 'register_menu' ) ); + } // Plugin action links add_filter( 'plugin_action_links', array( __CLASS__, 'plugin_action_links' ), 10, 2 ); @@ -80,9 +84,12 @@ public static function admin_notices() { * Register menu page * * @action admin_menu - * @return void + * @return bool|void */ public static function register_menu() { + if ( is_network_admin() && ! is_plugin_active_for_network( WP_STREAM_PLUGIN ) ) + return false; + self::$screen_id['main'] = add_menu_page( __( 'Stream', 'stream' ), __( 'Stream', 'stream' ), diff --git a/stream.php b/stream.php index ae478115e..5df4428ee 100644 --- a/stream.php +++ b/stream.php @@ -62,6 +62,7 @@ class WP_Stream { * Class constructor */ private function __construct() { + define( 'WP_STREAM_PLUGIN', plugin_basename( __FILE__ ) ); define( 'WP_STREAM_DIR', plugin_dir_path( __FILE__ ) ); define( 'WP_STREAM_URL', plugin_dir_url( __FILE__ ) ); define( 'WP_STREAM_INC_DIR', WP_STREAM_DIR . 'includes/' ); From e589ede09ae48562eb7456437a963d2557646ec1 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 14 Jan 2014 16:46:24 -0600 Subject: [PATCH 004/123] Network Admin Screen - Replaced all occurrences of admin_url() with network_admin_url() if is_network_admin() returns true - Updated query args for blog_id filter --- includes/admin.php | 6 +++--- includes/list-table.php | 40 +++++++++++++++++++++++++++++++++++----- includes/query.php | 19 ++++++++----------- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/includes/admin.php b/includes/admin.php index 1e5d26189..4ffee92d8 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -217,7 +217,7 @@ public static function admin_menu_css() { */ public static function plugin_action_links( $links, $file ) { if ( plugin_basename( WP_STREAM_DIR . 'stream.php' ) === $file ) { - $admin_page_url = add_query_arg( array( 'page' => self::SETTINGS_PAGE_SLUG ), admin_url( self::ADMIN_PARENT_PAGE ) ); + $admin_page_url = add_query_arg( array( 'page' => self::SETTINGS_PAGE_SLUG ), is_network_admin() ? network_admin_url( self::ADMIN_PARENT_PAGE ) : admin_url( self::ADMIN_PARENT_PAGE ) ); $links[] = sprintf( '%s', esc_url( $admin_page_url ), esc_html__( 'Settings', 'stream' ) ); $url = add_query_arg( @@ -300,7 +300,7 @@ public static function wp_ajax_reset() { check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' ); if ( current_user_can( self::SETTINGS_CAP ) ) { self::erase_stream_records(); - wp_redirect( add_query_arg( array( 'page' => 'wp_stream_settings', 'message' => 'data_erased' ), admin_url( 'admin.php' ) ) ); + wp_redirect( add_query_arg( array( 'page' => 'wp_stream_settings', 'message' => 'data_erased' ), is_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ) ) ); exit; } else { wp_die( "You don't have sufficient priviledges to do this action." ); @@ -485,7 +485,7 @@ public static function dashboard_stream_activity_contents() { $records_link = add_query_arg( array( 'page' => self::RECORDS_PAGE_SLUG ), - admin_url( self::ADMIN_PARENT_PAGE ) + is_network_admin() ? network_admin_url( self::ADMIN_PARENT_PAGE ) : admin_url( self::ADMIN_PARENT_PAGE ) ); $author_link = add_query_arg( diff --git a/includes/list-table.php b/includes/list-table.php index 734b8ade8..cc76ae1b4 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -23,6 +23,10 @@ function __construct( $args = array() ) { add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 ); add_filter( 'screen_settings', array( __CLASS__, 'live_update_checkbox' ), 10, 2 ); set_screen_options(); + + if ( is_network_admin() ) { + add_filter( 'wp_stream_list_table_columns', array( $this, 'network_admin_columns' ) ); + } } function extra_tablenav( $which ) { @@ -31,6 +35,11 @@ function extra_tablenav( $which ) { } } + function network_admin_columns( $columns ) { + $columns['blog_id'] = __( 'Blog', 'stream' ); + return $columns; + } + function get_columns(){ return apply_filters( 'wp_stream_list_table_columns', @@ -105,7 +114,7 @@ function get_records() { 'connector', 'context', 'action', 'author', 'object_id', 'search', 'date', 'date_from', 'date_to', - 'record__in', + 'record__in', 'blog_id' ); foreach ( $allowed_params as $param ) { @@ -164,7 +173,7 @@ function column_default( $item, $column_name ) { $author_role = isset( $user->roles[0] ) ? $wp_roles->role_names[$user->roles[0]] : null; $out = sprintf( '%s %s
%s', - add_query_arg( array( 'author' => $author_ID ), admin_url( 'admin.php?page=wp_stream' ) ), + add_query_arg( array( 'author' => $author_ID ), is_network_admin() ? network_admin_url( 'admin.php?page=wp_stream' ) : admin_url( 'admin.php?page=wp_stream' ) ), get_avatar( $author_ID, 40 ), $author_name, $author_role @@ -194,6 +203,15 @@ function column_default( $item, $column_name ) { $out = intval( $item->ID ); break; + case 'blog_id': + $blog = get_blog_details( $item->blog_id ); + $out = sprintf( + '%s', + add_query_arg( array( 'blog_id' => $blog->blog_id ), network_admin_url( 'admin.php?page=wp_stream' ) ), + esc_html( $blog->blogname ) + ); + break; + default: // Register inserted column defaults. Must match a column header from get_columns. $inserted_columns = apply_filters( 'wp_stream_register_column_defaults', $new_columns = array() ); @@ -271,7 +289,7 @@ public static function get_action_links( $record ){ } function column_link( $display, $key, $value = null, $title = null ) { - $url = admin_url( 'admin.php?page=wp_stream' ); + $url = is_network_admin() ? network_admin_url( 'admin.php?page=wp_stream') : admin_url( 'admin.php?page=wp_stream' ); $args = ! is_array( $key ) ? array( $key => $value ) : $key; @@ -326,6 +344,18 @@ function filters_form() { 'items' => $actions, ); + if ( is_network_admin() ) { + $blogs = array(); + foreach( (array) wp_get_sites() as $blog ) { + $blogs[$blog['blog_id']] = $blog['domain']; + } + + $filters['blog_id'] = array( + 'title' => __( 'blogs', 'stream' ), + 'items' => $blogs, + ); + } + $filters = apply_filters( 'wp_stream_list_table_filters', $filters ); $filters_string .= $this->filter_date(); @@ -335,7 +365,7 @@ function filters_form() { } $filters_string .= sprintf( '', __( 'Filter', 'stream' ) ); - $url = admin_url( 'admin.php' ); + $url = is_network_admin() ? network_admin_url( 'admin.php' ) : admin_url( 'admin.php' ); echo sprintf( '
%s
', $filters_string ); // xss okay } @@ -396,7 +426,7 @@ function filter_date() { } function display() { - echo '
'; + echo ''; echo $this->filter_search(); // xss okay parent::display(); echo '
'; diff --git a/includes/query.php b/includes/query.php index 8c7f762fa..6e4d23c52 100644 --- a/includes/query.php +++ b/includes/query.php @@ -31,8 +31,8 @@ public function query( $args ) { 'type' => 'stream', 'object_id' => null, 'ip' => null, - 'site_id' => get_current_site()->id, - 'blog_id' => get_current_blog_id(), + 'site_id' => is_network_admin() ? null : get_current_site()->id, + 'blog_id' => is_network_admin() ? null : get_current_blog_id(), // Author param 'author' => null, // Date-based filters @@ -82,15 +82,12 @@ public function query( $args ) { $where .= $wpdb->prepare( " AND $wpdb->stream.ip = %s", filter_var( $args['ip'], FILTER_VALIDATE_IP ) ); } - if ( is_multisite() ) { - if ( $args['site_id'] ) { - $where .= $wpdb->prepare( " AND $wpdb->stream.site_id = %d", $args['site_id'] ); - } - - if ( $args['blog_id'] ) { - $where .= $wpdb->prepare( " AND $wpdb->stream.blog_id = %d", $args['blog_id'] ); - } + if ( $args['site_id'] ) { + $where .= $wpdb->prepare( " AND $wpdb->stream.site_id = %d", $args['site_id'] ); + } + if ( $args['blog_id'] ) { + $where .= $wpdb->prepare( " AND $wpdb->stream.blog_id = %d", $args['blog_id'] ); } if ( $args['search'] ) { @@ -190,7 +187,7 @@ public function query( $args ) { if ( in_array( $orderby, - array( 'ID', 'blog_id', 'object_id', 'author', 'summary', 'visibility', 'parent', 'type', 'created' ) + array( 'ID', 'site_id', 'blog_id', 'object_id', 'author', 'summary', 'visibility', 'parent', 'type', 'created' ) ) ) { $orderby = $wpdb->stream . '.' . $orderby; } From 9f65ca9bfa673bfbcbcbfdbffdba1c8773b84e56 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Tue, 14 Jan 2014 17:09:06 -0600 Subject: [PATCH 005/123] Add Stream Activity dashboard widget to network admin screen --- includes/admin.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/admin.php b/includes/admin.php index 4ffee92d8..6f9b1a495 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -55,6 +55,7 @@ public static function load() { // Load Dashboard widget add_action( 'wp_dashboard_setup', array( __CLASS__, 'dashboard_stream_activity' ) ); + add_action( 'wp_network_dashboard_setup', array( __CLASS__, 'dashboard_stream_activity' ) ); // Heartbeat live update add_filter( 'heartbeat_received', array( __CLASS__, 'live_update' ), 10, 2 ); From cf6674c8888586f8a20791101cd14e5b212a12a1 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 15 Jan 2014 10:30:52 -0600 Subject: [PATCH 006/123] Add initial context for blogs connector - Added all actions to be tracked - Created empty callback function for each action --- connectors/blogs.php | 181 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 connectors/blogs.php diff --git a/connectors/blogs.php b/connectors/blogs.php new file mode 100644 index 000000000..83dff3f0a --- /dev/null +++ b/connectors/blogs.php @@ -0,0 +1,181 @@ + __( 'Updated', 'stream' ), + 'created' => __( 'Created', 'stream' ), + 'archive_blog' => __( 'Archived', 'stream' ), + 'deleted' => __( 'Deleted', 'stream' ), + ); + } + + /** + * Return translated context labels + * + * @return array Context label translations + */ + public static function get_context_labels() { + $blogs = wp_get_sites(); + $blog_labels = array(); + foreach( $blogs as $blog ) { + $blog_labels[$blog['blog_id']] = array( + 'domain' => $blog['domain'], + 'public' => $blog['public'], + 'last_updated' => $blog['last_updated'], + 'registered' => $blog['registered'], + 'archived' => $blog['archived'], + 'mature' => $blog['mature'], + 'spam' => $blog['spam'], + 'deleted' => $blog['deleted'], + ); + } + } + + /** + * Add action links to Stream drop row in admin list screen + * + * @filter wp_stream_action_links_{connector} + * @param array $links Previous links registered + * @param int $record Stream record + * @return array Action links + */ + public static function action_links( $links, $record ) { + + return $links; + } + + /** + * @param $blog_id + * @action activate_blog + */ + public static function callback_activate_blog( $blog_id ) { + + } + + /** + * @param $blog_id + * @action wpmu_new_blog + */ + public static function callback_wpmu_new_blog( $blog_id ) { + + } + + /** + * @param $post_id + * @action make_spam_blog + */ + public static function callback_make_spam_blog( $post_id ) { + + } + + /** + * @param $blog + * @action make_ham_blog + */ + public static function callback_make_ham_blog( $blog ) { + + } + + /** + * @param $blog_id + * @action mature_blog + */ + public static function callback_mature_blog( $blog_id ) { + + } + + /** + * @param $blog + * @action unmature_blog + */ + public static function callback_unmature_blog ( $blog ) { + + } + + /** + * @param $blog + * @action archive_blog + */ + public static function callback_archive_blog( $blog ) { + + } + + /** + * @param $blog_id + * @action unarchive_blog + */ + public static function callback_unarchive_blog( $blog_id ) { + + } + + /** + * @param $blog_id + * @action make_delete_blog + */ + public static function callback_make_delete_blog( $blog_id ) { + + } + + /** + * @param $blog_id + * @action undelete_blog + */ + public static function callback_make_undelete_blog( $blog_id ) { + + } + + /** + * @param $blog_id + * @action update_blog_public + */ + public static function callback_update_blog_public( $blog_id ) { + + } + +} \ No newline at end of file From 8798f35574be69f48c441dbf87b351da4a662ead Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 15 Jan 2014 11:09:47 -0600 Subject: [PATCH 007/123] Blogs connector //comment out wp_get_sites to prevent fatal errors before adding connector items --- connectors/blogs.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/connectors/blogs.php b/connectors/blogs.php index 83dff3f0a..dec72ed9c 100644 --- a/connectors/blogs.php +++ b/connectors/blogs.php @@ -60,22 +60,22 @@ public static function get_action_labels() { * * @return array Context label translations */ - public static function get_context_labels() { - $blogs = wp_get_sites(); - $blog_labels = array(); - foreach( $blogs as $blog ) { - $blog_labels[$blog['blog_id']] = array( - 'domain' => $blog['domain'], - 'public' => $blog['public'], - 'last_updated' => $blog['last_updated'], - 'registered' => $blog['registered'], - 'archived' => $blog['archived'], - 'mature' => $blog['mature'], - 'spam' => $blog['spam'], - 'deleted' => $blog['deleted'], - ); - } - } +// public static function get_context_labels() { +// $blogs = wp_get_sites(); +// $blog_labels = array(); +// foreach( $blogs as $blog ) { +// $blog_labels[$blog['blog_id']] = array( +// 'domain' => $blog['domain'], +// 'public' => $blog['public'], +// 'last_updated' => $blog['last_updated'], +// 'registered' => $blog['registered'], +// 'archived' => $blog['archived'], +// 'mature' => $blog['mature'], +// 'spam' => $blog['spam'], +// 'deleted' => $blog['deleted'], +// ); +// } +// } /** * Add action links to Stream drop row in admin list screen From 343ad53d6a5ba3f5383906545a534e1e5f6b064b Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 15 Jan 2014 11:14:44 -0600 Subject: [PATCH 008/123] Move blogs.php to tmp directory during development --- {connectors => tmp}/blogs.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {connectors => tmp}/blogs.php (100%) diff --git a/connectors/blogs.php b/tmp/blogs.php similarity index 100% rename from connectors/blogs.php rename to tmp/blogs.php From 752fdb120aea03541d178d896b9d9e8e94fc9e2f Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 15 Jan 2014 17:23:24 -0600 Subject: [PATCH 009/123] Log, query and display network wide options as blog_id 0 - Added check for is_network_admin before defaulting the blog_id logged as 1 - Added function to the list table to generate a blog object for actions done in network admin --- includes/list-table.php | 15 ++++++++++++++- includes/log.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/list-table.php b/includes/list-table.php index cc76ae1b4..d932250f3 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -204,7 +204,7 @@ function column_default( $item, $column_name ) { break; case 'blog_id': - $blog = get_blog_details( $item->blog_id ); + $blog = $item->blog_id ? get_blog_details( $item->blog_id ) : self::get_network_blog(); $out = sprintf( '%s', add_query_arg( array( 'blog_id' => $blog->blog_id ), network_admin_url( 'admin.php?page=wp_stream' ) ), @@ -241,6 +241,18 @@ function column_default( $item, $column_name ) { echo $out; // xss okay } + /** + * Builds a stdClass object used when displaying actions done in network administration + * @return stdClass + */ + public static function get_network_blog() { + $blog = new stdClass; + $blog->blog_id = 0; + $blog->blogname = 'Network Admin'; + + return $blog; + } + public static function get_action_links( $record ){ $out = ''; @@ -349,6 +361,7 @@ function filters_form() { foreach( (array) wp_get_sites() as $blog ) { $blogs[$blog['blog_id']] = $blog['domain']; } + $blogs[0] = $filters['blog_id'] = array( 'title' => __( 'blogs', 'stream' ), diff --git a/includes/log.php b/includes/log.php index ef77b05c6..6e144b61b 100644 --- a/includes/log.php +++ b/includes/log.php @@ -57,7 +57,7 @@ public function log( $connector, $message, $args, $object_id, $contexts, $user_i $recordarr = array( 'object_id' => $object_id, 'site_id' => get_current_site()->id, - 'blog_id' => get_current_blog_id(), + 'blog_id' => is_network_admin() ? 0 : get_current_blog_id(), 'author' => $user_id, 'created' => current_time( 'mysql', 1 ), 'summary' => vsprintf( $message, $args ), From dc70230e3386134f0d4b78cf3a6aaa7cbcec6c67 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Wed, 15 Jan 2014 17:27:50 -0600 Subject: [PATCH 010/123] added filter to blog_id used in log - Will allow extensions and future features to set blog_id without relying on get_current_blog_id() or is_network_admin() --- includes/log.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/log.php b/includes/log.php index 6e144b61b..2e2b31839 100644 --- a/includes/log.php +++ b/includes/log.php @@ -57,7 +57,7 @@ public function log( $connector, $message, $args, $object_id, $contexts, $user_i $recordarr = array( 'object_id' => $object_id, 'site_id' => get_current_site()->id, - 'blog_id' => is_network_admin() ? 0 : get_current_blog_id(), + 'blog_id' => apply_filters( 'blog_id_logged', is_network_admin() ? 0 : get_current_blog_id() ), 'author' => $user_id, 'created' => current_time( 'mysql', 1 ), 'summary' => vsprintf( $message, $args ), From babb077bee8afc15a426ec2550cff328df21f050 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Sun, 19 Jan 2014 17:08:52 -0600 Subject: [PATCH 011/123] Fix undefined function when multisite is not enabled --- includes/query.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/query.php b/includes/query.php index 6e4d23c52..284316675 100644 --- a/includes/query.php +++ b/includes/query.php @@ -21,6 +21,8 @@ public static function get_instance() { public function query( $args ) { global $wpdb; + $site_id = is_multisite() ? get_current_site()->id : 1; + $defaults = array( // Pagination params 'records_per_page' => 10, @@ -31,7 +33,7 @@ public function query( $args ) { 'type' => 'stream', 'object_id' => null, 'ip' => null, - 'site_id' => is_network_admin() ? null : get_current_site()->id, + 'site_id' => is_network_admin() ? null : $site_id, 'blog_id' => is_network_admin() ? null : get_current_blog_id(), // Author param 'author' => null, From ce2b64c8de1977fa5760d967b1b647ee01eeb499 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Sun, 19 Jan 2014 17:15:00 -0600 Subject: [PATCH 012/123] Just use null for site_id when not in multisite --- includes/query.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/query.php b/includes/query.php index 284316675..34a8453e1 100644 --- a/includes/query.php +++ b/includes/query.php @@ -21,7 +21,7 @@ public static function get_instance() { public function query( $args ) { global $wpdb; - $site_id = is_multisite() ? get_current_site()->id : 1; + $site_id = is_multisite() ? get_current_site()->id : null; $defaults = array( // Pagination params From fe004b53120e2656cdd8470269b931d73d0930fe Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Sun, 19 Jan 2014 20:29:13 -0600 Subject: [PATCH 013/123] Remove ID col from network admin list table view --- includes/list-table.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/list-table.php b/includes/list-table.php index d932250f3..7e1f96329 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -36,6 +36,7 @@ function extra_tablenav( $which ) { } function network_admin_columns( $columns ) { + unset( $columns['id'] ); $columns['blog_id'] = __( 'Blog', 'stream' ); return $columns; } From dfc3437c1aa5fdd54dec5182c62a844ed11e05c7 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Sun, 19 Jan 2014 20:49:02 -0600 Subject: [PATCH 014/123] Trivial code formatting --- includes/list-table.php | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/includes/list-table.php b/includes/list-table.php index 7e1f96329..536b277d0 100644 --- a/includes/list-table.php +++ b/includes/list-table.php @@ -17,8 +17,8 @@ function __construct( $args = array() ) { 'default' => 20, 'label' => __( 'Records per page', 'stream' ), 'option' => 'edit_stream_per_page', - ) - ); + ) + ); add_filter( 'set-screen-option', array( __CLASS__, 'set_screen_option' ), 10, 3 ); add_filter( 'screen_settings', array( __CLASS__, 'live_update_checkbox' ), 10, 2 ); @@ -78,7 +78,7 @@ function prepare_items() { $this->set_pagination_args( array( 'total_items' => $total_items, - 'per_page' => $this->get_items_per_page( 'edit_stream_per_page', 20 ), + 'per_page' => $this->get_items_per_page( 'edit_stream_per_page', 20 ), ) ); } @@ -90,10 +90,10 @@ function prepare_items() { * @return string Displays a checkbox */ function column_cb( $item ) { - return sprintf( + return sprintf( '', - /*$1%s*/ 'wp_stream_checkbox', - /*$2%s*/ $item->ID + 'wp_stream_checkbox', + $item->ID ); } @@ -112,10 +112,17 @@ function get_records() { // Filters $allowed_params = array( - 'connector', 'context', 'action', - 'author', 'object_id', 'search', - 'date', 'date_from', 'date_to', - 'record__in', 'blog_id' + 'connector', + 'context', + 'action', + 'author', + 'object_id', + 'search', + 'date', + 'date_from', + 'date_to', + 'record__in', + 'blog_id', ); foreach ( $allowed_params as $param ) { From b951ff971b732a616487d5f6031aebce2613e845 Mon Sep 17 00:00:00 2001 From: Chris Olbekson Date: Mon, 10 Feb 2014 10:46:42 -0600 Subject: [PATCH 015/123] Network Wide Stream - Added settings API wrapper for saving network wide settings - Added filter to get_fields method to allow settings to be extended - Added function to filter stream get settings to load correct values on network admin settings page --- includes/admin.php | 30 ++++++++---- includes/network.php | 109 ++++++++++++++++++++++++++++++++++++++++++ includes/settings.php | 3 +- stream.php | 7 ++- 4 files changed, 137 insertions(+), 12 deletions(-) create mode 100644 includes/network.php diff --git a/includes/admin.php b/includes/admin.php index 4411e9986..2ee4a2ff7 100644 --- a/includes/admin.php +++ b/includes/admin.php @@ -26,12 +26,19 @@ public static function load() { add_filter( 'user_has_cap', array( __CLASS__, '_filter_user_caps' ), 10, 4 ); add_filter( 'role_has_cap', array( __CLASS__, '_filter_role_caps' ), 10, 3 ); - // Register settings page - add_action( 'admin_menu', array( __CLASS__, 'register_menu' ) ); - // Register settings page for network admin - if ( is_multisite() ) { + if ( is_network_admin() ) { add_action( 'network_admin_menu', array( __CLASS__, 'register_menu' ) ); + + // Admin notices + add_action( 'network_admin_notices', array( __CLASS__, 'admin_notices' ) ); + + } else { + // Register settings page + add_action( 'admin_menu', array( __CLASS__, 'register_menu' ) ); + + // Admin notices + add_action( 'admin_notices', array( __CLASS__, 'admin_notices' ) ); } // Plugin action links add_filter( 'plugin_action_links', array( __CLASS__, 'plugin_action_links' ), 10, 2 ); @@ -155,8 +162,9 @@ public static function admin_enqueue_scripts( $hook ) { /** * Add menu styles for various WP Admin skins * + * @uses wp_add_inline_style() * @action admin_enqueue_scripts - * @return wp_add_inline_style + * @return bool true on success false on failure */ public static function admin_menu_css() { wp_register_style( 'wp-stream-icons', WP_STREAM_URL . 'ui/stream-icons/style.css' ); @@ -240,6 +248,10 @@ public static function plugin_action_links( $links, $file ) { * @return void */ public static function render_page() { + if ( is_multisite() ) + include_once ABSPATH . 'wp-admin/options-head.php'; + + $form_action = is_network_admin() ? network_admin_url( 'edit.php?action=stream_settings' ) : admin_url( 'options.php' ); ?>
@@ -263,7 +275,7 @@ public static function render_page() {