From 5b99934106b42e0a324feac4952f21454840e931 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Thu, 13 Mar 2014 11:33:59 +0100 Subject: [PATCH 01/46] [issue-313] Add Editor connector --- connectors/editor.php | 61 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 connectors/editor.php diff --git a/connectors/editor.php b/connectors/editor.php new file mode 100644 index 000000000..7a0c10c63 --- /dev/null +++ b/connectors/editor.php @@ -0,0 +1,61 @@ + Date: Thu, 13 Mar 2014 12:12:43 +0100 Subject: [PATCH 02/46] [issue-313] Clone textarea --- connectors/editor.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 7a0c10c63..2335f8796 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -15,7 +15,7 @@ class WP_Stream_Connector_Editor extends WP_Stream_Connector { * @var array */ public static $actions = array( - + 'admin_footer', ); /** @@ -58,4 +58,22 @@ public static function get_context_labels() { ); } + public static function callback_admin_footer() { + if( 'theme-editor' === get_current_screen()->id ) : ?> + + Date: Thu, 13 Mar 2014 12:47:09 +0100 Subject: [PATCH 03/46] [issue-313] Log file changes --- connectors/editor.php | 54 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 4 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 2335f8796..5d925b28e 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -25,6 +25,7 @@ class WP_Stream_Connector_Editor extends WP_Stream_Connector { */ public static function register() { parent::register(); + add_filter( 'wp_redirect', array( __CLASS__, 'log_changes_on_redirect' ) ); } /** @@ -43,7 +44,7 @@ public static function get_label() { */ public static function get_action_labels() { return array( - + 'updated' => __( 'Updated', 'stream' ), ); } @@ -54,7 +55,7 @@ public static function get_action_labels() { */ public static function get_context_labels() { return array( - + 'file' => __( 'File', 'stream' ), ); } @@ -72,8 +73,53 @@ public static function callback_admin_footer() { id && 'POST' === $_SERVER['REQUEST_METHOD'] && isset( $_POST['action'] ) && 'update' === $_POST['action'] ) { + + if ( isset( $_POST['theme'] ) && $_POST['theme'] ) { + $stylesheet = $_POST['theme']; + } else { + $stylesheet = get_stylesheet(); + } + + $theme = wp_get_theme( $stylesheet ); + + if ( $theme->exists() && ! ($theme->errors() && 'theme_no_stylesheet' == $theme->errors()->get_error_code() ) ) { + $allowed_files = $theme->get_files( 'php', 1 ); + $has_templates = ! empty( $allowed_files ); + $style_files = $theme->get_files( 'css' ); + $allowed_files['style.css'] = $style_files['style.css']; + $allowed_files += $style_files; + + if ( empty( $_POST['file'] ) ) { + $relative_file = 'style.css'; + $file = $allowed_files['style.css']; + } else { + $relative_file = $_POST['file']; + $file = $theme->get_stylesheet_directory() . '/' . $relative_file; + } + + $file_contents = file_get_contents( $file ); + + if ( $file_contents !== $_POST['oldcontent'] ) { + $properties = array( + 'file' => $relative_file, + 'theme' => $theme, + 'new_value' => $file_contents, + 'old_value' => $_POST['oldcontent'], + ); + + self::log( + __( '"%1$s" file of "%2$s" theme was updated via editor', 'stream' ), + $properties, + null, + array( 'file' => 'updated' ) + ); + } + } + } + + return $location; } } From c24db6b7d7435d4d5fb7a39dc61896393ced2123 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Thu, 13 Mar 2014 13:05:03 +0100 Subject: [PATCH 04/46] [issue-313] Improve log message --- connectors/editor.php | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 5d925b28e..3abd16153 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -103,14 +103,31 @@ public static function log_changes_on_redirect( $location ) { if ( $file_contents !== $_POST['oldcontent'] ) { $properties = array( - 'file' => $relative_file, - 'theme' => $theme, - 'new_value' => $file_contents, - 'old_value' => $_POST['oldcontent'], + 'file_html' => sprintf( + '%s', + esc_attr( admin_url( sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme->get_template(), + $relative_file + ) ) ), + $relative_file + ), + 'theme_html' => sprintf( + '%s', + esc_attr( admin_url( sprintf( 'themes.php?theme=%s', $theme->get_template() ) ) ), + $theme->get_template() + ), + 'editor_opening_html' => sprintf( '', esc_attr( admin_url( 'theme-editor.php' ) ) ), + 'editor_closing_html' => '', + 'file' => $relative_file, + 'theme' => $theme, + 'closing' => '', + 'new_value' => $file_contents, + 'old_value' => $_POST['oldcontent'], ); self::log( - __( '"%1$s" file of "%2$s" theme was updated via editor', 'stream' ), + __( '%1$s file of %2$s theme was updated via %3$sEditor%4$s', 'stream' ), $properties, null, array( 'file' => 'updated' ) From 2a288a3f40087f90ca074abba40aa6866685b771 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Thu, 13 Mar 2014 13:38:51 +0100 Subject: [PATCH 05/46] [issue-313] Use theme name --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 3abd16153..89f9e71af 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -115,7 +115,7 @@ public static function log_changes_on_redirect( $location ) { 'theme_html' => sprintf( '%s', esc_attr( admin_url( sprintf( 'themes.php?theme=%s', $theme->get_template() ) ) ), - $theme->get_template() + $theme ), 'editor_opening_html' => sprintf( '', esc_attr( admin_url( 'theme-editor.php' ) ) ), 'editor_closing_html' => '', From 2a3622530da245617d993bea83d9b0b7441d377a Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 07:26:05 +0100 Subject: [PATCH 06/46] [issue-313] Make sure `get_current_screen` function exists --- connectors/editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 89f9e71af..f44e205ca 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -60,7 +60,7 @@ public static function get_context_labels() { } public static function callback_admin_footer() { - if( 'theme-editor' === get_current_screen()->id ) : ?> + if( is_admin() && 'theme-editor' === get_current_screen()->id ) : ?> - Date: Fri, 14 Mar 2014 09:18:53 +0100 Subject: [PATCH 13/46] [issue-313] Ignore theme editor changes in Installer connector --- connectors/installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/installer.php b/connectors/installer.php index b89a7f513..fcc2f6db1 100644 --- a/connectors/installer.php +++ b/connectors/installer.php @@ -312,7 +312,7 @@ public static function callback_pre_set_site_transient_update_plugins( $value ) } public static function callback_wp_redirect( $location ) { - if ( ! preg_match( '#(plugin|theme)-editor.php#', $location, $match ) ) { + if ( ! preg_match( '#(plugin)-editor.php#', $location, $match ) ) { return $location; } From 22ff0f80ff7d1796cd1d30ef93ce9f190bddb269 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 09:38:06 +0100 Subject: [PATCH 14/46] [issue-313] Add action link to Edit File --- connectors/editor.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/connectors/editor.php b/connectors/editor.php index 2159461d0..1dd351008 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -65,6 +65,28 @@ public static function get_context_labels() { ); } + /** + * 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 ) { + if ( 'file' === $record->context ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'theme', true ); + + $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme_name, + $file_name + ) ); + } + return $links; + } + /** * @action load-theme-editor.php */ From 20376f52bba5d40d7417a20065b6301ab38188d4 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 09:42:25 +0100 Subject: [PATCH 15/46] Add Edit Theme action link --- connectors/editor.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 1dd351008..e1d8fc544 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -83,6 +83,11 @@ public static function action_links( $links, $record ) { $theme_name, $file_name ) ); + + $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( + 'themes.php?theme=%s', + $theme_name + ) ); } return $links; } @@ -151,7 +156,7 @@ public static function log_changes_on_redirect( $location ) { 'editor_opening_html' => sprintf( '', esc_attr( admin_url( 'theme-editor.php' ) ) ), 'editor_closing_html' => '', 'file' => self::$edited_file['file_name'], - 'theme' => self::$edited_file['theme'], + 'theme' => self::$edited_file['theme']->get_template(), 'closing' => '', 'new_value' => self::$edited_file['file_contents_after'], 'old_value' => self::$edited_file['file_contents_before'], From b157e3a31ddb996fd8f08a18047178d0c2fbc66f Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 09:49:18 +0100 Subject: [PATCH 16/46] [issue-313] Simplify log message --- connectors/editor.php | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index e1d8fc544..1ffd2ffc0 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -50,7 +50,7 @@ public static function get_label() { */ public static function get_action_labels() { return array( - 'updated' => __( 'Updated', 'stream' ), + 'edited' => __( 'Edited', 'stream' ), ); } @@ -139,34 +139,18 @@ public static function log_changes_on_redirect( $location ) { if ( $file_contents_after !== self::$edited_file['file_contents_before'] ) { $properties = array( - 'file_html' => sprintf( - '%s', - esc_attr( admin_url( sprintf( - 'theme-editor.php?theme=%s&file=%s', - self::$edited_file['theme']->get_template(), - self::$edited_file['file_name'] - ) ) ), - self::$edited_file['file_name'] - ), - 'theme_html' => sprintf( - '%s', - esc_attr( admin_url( sprintf( 'themes.php?theme=%s', self::$edited_file['theme']->get_template() ) ) ), - self::$edited_file['theme'] - ), - 'editor_opening_html' => sprintf( '', esc_attr( admin_url( 'theme-editor.php' ) ) ), - 'editor_closing_html' => '', 'file' => self::$edited_file['file_name'], + 'theme_name' => (string) self::$edited_file['theme'], 'theme' => self::$edited_file['theme']->get_template(), - 'closing' => '', 'new_value' => self::$edited_file['file_contents_after'], 'old_value' => self::$edited_file['file_contents_before'], ); self::log( - __( '%1$s file of %2$s theme was updated via %3$sEditor%4$s', 'stream' ), + __( '%1$s file edited in %2$s theme', 'stream' ), $properties, null, - array( 'file' => 'updated' ) + array( 'file' => 'edited' ) ); } } From dca4a932236a0f48c2b146a390a590aa9e2ec594 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 09:56:00 +0100 Subject: [PATCH 17/46] [issue-313] Update connector name to Theme Editor --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 1ffd2ffc0..8fece60dd 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -40,7 +40,7 @@ public static function register() { * @return string Translated context label */ public static function get_label() { - return __( 'Editor', 'stream' ); + return __( 'Theme Editor', 'stream' ); } /** From 7d9b8fdd9c332f83b17e1725a1c75a57aac99a23 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 10:06:15 +0100 Subject: [PATCH 18/46] [issue-313] Use theme name as Context --- connectors/editor.php | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 8fece60dd..26be03022 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -60,9 +60,23 @@ public static function get_action_labels() { * @return array Context label translations */ public static function get_context_labels() { - return array( - 'file' => __( 'File', 'stream' ), + $themes = wp_get_themes(); + + $themes_slugs = array_map( + function( $theme ) { + return $theme->get_template(); + }, + $themes ); + + $themes_names = array_map( + function( $theme ) { + return (string) $theme; + }, + $themes + ); + + return array_combine( $themes_slugs, $themes_names ); } /** @@ -138,10 +152,11 @@ public static function log_changes_on_redirect( $location ) { $file_contents_after = file_get_contents( self::$edited_file['file_path'] ); if ( $file_contents_after !== self::$edited_file['file_contents_before'] ) { + $theme_slug = self::$edited_file['theme']->get_template(); $properties = array( 'file' => self::$edited_file['file_name'], 'theme_name' => (string) self::$edited_file['theme'], - 'theme' => self::$edited_file['theme']->get_template(), + 'theme' => $theme_slug, 'new_value' => self::$edited_file['file_contents_after'], 'old_value' => self::$edited_file['file_contents_before'], ); @@ -150,7 +165,7 @@ public static function log_changes_on_redirect( $location ) { __( '%1$s file edited in %2$s theme', 'stream' ), $properties, null, - array( 'file' => 'edited' ) + array( $theme_slug => 'edited' ) ); } } From d1333922a9df1624c6add2f4b4022e15f3dad95d Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 10:09:21 +0100 Subject: [PATCH 19/46] [issue-313] Change action to Updated --- connectors/editor.php | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 26be03022..2332c08f5 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -50,7 +50,7 @@ public static function get_label() { */ public static function get_action_labels() { return array( - 'edited' => __( 'Edited', 'stream' ), + 'updated' => __( 'Updated', 'stream' ), ); } @@ -88,21 +88,20 @@ function( $theme ) { * @return array Action links */ public static function action_links( $links, $record ) { - if ( 'file' === $record->context ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'theme', true ); - - $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( - 'theme-editor.php?theme=%s&file=%s', - $theme_name, - $file_name - ) ); - - $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( - 'themes.php?theme=%s', - $theme_name - ) ); - } + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'theme', true ); + + $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme_name, + $file_name + ) ); + + $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( + 'themes.php?theme=%s', + $theme_name + ) ); + return $links; } @@ -165,7 +164,7 @@ public static function log_changes_on_redirect( $location ) { __( '%1$s file edited in %2$s theme', 'stream' ), $properties, null, - array( $theme_slug => 'edited' ) + array( $theme_slug => 'updated' ) ); } } From cd4014ae701d26bbda0924328f2e77fc14c098d9 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 10:12:05 +0100 Subject: [PATCH 20/46] [issue-313] Hide action links for users without permissions --- connectors/editor.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 2332c08f5..2842a1d0f 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -88,19 +88,21 @@ function( $theme ) { * @return array Action links */ public static function action_links( $links, $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'theme', true ); - - $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( - 'theme-editor.php?theme=%s&file=%s', - $theme_name, - $file_name - ) ); - - $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( - 'themes.php?theme=%s', - $theme_name - ) ); + if ( current_user_can( 'edit_theme_options' ) ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'theme', true ); + + $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme_name, + $file_name + ) ); + + $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( + 'themes.php?theme=%s', + $theme_name + ) ); + } return $links; } From c372356cf5ceb6f74c7e266ec92e1657008fe117 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 10:18:31 +0100 Subject: [PATCH 21/46] [issue-313] Tiny log message improvement --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 2842a1d0f..3a23bf669 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -163,7 +163,7 @@ public static function log_changes_on_redirect( $location ) { ); self::log( - __( '%1$s file edited in %2$s theme', 'stream' ), + __( '"%1$s" was updated in "%2$s"', 'stream' ), $properties, null, array( $theme_slug => 'updated' ) From 6e6534d8412352f801b81610b1c08c3c2170a7b2 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 10:21:04 +0100 Subject: [PATCH 22/46] [issue-313] Document and simplify method --- connectors/editor.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 3a23bf669..9aa9bb877 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -31,7 +31,7 @@ class WP_Stream_Connector_Editor extends WP_Stream_Connector { public static function register() { parent::register(); add_action( 'load-theme-editor.php', array( __CLASS__, 'get_edition_data' ) ); - add_filter( 'wp_redirect', array( __CLASS__, 'log_changes_on_redirect' ) ); + add_filter( 'wp_redirect', array( __CLASS__, 'log_changes' ) ); } /** @@ -148,7 +148,10 @@ public static function get_edition_data() { ); } - public static function log_changes_on_redirect( $location ) { + /** + * @filter wp_redirect + */ + public static function log_changes( $location ) { if( ! empty( self::$edited_file ) ) { $file_contents_after = file_get_contents( self::$edited_file['file_path'] ); From 25b0eea67120f6aecccf8dd96ed36c6d3852960d Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 16:58:05 +0100 Subject: [PATCH 23/46] [issue-313] Ignore file contents in logs --- connectors/editor.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 9aa9bb877..6b5210e1a 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -161,8 +161,6 @@ public static function log_changes( $location ) { 'file' => self::$edited_file['file_name'], 'theme_name' => (string) self::$edited_file['theme'], 'theme' => $theme_slug, - 'new_value' => self::$edited_file['file_contents_after'], - 'old_value' => self::$edited_file['file_contents_before'], ); self::log( From 5169f8076bf61cf83c4d33e5b611f56e9b326697 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 17:02:51 +0100 Subject: [PATCH 24/46] [issue-313] Syntax tidying --- connectors/editor.php | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 6b5210e1a..952e9257c 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -92,16 +92,20 @@ public static function action_links( $links, $record ) { $file_name = get_stream_meta( $record->ID, 'file', true ); $theme_name = get_stream_meta( $record->ID, 'theme', true ); - $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( - 'theme-editor.php?theme=%s&file=%s', - $theme_name, - $file_name - ) ); - - $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( sprintf( - 'themes.php?theme=%s', - $theme_name - ) ); + $links[ __( 'Edit File', 'stream' ) ] = admin_url( + sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme_name, + $file_name + ) + ); + + $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( + sprintf( + 'themes.php?theme=%s', + $theme_name + ) + ); } return $links; @@ -111,11 +115,11 @@ public static function action_links( $links, $record ) { * @action load-theme-editor.php */ public static function get_edition_data() { - if( 'POST' !== $_SERVER['REQUEST_METHOD'] ) { + if ( 'POST' !== $_SERVER['REQUEST_METHOD'] ) { return; } - if( ! isset( $_POST['action'] ) || 'update' !== $_POST['action'] ) { + if ( ! isset( $_POST['action'] ) || 'update' !== $_POST['action'] ) { return; } @@ -152,7 +156,7 @@ public static function get_edition_data() { * @filter wp_redirect */ public static function log_changes( $location ) { - if( ! empty( self::$edited_file ) ) { + if ( ! empty( self::$edited_file ) ) { $file_contents_after = file_get_contents( self::$edited_file['file_path'] ); if ( $file_contents_after !== self::$edited_file['file_contents_before'] ) { From e337678a3141d5ebe7ffcd6e431e395c39b12aa2 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 14 Mar 2014 17:47:22 +0100 Subject: [PATCH 25/46] [issue-313] Use wp_stream_filter_input() --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 952e9257c..e5946d47f 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -119,7 +119,7 @@ public static function get_edition_data() { return; } - if ( ! isset( $_POST['action'] ) || 'update' !== $_POST['action'] ) { + if ( 'update' !== wp_stream_filter_input( INPUT_POST, 'action' ) ) { return; } From 3b0b750c3eebb28bbdbbfbf73d7fc23b1742871d Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Mon, 24 Mar 2014 10:11:55 -0500 Subject: [PATCH 26/46] Use wp_stream_filter_input where possible --- connectors/editor.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index e5946d47f..4a8bf576d 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -123,22 +123,23 @@ public static function get_edition_data() { return; } - $theme_name = ( isset( $_POST['theme'] ) && $_POST['theme'] ? $_POST['theme'] : get_stylesheet() ); - $theme = wp_get_theme( $theme_name ); + $theme_name = wp_stream_filter_input( INPUT_POST, 'theme' ) ? wp_stream_filter_input( INPUT_POST, 'theme' ) : get_stylesheet(); + $theme = wp_get_theme( $theme_name ); if ( ! $theme->exists() || ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) ) { return; } - $allowed_files = $theme->get_files( 'php', 1 ); - $style_files = $theme->get_files( 'css' ); + $allowed_files = $theme->get_files( 'php', 1 ); + $style_files = $theme->get_files( 'css' ); $allowed_files['style.css'] = $style_files['style.css']; + $file = wp_stream_filter_input( INPUT_POST, 'file' ); - if ( empty( $_POST['file'] ) ) { + if ( empty( $file ) ) { $file_name = 'style.css'; $file_path = $allowed_files['style.css']; } else { - $file_name = $_POST['file']; + $file_name = $file; $file_path = $theme->get_stylesheet_directory() . '/' . $file_name; } From d21362f1c8ca7ce2cb72625a320dc59cf96ae7e3 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 09:43:48 +0100 Subject: [PATCH 27/46] [issue-313] Get message in method --- connectors/editor.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 4a8bf576d..9daa6f4db 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -79,6 +79,10 @@ function( $theme ) { return array_combine( $themes_slugs, $themes_names ); } + public static function get_message() { + return __( '"%1$s" was updated in "%2$s"', 'stream' ); + } + /** * Add action links to Stream drop row in admin list screen * @@ -169,7 +173,7 @@ public static function log_changes( $location ) { ); self::log( - __( '"%1$s" was updated in "%2$s"', 'stream' ), + self::get_message(), $properties, null, array( $theme_slug => 'updated' ) From a8e1d1c16082b7c12bbc3847ff13385fd24d7e99 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 09:49:54 +0100 Subject: [PATCH 28/46] [issue-313] Update summary --- includes/install.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/includes/install.php b/includes/install.php index 55b880c56..dba0e8928 100644 --- a/includes/install.php +++ b/includes/install.php @@ -203,6 +203,31 @@ public static function update( $db_version, $current ) { if ( version_compare( $db_version, '1.3.0', '<' ) ) { add_filter( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_old_options_to_exclude_tab' ); } + + // If version is lower than 1.3.0, do the update routine + // Update records of Installer to Theme Editor connector + if ( version_compare( $db_version, '1.3.0', '<' ) ) { + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + ); + $records = stream_query( $args ); + + foreach( $records as $record ) { + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( + WP_Stream_Connector_Editor::get_message(), + get_stream_meta( $record->ID, 'file', true ), + get_stream_meta( $record->ID, 'name', true ) + ) + ), + array( 'ID' => $record->ID ) + ); + } + } } /** From 8233914ef793979fe995803e7fe376ad3f9f5647 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:06:38 +0100 Subject: [PATCH 29/46] [issue-313] Update stream context table --- includes/install.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/includes/install.php b/includes/install.php index dba0e8928..16617383a 100644 --- a/includes/install.php +++ b/includes/install.php @@ -214,6 +214,8 @@ public static function update( $db_version, $current ) { $records = stream_query( $args ); foreach( $records as $record ) { + $theme_name = get_stream_meta( $record->ID, 'name', true ); + // `stream` $wpdb->update( $wpdb->stream, @@ -221,11 +223,22 @@ public static function update( $db_version, $current ) { 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), get_stream_meta( $record->ID, 'file', true ), - get_stream_meta( $record->ID, 'name', true ) + $theme_name ) ), array( 'ID' => $record->ID ) ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); } } } From 31e38fa1290223636e4b4f56decbab0e32c8bc69 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:23:33 +0100 Subject: [PATCH 30/46] Add action to WHERE --- includes/install.php | 1 + 1 file changed, 1 insertion(+) diff --git a/includes/install.php b/includes/install.php index 16617383a..8083d44d9 100644 --- a/includes/install.php +++ b/includes/install.php @@ -210,6 +210,7 @@ public static function update( $db_version, $current ) { $args = array( 'connector' => 'installer', 'context' => 'themes', + 'action' => 'edited', ); $records = stream_query( $args ); From ba590f9833ae47e9eaaed7e5bc77bf3973b3517d Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:32:53 +0100 Subject: [PATCH 31/46] [issue-313] Find theme object by name --- includes/install.php | 56 ++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/includes/install.php b/includes/install.php index 8083d44d9..d5ffaa0c4 100644 --- a/includes/install.php +++ b/includes/install.php @@ -217,29 +217,39 @@ public static function update( $db_version, $current ) { foreach( $records as $record ) { $theme_name = get_stream_meta( $record->ID, 'name', true ); - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( - WP_Stream_Connector_Editor::get_message(), - get_stream_meta( $record->ID, 'file', true ), - $theme_name - ) - ), - array( 'ID' => $record->ID ) - ); - - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); + if( $theme_name !== '' ) { + $matched_themes = array_filter( + wp_get_themes(), + function( $theme ) use ( $theme_name ) { + return (string) $theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( + WP_Stream_Connector_Editor::get_message(), + get_stream_meta( $record->ID, 'file', true ), + $theme_name + ) + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + } } } } From 5a02d2f3501db24854d1a2e0c81e1267f7d2bdfd Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:42:13 +0100 Subject: [PATCH 32/46] [issue-313] Update meta --- includes/install.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/includes/install.php b/includes/install.php index d5ffaa0c4..1e49288aa 100644 --- a/includes/install.php +++ b/includes/install.php @@ -249,6 +249,12 @@ function( $theme ) use ( $theme_name ) { ), array( 'record_id' => $record->ID ) ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme', (string) $theme ); + } } } } From ce2ad987c54917b2c307bf40cf1a432df519243e Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:44:42 +0100 Subject: [PATCH 33/46] [issue-313] Move update routine to Editor connector class --- connectors/editor.php | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/connectors/editor.php b/connectors/editor.php index 9daa6f4db..5343b8448 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -184,4 +184,57 @@ public static function log_changes( $location ) { return $location; } + public static function update_routine() { + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + 'action' => 'edited', + ); + $records = stream_query( $args ); + + foreach( $records as $record ) { + $theme_name = get_stream_meta( $record->ID, 'name', true ); + + if( $theme_name !== '' ) { + $matched_themes = array_filter( + wp_get_themes(), + function( $theme ) use ( $theme_name ) { + return (string) $theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( + self::get_message(), + get_stream_meta( $record->ID, 'file', true ), + $theme_name + ) + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme', (string) $theme ); + } + } + } + } + } From 55e233ca13641fc39d6bb4f82958d8eb44755533 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:45:21 +0100 Subject: [PATCH 34/46] [issue-313] Use new method --- includes/install.php | 51 +------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/includes/install.php b/includes/install.php index 1e49288aa..3c83aab49 100644 --- a/includes/install.php +++ b/includes/install.php @@ -207,56 +207,7 @@ public static function update( $db_version, $current ) { // If version is lower than 1.3.0, do the update routine // Update records of Installer to Theme Editor connector if ( version_compare( $db_version, '1.3.0', '<' ) ) { - $args = array( - 'connector' => 'installer', - 'context' => 'themes', - 'action' => 'edited', - ); - $records = stream_query( $args ); - - foreach( $records as $record ) { - $theme_name = get_stream_meta( $record->ID, 'name', true ); - - if( $theme_name !== '' ) { - $matched_themes = array_filter( - wp_get_themes(), - function( $theme ) use ( $theme_name ) { - return (string) $theme === $theme_name; - } - ); - $theme = array_shift( $matched_themes ); - - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( - WP_Stream_Connector_Editor::get_message(), - get_stream_meta( $record->ID, 'file', true ), - $theme_name - ) - ), - array( 'ID' => $record->ID ) - ); - - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); - - update_stream_meta( $record->ID, 'theme_name', $theme_name ); - - if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme', (string) $theme ); - } - } - } + WP_Stream_Connector_Editor::update_routine(); } } From f61b5595c965c12b430029bfd8e304c1fa710577 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:46:33 +0100 Subject: [PATCH 35/46] [issue-313] Get global $wpdb --- connectors/editor.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/connectors/editor.php b/connectors/editor.php index 5343b8448..190a312aa 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -185,6 +185,8 @@ public static function log_changes( $location ) { } public static function update_routine() { + global $wpdb; + $args = array( 'connector' => 'installer', 'context' => 'themes', From 33d640f16bd2c9e11594f0abb7b196b9aba5162d Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 10:55:20 +0100 Subject: [PATCH 36/46] [issue-313] Don't display action links with insufficient meta --- connectors/editor.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 190a312aa..ffdf33112 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -94,22 +94,24 @@ public static function get_message() { public static function action_links( $links, $record ) { if ( current_user_can( 'edit_theme_options' ) ) { $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'theme', true ); - - $links[ __( 'Edit File', 'stream' ) ] = admin_url( - sprintf( - 'theme-editor.php?theme=%s&file=%s', - $theme_name, - $file_name - ) - ); - - $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( - sprintf( - 'themes.php?theme=%s', - $theme_name - ) - ); + $theme_slug = get_stream_meta( $record->ID, 'theme', true ); + + if ( $file_name !== '' && $theme_slug !== '' ) { + $links[ __( 'Edit File', 'stream' ) ] = admin_url( + sprintf( + 'theme-editor.php?theme=%s&file=%s', + $theme_slug, + $file_name + ) + ); + + $links[ __( 'Edit Theme', 'stream' ) ] = admin_url( + sprintf( + 'themes.php?theme=%s', + $theme_slug + ) + ); + } } return $links; From b4df52a24540744d70d63a16ae7270ed42729494 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 11:14:30 +0100 Subject: [PATCH 37/46] [issue-313] Use theme slug in `theme` meta --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index ffdf33112..716ab1343 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -235,7 +235,7 @@ function( $theme ) use ( $theme_name ) { update_stream_meta( $record->ID, 'theme_name', $theme_name ); if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme', (string) $theme ); + update_stream_meta( $record->ID, 'theme', $theme->get_template() ); } } } From 93b34c16245787587443b20d852249a3285b6063 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 11:24:23 +0100 Subject: [PATCH 38/46] [issue-313] Syntax tweaks --- connectors/editor.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 716ab1343..cb9a9d7d9 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -196,10 +196,10 @@ public static function update_routine() { ); $records = stream_query( $args ); - foreach( $records as $record ) { + foreach ( $records as $record ) { $theme_name = get_stream_meta( $record->ID, 'name', true ); - if( $theme_name !== '' ) { + if ( $theme_name !== '' ) { $matched_themes = array_filter( wp_get_themes(), function( $theme ) use ( $theme_name ) { @@ -216,7 +216,7 @@ function( $theme ) use ( $theme_name ) { self::get_message(), get_stream_meta( $record->ID, 'file', true ), $theme_name - ) + ), ), array( 'ID' => $record->ID ) ); From cab8091fb89cd38c2cdada4225a367fa7918367e Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 11:32:16 +0100 Subject: [PATCH 39/46] [issue-313] Replace `theme` meta key with `theme_slug` --- connectors/editor.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index cb9a9d7d9..3ab239daf 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -94,7 +94,7 @@ public static function get_message() { public static function action_links( $links, $record ) { if ( current_user_can( 'edit_theme_options' ) ) { $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_slug = get_stream_meta( $record->ID, 'theme', true ); + $theme_slug = get_stream_meta( $record->ID, 'theme_slug', true ); if ( $file_name !== '' && $theme_slug !== '' ) { $links[ __( 'Edit File', 'stream' ) ] = admin_url( @@ -129,8 +129,8 @@ public static function get_edition_data() { return; } - $theme_name = wp_stream_filter_input( INPUT_POST, 'theme' ) ? wp_stream_filter_input( INPUT_POST, 'theme' ) : get_stylesheet(); - $theme = wp_get_theme( $theme_name ); + $theme_slug = wp_stream_filter_input( INPUT_POST, 'theme' ) ? wp_stream_filter_input( INPUT_POST, 'theme' ) : get_stylesheet(); + $theme = wp_get_theme( $theme_slug ); if ( ! $theme->exists() || ( $theme->errors() && 'theme_no_stylesheet' === $theme->errors()->get_error_code() ) ) { return; @@ -171,7 +171,7 @@ public static function log_changes( $location ) { $properties = array( 'file' => self::$edited_file['file_name'], 'theme_name' => (string) self::$edited_file['theme'], - 'theme' => $theme_slug, + 'theme_slug' => $theme_slug, ); self::log( @@ -235,7 +235,7 @@ function( $theme ) use ( $theme_name ) { update_stream_meta( $record->ID, 'theme_name', $theme_name ); if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme', $theme->get_template() ); + update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); } } } From e677fcc67cb1bce6d2a8adf435736ee955d41659 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Wed, 26 Mar 2014 11:34:12 +0100 Subject: [PATCH 40/46] [issue-313] Beautify sprintf --- connectors/editor.php | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 3ab239daf..2ef173e08 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -197,6 +197,7 @@ public static function update_routine() { $records = stream_query( $args ); foreach ( $records as $record ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); $theme_name = get_stream_meta( $record->ID, 'name', true ); if ( $theme_name !== '' ) { @@ -212,11 +213,7 @@ function( $theme ) use ( $theme_name ) { $wpdb->update( $wpdb->stream, array( - 'summary' => sprintf( - self::get_message(), - get_stream_meta( $record->ID, 'file', true ), - $theme_name - ), + 'summary' => sprintf( self::get_message(), $file_name, $theme_name ), ), array( 'ID' => $record->ID ) ); From bc11f7e13c8c153bc302c6b7690a84bb708c3c72 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Thu, 27 Mar 2014 12:11:28 -0500 Subject: [PATCH 41/46] Bumping version for upgrade routine --- includes/install.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/install.php b/includes/install.php index 3c83aab49..bd233bacf 100644 --- a/includes/install.php +++ b/includes/install.php @@ -204,9 +204,9 @@ public static function update( $db_version, $current ) { add_filter( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_old_options_to_exclude_tab' ); } - // If version is lower than 1.3.0, do the update routine + // If version is lower than 1.3.1, do the update routine // Update records of Installer to Theme Editor connector - if ( version_compare( $db_version, '1.3.0', '<' ) ) { + if ( version_compare( $db_version, '1.3.1', '<' ) ) { WP_Stream_Connector_Editor::update_routine(); } } From 922c17a8cf6081229b0403857600b0b60f906726 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Fri, 28 Mar 2014 17:29:36 +0100 Subject: [PATCH 42/46] [issue-313] Move update routine to installer --- connectors/editor.php | 52 ------------------------------------------- includes/install.php | 48 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 47 insertions(+), 53 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 2ef173e08..24f3da9b1 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -186,56 +186,4 @@ public static function log_changes( $location ) { return $location; } - public static function update_routine() { - global $wpdb; - - $args = array( - 'connector' => 'installer', - 'context' => 'themes', - 'action' => 'edited', - ); - $records = stream_query( $args ); - - foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'name', true ); - - if ( $theme_name !== '' ) { - $matched_themes = array_filter( - wp_get_themes(), - function( $theme ) use ( $theme_name ) { - return (string) $theme === $theme_name; - } - ); - $theme = array_shift( $matched_themes ); - - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( self::get_message(), $file_name, $theme_name ), - ), - array( 'ID' => $record->ID ) - ); - - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); - - update_stream_meta( $record->ID, 'theme_name', $theme_name ); - - if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); - } - } - } - } - } diff --git a/includes/install.php b/includes/install.php index bd233bacf..824c731b2 100644 --- a/includes/install.php +++ b/includes/install.php @@ -207,7 +207,53 @@ public static function update( $db_version, $current ) { // If version is lower than 1.3.1, do the update routine // Update records of Installer to Theme Editor connector if ( version_compare( $db_version, '1.3.1', '<' ) ) { - WP_Stream_Connector_Editor::update_routine(); + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + 'action' => 'edited', + ); + $records = stream_query( $args ); + + foreach ( $records as $record ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'name', true ); + + if ( '' !== $theme_name ) { + $matched_themes = array_filter( + wp_get_themes(), + function( $theme ) use ( $theme_name ) { + return (string) $theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); + } + } + } } } From 6562d1bbb9e86e9e1a00732959850f409e2ab4fa Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Fri, 28 Mar 2014 22:05:08 -0500 Subject: [PATCH 43/46] Run migrate routine after connectors are registered --- includes/install.php | 108 +++++++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 49 deletions(-) diff --git a/includes/install.php b/includes/install.php index 824c731b2..acec59e2e 100644 --- a/includes/install.php +++ b/includes/install.php @@ -207,53 +207,7 @@ public static function update( $db_version, $current ) { // If version is lower than 1.3.1, do the update routine // Update records of Installer to Theme Editor connector if ( version_compare( $db_version, '1.3.1', '<' ) ) { - $args = array( - 'connector' => 'installer', - 'context' => 'themes', - 'action' => 'edited', - ); - $records = stream_query( $args ); - - foreach ( $records as $record ) { - $file_name = get_stream_meta( $record->ID, 'file', true ); - $theme_name = get_stream_meta( $record->ID, 'name', true ); - - if ( '' !== $theme_name ) { - $matched_themes = array_filter( - wp_get_themes(), - function( $theme ) use ( $theme_name ) { - return (string) $theme === $theme_name; - } - ); - $theme = array_shift( $matched_themes ); - - // `stream` - $wpdb->update( - $wpdb->stream, - array( - 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), - ), - array( 'ID' => $record->ID ) - ); - - // `stream_context` - $wpdb->update( - $wpdb->streamcontext, - array( - 'connector' => 'editor', - 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, - 'action' => 'updated', - ), - array( 'record_id' => $record->ID ) - ); - - update_stream_meta( $record->ID, 'theme_name', $theme_name ); - - if ( is_object( $theme ) ) { - update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); - } - } - } + add_filter( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_installer_edits_to_theme_editor_connector' ); } } @@ -261,10 +215,9 @@ function( $theme ) use ( $theme_name ) { * Function will migrate old options from the General and Connectors tabs into the new Exclude tab * * @param $labels array connectors terms labels - * @used wp_stream_after_connector_term_labels_loaded + * @filter wp_stream_after_connectors_registration */ public static function migrate_old_options_to_exclude_tab( $labels ) { - $old_options = get_option( WP_Stream_Settings::KEY, array() ); // Stream > Settings > General > Log Activity for @@ -289,4 +242,61 @@ public static function migrate_old_options_to_exclude_tab( $labels ) { update_option( WP_Stream_Settings::KEY, WP_Stream_Settings::$options ); } + /** + * Function will migrate theme file edit records from Installer connector to the Theme Editor connector + * + * @filter wp_stream_after_connectors_registration + */ + public static function migrate_installer_edits_to_theme_editor_connector() { + global $wpdb; + + $args = array( + 'connector' => 'installer', + 'context' => 'themes', + 'action' => 'edited', + ); + $records = stream_query( $args ); + + foreach ( $records as $record ) { + $file_name = get_stream_meta( $record->ID, 'file', true ); + $theme_name = get_stream_meta( $record->ID, 'name', true ); + + if ( '' !== $theme_name ) { + $matched_themes = array_filter( + wp_get_themes(), + function( $theme ) use ( $theme_name ) { + return (string) $theme === $theme_name; + } + ); + $theme = array_shift( $matched_themes ); + + // `stream` + $wpdb->update( + $wpdb->stream, + array( + 'summary' => sprintf( WP_Stream_Connector_Editor::get_message(), $file_name, $theme_name ), + ), + array( 'ID' => $record->ID ) + ); + + // `stream_context` + $wpdb->update( + $wpdb->streamcontext, + array( + 'connector' => 'editor', + 'context' => is_object( $theme ) ? $theme->get_template() : $theme_name, + 'action' => 'updated', + ), + array( 'record_id' => $record->ID ) + ); + + update_stream_meta( $record->ID, 'theme_name', $theme_name ); + + if ( is_object( $theme ) ) { + update_stream_meta( $record->ID, 'theme_slug', $theme->get_template() ); + } + } + } + } + } From fe62bae0fc803e52e8543c111b97bedc24bdb9ad Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Tue, 1 Apr 2014 08:51:30 +0200 Subject: [PATCH 44/46] [issue-313] Add action, not filter --- includes/install.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/install.php b/includes/install.php index acec59e2e..9c5fc9d0c 100644 --- a/includes/install.php +++ b/includes/install.php @@ -201,13 +201,13 @@ public static function update( $db_version, $current ) { // If version is lower than 1.3.0, do the update routine for site options // Backward settings compatibility for old version plugins if ( version_compare( $db_version, '1.3.0', '<' ) ) { - add_filter( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_old_options_to_exclude_tab' ); + add_action( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_old_options_to_exclude_tab' ); } // If version is lower than 1.3.1, do the update routine // Update records of Installer to Theme Editor connector if ( version_compare( $db_version, '1.3.1', '<' ) ) { - add_filter( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_installer_edits_to_theme_editor_connector' ); + add_action( 'wp_stream_after_connectors_registration', 'WP_Stream_Install::migrate_installer_edits_to_theme_editor_connector' ); } } @@ -215,7 +215,7 @@ public static function update( $db_version, $current ) { * Function will migrate old options from the General and Connectors tabs into the new Exclude tab * * @param $labels array connectors terms labels - * @filter wp_stream_after_connectors_registration + * @action wp_stream_after_connectors_registration */ public static function migrate_old_options_to_exclude_tab( $labels ) { $old_options = get_option( WP_Stream_Settings::KEY, array() ); @@ -245,7 +245,7 @@ public static function migrate_old_options_to_exclude_tab( $labels ) { /** * Function will migrate theme file edit records from Installer connector to the Theme Editor connector * - * @filter wp_stream_after_connectors_registration + * @action wp_stream_after_connectors_registration */ public static function migrate_installer_edits_to_theme_editor_connector() { global $wpdb; From 26967b51c24ecf0e817191ce4ade8193bcc378ad Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 1 Apr 2014 10:45:09 -0500 Subject: [PATCH 45/46] Summary tweak for theme editor updates --- connectors/editor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/editor.php b/connectors/editor.php index 24f3da9b1..4dbb1e55e 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -80,7 +80,7 @@ function( $theme ) { } public static function get_message() { - return __( '"%1$s" was updated in "%2$s"', 'stream' ); + return __( '"%1$s" in "%2$s" updated', 'stream' ); } /** From 989b1f0d3ba8fb41be2c329d8d31604c7adf8173 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 1 Apr 2014 10:47:56 -0500 Subject: [PATCH 46/46] Code format tweaks --- connectors/editor.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/editor.php b/connectors/editor.php index 4dbb1e55e..7f49c8edc 100644 --- a/connectors/editor.php +++ b/connectors/editor.php @@ -96,7 +96,7 @@ public static function action_links( $links, $record ) { $file_name = get_stream_meta( $record->ID, 'file', true ); $theme_slug = get_stream_meta( $record->ID, 'theme_slug', true ); - if ( $file_name !== '' && $theme_slug !== '' ) { + if ( '' !== $file_name && '' !== $theme_slug ) { $links[ __( 'Edit File', 'stream' ) ] = admin_url( sprintf( 'theme-editor.php?theme=%s&file=%s', @@ -146,7 +146,7 @@ public static function get_edition_data() { $file_path = $allowed_files['style.css']; } else { $file_name = $file; - $file_path = $theme->get_stylesheet_directory() . '/' . $file_name; + $file_path = sprintf( '%s/%s', $theme->get_stylesheet_directory(), $file_name ); } $file_contents_before = file_get_contents( $file_path );