From c30c934dec22c224cb7f815835814414eaa561e8 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 21:25:21 +0100 Subject: [PATCH 01/50] [issue-309] Add `get_changed_keys` method --- classes/connector.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/classes/connector.php b/classes/connector.php index 1c9fc18c1..241300f6c 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -138,4 +138,18 @@ public static function delayed_log_commit() { } } + public static function get_changed_keys( $old_value, $new_value ) { + if ( ! is_array( $old_value ) && ! is_array( $new_value ) ) { + return array(); + } + + if( ! is_array( $old_value ) ) { + return array_keys( $new_value ); + } + + if( ! is_array( $new_value ) ) { + return array_keys( $old_value ); + } + } + } From d7355382485e5c0f3f83cbd1ff329b1d81f0abaf Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 21:29:22 +0100 Subject: [PATCH 02/50] [issue-309] Doc for new method --- classes/connector.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/classes/connector.php b/classes/connector.php index 241300f6c..be685e6ca 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -138,6 +138,12 @@ public static function delayed_log_commit() { } } + /** + * Compare two values and return changed keys if they are arrays + * @param mixed $old_value Value before change + * @param mixed $new_value Value after change + * @return array + */ public static function get_changed_keys( $old_value, $new_value ) { if ( ! is_array( $old_value ) && ! is_array( $new_value ) ) { return array(); From 6a50574bcf8d2be7ed632a9a385c5be6d6793724 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 21:43:23 +0100 Subject: [PATCH 03/50] [issue-309] Return difference of arrays --- classes/connector.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/classes/connector.php b/classes/connector.php index be685e6ca..17099c4cf 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -156,6 +156,17 @@ public static function get_changed_keys( $old_value, $new_value ) { if( ! is_array( $new_value ) ) { return array_keys( $old_value ); } + + $diff = array_udiff_assoc( + $old_value, + $new_value, function( $value1, $value2 ) { + return maybe_serialize( $value1 ) !== maybe_serialize( $value2 ); + } + ); + + $result = array_keys( $diff ); + + return $result; } } From e87a6ffc86c1da2508f3f61c2a436bcf991f1680 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 21:51:38 +0100 Subject: [PATCH 04/50] [issue-309] Remove numeric indexes --- classes/connector.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/classes/connector.php b/classes/connector.php index 17099c4cf..e828bd134 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -166,7 +166,16 @@ public static function get_changed_keys( $old_value, $new_value ) { $result = array_keys( $diff ); - return $result; + // remove numeric indexes + $result = array_filter( + $result, + function( $value ) { + // check if is not valid number (is_int, is_numeric and ctype_digit are not enough) + return (string) (int) $value !== (string) $value; + } + ); + + return array_values( $result ); } } From 31aad9b908b97210ae218dec3781924a275cafb7 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:14:11 +0100 Subject: [PATCH 05/50] [issue-309] Treat missing keys as differences --- classes/connector.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/connector.php b/classes/connector.php index e828bd134..5159ac5ea 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -159,13 +159,20 @@ public static function get_changed_keys( $old_value, $new_value ) { $diff = array_udiff_assoc( $old_value, - $new_value, function( $value1, $value2 ) { + $new_value, + function( $value1, $value2 ) { return maybe_serialize( $value1 ) !== maybe_serialize( $value2 ); } ); $result = array_keys( $diff ); + // find unexisting keys in old or new value + $common_keys = array_keys( array_intersect_key( $old_value, $new_value ) ); + $unique_keys_old = array_values( array_diff( array_keys( $old_value ), $common_keys ) ); + $unique_keys_new = array_values( array_diff( array_keys( $new_value ), $common_keys ) ); + $result = array_merge( $result, $unique_keys_old, $unique_keys_new ); + // remove numeric indexes $result = array_filter( $result, @@ -175,7 +182,7 @@ function( $value ) { } ); - return array_values( $result ); + return array_values( array_unique( $result ) ); } } From de44c294463def9fa492bdaf5daaccf08f8e8e82 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:14:55 +0100 Subject: [PATCH 06/50] [issue-309] Add method to log theme modifications --- connectors/settings.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/connectors/settings.php b/connectors/settings.php index 478fdbc4d..214fb7533 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -40,6 +40,14 @@ public static function register() { parent::register(); add_action( 'admin_head', array( __CLASS__, 'highlight_field' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_jquery_color' ) ); + add_action( sprintf( 'update_option_theme_mods_%s', get_option( 'stylesheet' ) ), array( __CLASS__, 'log_theme_modification' ), 10, 2 ); + } + + /** + * @action update_option_theme_mods_{name} + */ + public static function log_theme_modification( $old_value, $new_value ) { + } /** From b4446de1996c8968d93908bf97cd46b5fe8640d0 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:21:29 +0100 Subject: [PATCH 07/50] [isue-309] Use updated option calback --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 214fb7533..9348b9ae1 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -47,7 +47,7 @@ public static function register() { * @action update_option_theme_mods_{name} */ public static function log_theme_modification( $old_value, $new_value ) { - + self::callback_updated_option( 'theme_mods', $old_value, $new_value ); } /** From 8309073fccd97cee94607bffec8f6a64505908bb Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:26:01 +0100 Subject: [PATCH 08/50] [issue-309] Use improved keys comparison method --- connectors/settings.php | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 9348b9ae1..7cbc585ca 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -314,23 +314,8 @@ public static function callback_updated_option( $option, $old_value, $value ) { $changed_options = array(); - if ( is_array( $old_value ) && is_array( $value ) ) { - $changed_keys = array(); - - // Added keys - $changed_keys = array_merge( $changed_keys, array_keys( array_diff_key( $value, $old_value ) ) ); - - // Deleted keys - $changed_keys = array_merge( $changed_keys, array_keys( array_diff_key( $old_value, $value ) ) ); - - // array_diff_assoc is not sufficient - foreach ( array_diff( array_keys( $value ), $changed_keys ) as $option_key ) { - if ( $value[$option_key] != $old_value[$option_key] ) { - $changed_keys[] = $option_key; - } - } - - foreach ( $changed_keys as $field_key ) { + if ( is_array( $old_value ) || is_array( $value ) ) { + foreach ( self::get_changed_keys( $old_value, $value ) as $field_key ) { $changed_options[] = array( 'label' => self::get_serialized_field_label( $option, $field_key ), 'option' => $current_key, From 73ba98bca432bbb23229da0bf1da523da8934707 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:35:25 +0100 Subject: [PATCH 09/50] [issue-309] Add translations to header mods --- connectors/settings.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 7cbc585ca..bf9af2186 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -188,7 +188,11 @@ public static function enqueue_jquery_color() { */ public static function get_serialized_field_label( $option_name, $field_key ) { $labels = array( - // to be updated + 'theme_mods' => array( + 'header_image' => __( 'Header Image', 'stream' ), + 'header_image_data' => __( 'Header Image Data', 'stream' ), + 'header_textcolor' => __( 'Text Color', 'stream' ), + ), ); /** From 97dd7f9528dccc0d4610afc509671d88ba2d8038 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 22:46:49 +0100 Subject: [PATCH 10/50] [issue-309] Pass context as argument --- connectors/settings.php | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index bf9af2186..c98d7c0f9 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -47,7 +47,7 @@ public static function register() { * @action update_option_theme_mods_{name} */ public static function log_theme_modification( $old_value, $new_value ) { - self::callback_updated_option( 'theme_mods', $old_value, $new_value ); + self::callback_updated_option( 'theme_mods', $old_value, $new_value, __( 'Custom Header', 'stream' ) ); } /** @@ -292,28 +292,30 @@ public static function callback_update_option_tag_base( $old_value, $value ) { * * @action updated_option */ - public static function callback_updated_option( $option, $old_value, $value ) { + public static function callback_updated_option( $option, $old_value, $value, $context = null ) { global $new_whitelist_options, $whitelist_options; if ( 0 === strpos( $option, '_transient_' ) ) { return; } - $options = array_merge( - (array) $whitelist_options, - $new_whitelist_options, - array( 'permalink' => self::$permalink_options ) - ); + if ( $context === null ) { + $options = array_merge( + (array) $whitelist_options, + $new_whitelist_options, + array( 'permalink' => self::$permalink_options ) + ); - foreach ( $options as $key => $opts ) { - if ( in_array( $option, $opts ) ) { - $current_key = $key; - break; + foreach ( $options as $key => $opts ) { + if ( in_array( $option, $opts ) ) { + $context = $key; + break; + } } } - if ( ! isset( $current_key ) ) { - $current_key = 'settings'; + if ( ! isset( $context ) ) { + $context = 'settings'; } $changed_options = array(); @@ -322,7 +324,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { foreach ( self::get_changed_keys( $old_value, $value ) as $field_key ) { $changed_options[] = array( 'label' => self::get_serialized_field_label( $option, $field_key ), - 'option' => $current_key, + 'option' => $context, // Prevent fatal error when saving option as array 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, @@ -344,7 +346,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { $properties, null, array( - $current_key => 'updated', + $context => 'updated', ) ); } From 592522a94e359c06e0d42c9e7d4538a9920283d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 23:21:24 +0100 Subject: [PATCH 11/50] [issue-309] Add translated labels for background options keys --- connectors/settings.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index c98d7c0f9..1821c2cf9 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -189,9 +189,17 @@ public static function enqueue_jquery_color() { public static function get_serialized_field_label( $option_name, $field_key ) { $labels = array( 'theme_mods' => array( - 'header_image' => __( 'Header Image', 'stream' ), - 'header_image_data' => __( 'Header Image Data', 'stream' ), - 'header_textcolor' => __( 'Text Color', 'stream' ), + // Custom Background + 'background_image' => __( 'Background Image', 'stream' ), + 'background_image_thumb' => __( 'Background Image Data', 'stream' ), + 'background_position_x' => __( 'Background Position', 'stream' ), + 'background_repeat' => __( 'Background Repeat', 'stream' ), + 'background_attachment' => __( 'Background Attachment', 'stream' ), + 'background_color' => __( 'Background Color', 'stream' ), + // Custom Header + 'header_image' => __( 'Header Image', 'stream' ), + 'header_image_data' => __( 'Header Image Data', 'stream' ), + 'header_textcolor' => __( 'Text Color', 'stream' ), ), ); From aecfb16f0e89d32387abf711487187eb8d5d1444 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 23:29:27 +0100 Subject: [PATCH 12/50] [issue-309] Add context labels --- connectors/settings.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 1821c2cf9..4c4f08781 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -77,14 +77,16 @@ public static function get_action_labels() { */ public static function get_context_labels() { return array( - 'settings' => __( 'Settings', 'stream' ), - 'general' => __( 'General', 'stream' ), - 'writing' => __( 'Writing', 'stream' ), - 'reading' => __( 'Reading', 'stream' ), - 'discussion' => __( 'Discussion', 'stream' ), - 'media' => __( 'Media', 'stream' ), - 'permalink' => __( 'Permalinks', 'stream' ), - 'wp_stream' => __( 'Stream', 'stream' ), + 'settings' => __( 'Settings', 'stream' ), + 'general' => __( 'General', 'stream' ), + 'writing' => __( 'Writing', 'stream' ), + 'reading' => __( 'Reading', 'stream' ), + 'discussion' => __( 'Discussion', 'stream' ), + 'media' => __( 'Media', 'stream' ), + 'permalink' => __( 'Permalinks', 'stream' ), + 'wp_stream' => __( 'Stream', 'stream' ), + 'custom-background' => __( 'Custom Background', 'stream' ), + 'custom-header' => __( 'Custom Header', 'stream' ), ); } From 79b14e760085667a1ffc291ea882ef9686bacfa9 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sat, 8 Mar 2014 23:31:04 +0100 Subject: [PATCH 13/50] [issue-309] Use context slug --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 4c4f08781..49abba3c6 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -47,7 +47,7 @@ public static function register() { * @action update_option_theme_mods_{name} */ public static function log_theme_modification( $old_value, $new_value ) { - self::callback_updated_option( 'theme_mods', $old_value, $new_value, __( 'Custom Header', 'stream' ) ); + self::callback_updated_option( 'theme_mods', $old_value, $new_value, 'custom-header' ); } /** From 615ad7829e84242680c4a712d2af05b6f6aa0537 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 11:42:00 +0100 Subject: [PATCH 14/50] [issue-305] Display link under Stream settings logs --- connectors/settings.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 478fdbc4d..4ca736020 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -217,11 +217,16 @@ public static function action_links( $links, $record ) { array( 2 => $submenu_slug ) ); - if ( ! empty( $found_submenus ) ) { + if ( ! empty( $found_submenus ) || $record->context === 'wp_stream' ) { $target_submenu = array_pop( $found_submenus ); if ( current_user_can( $target_submenu[1] ) ) { $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[$record->context] ); - $url = admin_url( $submenu_slug ); + + if ( 'wp_stream' === $record->context ) { + $url = add_query_arg( 'page', WP_Stream_Admin::SETTINGS_PAGE_SLUG, admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE ) ); + } else { + $url = admin_url( $submenu_slug ); + } $field_name = get_stream_meta( $record->ID, 'option', true ); if ( $field_name !== '' ) { From 16a73265f44bb30c4ce6ff2610aebb4f8b77633f Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 11:54:43 +0100 Subject: [PATCH 15/50] [issue-305] Filter action link url --- connectors/settings.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 4ca736020..3af143a4a 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -40,6 +40,7 @@ public static function register() { parent::register(); add_action( 'admin_head', array( __CLASS__, 'highlight_field' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_jquery_color' ) ); + add_filter( 'wp_stream_action_link_url', array( __CLASS__, 'stream_settings_url' ) ); } /** @@ -222,11 +223,7 @@ public static function action_links( $links, $record ) { if ( current_user_can( $target_submenu[1] ) ) { $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[$record->context] ); - if ( 'wp_stream' === $record->context ) { - $url = add_query_arg( 'page', WP_Stream_Admin::SETTINGS_PAGE_SLUG, admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE ) ); - } else { - $url = admin_url( $submenu_slug ); - } + $url = apply_filters( 'wp_stream_action_link_url', admin_url( $submenu_slug ), $record ); $field_name = get_stream_meta( $record->ID, 'option', true ); if ( $field_name !== '' ) { @@ -358,6 +355,13 @@ public static function callback_updated_option( $option, $old_value, $value ) { } } + /** + * @filter wp_stream_action_link_url + */ + public static function stream_settings_url( $record ) { + + } + /** * Add class to highlight field by URL param * From 204f24391c51c18c3025287ee544a59093359901 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 11:55:46 +0100 Subject: [PATCH 16/50] [issue-305] Pass record as argument --- connectors/settings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 3af143a4a..611c7e3a2 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -40,7 +40,7 @@ public static function register() { parent::register(); add_action( 'admin_head', array( __CLASS__, 'highlight_field' ) ); add_action( 'admin_enqueue_scripts', array( __CLASS__, 'enqueue_jquery_color' ) ); - add_filter( 'wp_stream_action_link_url', array( __CLASS__, 'stream_settings_url' ) ); + add_filter( 'wp_stream_action_link_url', array( __CLASS__, 'stream_settings_url' ), 10, 2 ); } /** @@ -358,7 +358,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { /** * @filter wp_stream_action_link_url */ - public static function stream_settings_url( $record ) { + public static function stream_settings_url( $url, $record ) { } From ddb27f7d016fcbcf92ae479103039ea515e7dce2 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 11:59:43 +0100 Subject: [PATCH 17/50] [issue-305] Set URL to Stream settings --- connectors/settings.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 611c7e3a2..71104c264 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -359,7 +359,11 @@ public static function callback_updated_option( $option, $old_value, $value ) { * @filter wp_stream_action_link_url */ public static function stream_settings_url( $url, $record ) { - + if ( 'wp_stream' === $record->context ) { + $url = add_query_arg( 'page', WP_Stream_Admin::SETTINGS_PAGE_SLUG, admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE ) ); + } + + return $url; } /** From 169ff47ce9e18cf07f96a97cbf966f7488aa6d35 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 12:05:16 +0100 Subject: [PATCH 18/50] [issue-305] Log option_key meta --- connectors/settings.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 71104c264..87aec9a93 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -326,11 +326,12 @@ public static function callback_updated_option( $option, $old_value, $value ) { foreach ( $changed_keys as $field_key ) { $changed_options[] = array( - 'label' => self::get_serialized_field_label( $option, $field_key ), - 'option' => $current_key, + 'label' => self::get_serialized_field_label( $option, $field_key ), + 'option' => $current_key, + 'option_key' => $field_key, // Prevent fatal error when saving option as array - 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, - 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, + 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, + 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, ); } } else { From 55394acd4011c4a5f38e10fdf6085b4b664072af Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 12:28:23 +0100 Subject: [PATCH 19/50] [issue-305] Find proper tab --- connectors/settings.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 87aec9a93..8d573b514 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -361,7 +361,28 @@ public static function callback_updated_option( $option, $old_value, $value ) { */ public static function stream_settings_url( $url, $record ) { if ( 'wp_stream' === $record->context ) { - $url = add_query_arg( 'page', WP_Stream_Admin::SETTINGS_PAGE_SLUG, admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE ) ); + $option_key = get_stream_meta( $record->ID, 'option_key', true ); + $url_tab = null; + + if ( $option_key !== '' ) { + foreach( WP_Stream_Settings::get_fields() as $tab_name => $tab_properties ) { + foreach( $tab_properties['fields'] as $field ) { + $field_key = sprintf( '%s_%s', $tab_name, $field['name'] ); + if ( $field_key === $option_key ) { + $url_tab = $tab_name; + break 2; + } + } + } + } + + $url = add_query_arg( + array( + 'page' => WP_Stream_Admin::SETTINGS_PAGE_SLUG, + 'tab' => $url_tab, + ), + admin_url( WP_Stream_Admin::ADMIN_PARENT_PAGE ) + ); } return $url; From 3c6efcaa4392406afed6c7fe2b192d2446406e52 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 12:31:38 +0100 Subject: [PATCH 20/50] [issue-305] Check option key first for highlighting --- connectors/settings.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 8d573b514..c62da1e92 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -225,8 +225,13 @@ public static function action_links( $links, $record ) { $url = apply_filters( 'wp_stream_action_link_url', admin_url( $submenu_slug ), $record ); - $field_name = get_stream_meta( $record->ID, 'option', true ); - if ( $field_name !== '' ) { + $field_name = get_stream_meta( $record->ID, 'option_key', true ); + + if( '' === $field_name ) { + $field_name = get_stream_meta( $record->ID, 'option', true ); + } + + if ( '' !== $field_name ) { $url = sprintf( '%s#%s%s', rtrim( preg_replace( '/#.*/', '', $url ), '/' ), self::HIGHLIGHT_FIELD_URL_HASH_PREFIX, $field_name ); } From e2b0ad5b843bd5d097a28176cc00fc53eb61157e Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 12:42:17 +0100 Subject: [PATCH 21/50] [issue-305] Fix JS error when non-numeric hash found --- ui/admin.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ui/admin.js b/ui/admin.js index 88c3665bc..b0b1096f9 100644 --- a/ui/admin.js +++ b/ui/admin.js @@ -219,7 +219,8 @@ jQuery(function($){ $panels = $('table.form-table'), $activeTab = $tabs.find('.nav-tab-active'), defaultIndex = $activeTab.length > 0 ? $tabs.find('a').index( $activeTab ) : 0, - currentHash = window.location.hash ? window.location.hash.match(/\d+/)[0] : defaultIndex, + hashIndex = window.location.hash.match(/^#(\d+)$/); + currentHash = ( hashIndex !== null ? hashIndex[1] : defaultIndex ), syncFormAction = function( index ) { var $optionsForm = $('input[name="option_page"][value="wp_stream"]').parent('form'); var currentAction = $optionsForm.attr('action'); From c2d63fdd066dd48aaae1125012d355971a60a4c1 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 12:50:10 +0100 Subject: [PATCH 22/50] [issue-305] Prevent hash overriding --- ui/admin.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/admin.js b/ui/admin.js index b0b1096f9..5eaff7144 100644 --- a/ui/admin.js +++ b/ui/admin.js @@ -229,10 +229,16 @@ jQuery(function($){ }; $tabs.on('click', 'a', function(){ - var index = $tabs.find('a').index( $(this) ); + var index = $tabs.find('a').index( $(this) ), + hashIndex = window.location.hash.match(/^#(\d+)$/); + $panels.hide().eq(index).show(); $tabs.find('a').removeClass('nav-tab-active').filter($(this)).addClass('nav-tab-active'); - window.location.hash = index; + + if ( window.location.hash === '' || hashIndex !== null ) { + window.location.hash = index; + } + syncFormAction(index); return false; }); From 62f94dc278270a4b100f815de78047d1d8074f54 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:20:12 +0100 Subject: [PATCH 23/50] [issue-305] Fix label for --- connectors/settings.php | 13 ++++++++++--- includes/settings.php | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index c62da1e92..61b04fc4c 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -415,13 +415,20 @@ public static function highlight_field() { return $(this).attr("name") === fieldName; }); + if ( $field.length === 0 ) { + fieldName = "wp_stream[" + fieldName + "]"; + $field = $("#" + fieldName.replace("[", "\\\[").replace("]", "\\\]") + " ul"); + } + $("html, body") .animate({ scrollTop: ($field.closest("tr").length === 1 ? $field.closest("tr") : $field).offset().top - $("#wpadminbar").height() }, 1000, function () { - $field.animate({ - backgroundColor: "#fffedf" - }, 250); + $field + .css("background", "#fff") + .animate({ + backgroundColor: "#fffedf", + }, 250); $("label") .filter(function () { diff --git a/includes/settings.php b/includes/settings.php index 81ef1d65a..18ef5acd4 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -313,7 +313,7 @@ public static function register_settings() { $section_name, $field + array( 'section' => $section_name, - 'label_for' => sprintf( '%s_%s_%s', self::KEY, $section_name, $field['name'] ), // xss ok + 'label_for' => sprintf( '%s[%s_%s]', self::KEY, $section_name, $field['name'] ), // xss ok ) ); } From 01429d1b41fb747daa80bb1258cfaa5f5a0a12ba Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:20:40 +0100 Subject: [PATCH 24/50] Revert "[issue-305] Fix label for" This reverts commit 62f94dc278270a4b100f815de78047d1d8074f54. --- connectors/settings.php | 13 +++---------- includes/settings.php | 2 +- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 61b04fc4c..c62da1e92 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -415,20 +415,13 @@ public static function highlight_field() { return $(this).attr("name") === fieldName; }); - if ( $field.length === 0 ) { - fieldName = "wp_stream[" + fieldName + "]"; - $field = $("#" + fieldName.replace("[", "\\\[").replace("]", "\\\]") + " ul"); - } - $("html, body") .animate({ scrollTop: ($field.closest("tr").length === 1 ? $field.closest("tr") : $field).offset().top - $("#wpadminbar").height() }, 1000, function () { - $field - .css("background", "#fff") - .animate({ - backgroundColor: "#fffedf", - }, 250); + $field.animate({ + backgroundColor: "#fffedf" + }, 250); $("label") .filter(function () { diff --git a/includes/settings.php b/includes/settings.php index 18ef5acd4..81ef1d65a 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -313,7 +313,7 @@ public static function register_settings() { $section_name, $field + array( 'section' => $section_name, - 'label_for' => sprintf( '%s[%s_%s]', self::KEY, $section_name, $field['name'] ), // xss ok + 'label_for' => sprintf( '%s_%s_%s', self::KEY, $section_name, $field['name'] ), // xss ok ) ); } From 7bda4aa395b0559db153956a8be69134cfe6507c Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:21:30 +0100 Subject: [PATCH 25/50] Fix label for --- includes/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/settings.php b/includes/settings.php index 81ef1d65a..18ef5acd4 100644 --- a/includes/settings.php +++ b/includes/settings.php @@ -313,7 +313,7 @@ public static function register_settings() { $section_name, $field + array( 'section' => $section_name, - 'label_for' => sprintf( '%s_%s_%s', self::KEY, $section_name, $field['name'] ), // xss ok + 'label_for' => sprintf( '%s[%s_%s]', self::KEY, $section_name, $field['name'] ), // xss ok ) ); } From 3e2f73a2b067eedc756206b0b674414d8e6da8c7 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:25:17 +0100 Subject: [PATCH 26/50] [issue-305] Highlight stream setting --- connectors/settings.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index c62da1e92..68dff13f6 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -415,13 +415,20 @@ public static function highlight_field() { return $(this).attr("name") === fieldName; }); + if ( $field.length === 0 ) { + fieldName = "wp_stream[" + fieldName + "]"; + $field = $("#" + fieldName.replace("[", "\\\[").replace("]", "\\\]") + " ul"); + } + $("html, body") .animate({ scrollTop: ($field.closest("tr").length === 1 ? $field.closest("tr") : $field).offset().top - $("#wpadminbar").height() }, 1000, function () { - $field.animate({ - backgroundColor: "#fffedf" - }, 250); + $field + .css("background", $(this).css("background-color")) + .animate({ + backgroundColor: "#fffedf", + }, 250); $("label") .filter(function () { From c54103f63b76fcf8fa43e2c680eb4a33dd820145 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:31:27 +0100 Subject: [PATCH 27/50] [issue-305] Handle select2 --- connectors/settings.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 68dff13f6..6c5885ca2 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -405,6 +405,8 @@ public static function highlight_field() { $(function () { var hashPrefix = , fieldName = "", + escapedFieldName = "", + $select2UL = {}, $field = {}; if (location.hash.substr(1, hashPrefix.length) === hashPrefix) { @@ -417,7 +419,12 @@ public static function highlight_field() { if ( $field.length === 0 ) { fieldName = "wp_stream[" + fieldName + "]"; - $field = $("#" + fieldName.replace("[", "\\\[").replace("]", "\\\]") + " ul"); + escapedFieldName = fieldName.replace("[", "\\\[").replace("]", "\\\]"); + $field = $("#" + escapedFieldName); + $select2UL = $field.find("ul"); + if ( $select2UL.length === 1 ) { + $field = $select2UL; + } } $("html, body") From c19ad1b6a29e57061a7942c4601a2d343597e708 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 13:52:19 +0100 Subject: [PATCH 28/50] [issue-305] Handle multiple ID formats --- connectors/settings.php | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 6c5885ca2..65a70b68a 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -404,26 +404,35 @@ public static function highlight_field() { (function ($) { $(function () { var hashPrefix = , - fieldName = "", - escapedFieldName = "", - $select2UL = {}, + hashFieldName = "", + fieldNames = [], + $select2Choices = {}, $field = {}; if (location.hash.substr(1, hashPrefix.length) === hashPrefix) { - fieldName = location.hash.substr(hashPrefix.length + 1); + hashFieldName = location.hash.substr(hashPrefix.length + 1); + fieldNames = [hashFieldName]; $field = $("input, textarea, select") .filter(function () { - return $(this).attr("name") === fieldName; + return fieldNames.indexOf($(this).attr("name")) > -1; }); + // try to find wp_stream field if ( $field.length === 0 ) { - fieldName = "wp_stream[" + fieldName + "]"; - escapedFieldName = fieldName.replace("[", "\\\[").replace("]", "\\\]"); - $field = $("#" + escapedFieldName); - $select2UL = $field.find("ul"); - if ( $select2UL.length === 1 ) { - $field = $select2UL; + fieldNames = [ + "wp_stream_" + hashFieldName, + "wp_stream[" + hashFieldName + "]" + ]; + + $field = $("input, textarea, select, div").filter(function() { + return fieldNames.indexOf( $(this).attr("id") ) > -1; + }); + + // if the field has been selectified, the list is the one to be colorized + $select2Choices = $field.find(".select2-choices"); + if ( $select2Choices.length === 1 ) { + $field = $select2Choices; } } @@ -439,7 +448,7 @@ public static function highlight_field() { $("label") .filter(function () { - return $(this).attr("for") === fieldName; + return fieldNames.indexOf( $(this).attr("for") ) > -1; }) .animate({ color: "#d54e21" From ade37bf69892606c4067f62c0da6c5b2253cdf49 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 21:21:42 +0100 Subject: [PATCH 29/50] [issue-309] Remove context arg --- connectors/settings.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 49abba3c6..9a3897d5e 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -47,7 +47,7 @@ public static function register() { * @action update_option_theme_mods_{name} */ public static function log_theme_modification( $old_value, $new_value ) { - self::callback_updated_option( 'theme_mods', $old_value, $new_value, 'custom-header' ); + self::callback_updated_option( 'theme_mods', $old_value, $new_value ); } /** @@ -302,25 +302,23 @@ public static function callback_update_option_tag_base( $old_value, $value ) { * * @action updated_option */ - public static function callback_updated_option( $option, $old_value, $value, $context = null ) { + public static function callback_updated_option( $option, $old_value, $value ) { global $new_whitelist_options, $whitelist_options; if ( 0 === strpos( $option, '_transient_' ) ) { return; } - if ( $context === null ) { - $options = array_merge( - (array) $whitelist_options, - $new_whitelist_options, - array( 'permalink' => self::$permalink_options ) - ); + $options = array_merge( + (array) $whitelist_options, + $new_whitelist_options, + array( 'permalink' => self::$permalink_options ) + ); - foreach ( $options as $key => $opts ) { - if ( in_array( $option, $opts ) ) { - $context = $key; - break; - } + foreach ( $options as $key => $opts ) { + if ( in_array( $option, $opts ) ) { + $context = $key; + break; } } From a1003e9e83a0da9ad2a094efd2e45487b6859202 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 21:29:35 +0100 Subject: [PATCH 30/50] [issue-309] Add get_context_by_key method --- connectors/settings.php | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/connectors/settings.php b/connectors/settings.php index 9a3897d5e..248ff9eb2 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -90,6 +90,37 @@ public static function get_context_labels() { ); } + /** + * Return context by option name and key + * + * @return string Context slug + */ + public static function get_context_by_key( $option_name, $key ) { + $contexts = array( + 'custom-background' => array( + 'background_image', + 'background_image_thumb', + 'background_position_x', + 'background_repeat', + 'background_attachment', + 'background_color', + ), + 'custom-header' => array( + 'header_image', + 'header_image_data', + 'header_textcolor', + ), + ); + + foreach ( $contexts as $context => $keys ) { + if ( in_array( $key, $keys ) ) { + return $context; + } + } + + return false; + } + /** * Return translated labels for all default Settings fields found in WordPress. * From 09496deaf6e3ffab7dc1e0747210ef2e145bd0bd Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 21:36:49 +0100 Subject: [PATCH 31/50] [issue-309] Override context by key --- connectors/settings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 248ff9eb2..567e2a04c 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -361,9 +361,10 @@ public static function callback_updated_option( $option, $old_value, $value ) { if ( is_array( $old_value ) || is_array( $value ) ) { foreach ( self::get_changed_keys( $old_value, $value ) as $field_key ) { + $key_context = self::get_context_by_key( $option, $field_key ); $changed_options[] = array( 'label' => self::get_serialized_field_label( $option, $field_key ), - 'option' => $context, + 'option' => ( $key_context !== false ? $key_context : $context ), // Prevent fatal error when saving option as array 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, From 02142127b39e825874e877ef134fd5b44c70ee85 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 21:40:20 +0100 Subject: [PATCH 32/50] [issue-309] Add option name to hierarchy --- connectors/settings.php | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 567e2a04c..57c49aa13 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -97,24 +97,28 @@ public static function get_context_labels() { */ public static function get_context_by_key( $option_name, $key ) { $contexts = array( - 'custom-background' => array( - 'background_image', - 'background_image_thumb', - 'background_position_x', - 'background_repeat', - 'background_attachment', - 'background_color', - ), - 'custom-header' => array( - 'header_image', - 'header_image_data', - 'header_textcolor', + 'theme_mods' => array( + 'custom-background' => array( + 'background_image', + 'background_image_thumb', + 'background_position_x', + 'background_repeat', + 'background_attachment', + 'background_color', + ), + 'custom-header' => array( + 'header_image', + 'header_image_data', + 'header_textcolor', + ), ), ); - foreach ( $contexts as $context => $keys ) { - if ( in_array( $key, $keys ) ) { - return $context; + if ( isset( $contexts[$option_name] ) ) { + foreach ( $contexts[$option_name] as $context => $keys ) { + if ( in_array( $key, $keys ) ) { + return $context; + } } } From 1a1fc96ae94cb388e142b15375406495704a7d91 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 21:46:30 +0100 Subject: [PATCH 33/50] [issue-309] Log key context --- connectors/settings.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 57c49aa13..598531ca8 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -368,7 +368,8 @@ public static function callback_updated_option( $option, $old_value, $value ) { $key_context = self::get_context_by_key( $option, $field_key ); $changed_options[] = array( 'label' => self::get_serialized_field_label( $option, $field_key ), - 'option' => ( $key_context !== false ? $key_context : $context ), + 'option' => $option, + 'context' => ( false !== $key_context ? $key_context : $context ), // Prevent fatal error when saving option as array 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, @@ -378,6 +379,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { $changed_options[] = array( 'label' => self::get_field_label( $option ), 'option' => $option, + 'context' => $context, // Prevent fatal error when saving option as array 'old_value' => maybe_serialize( $old_value ), 'value' => maybe_serialize( $value ), @@ -390,7 +392,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { $properties, null, array( - $context => 'updated', + $properties['context'] => 'updated', ) ); } From c43594722c9b5bd0ed7e62cc1ec9d3b788490d36 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 22:02:59 +0100 Subject: [PATCH 34/50] [issue-309] Keep array key in variable --- connectors/settings.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 598531ca8..be8f512cc 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -387,12 +387,13 @@ public static function callback_updated_option( $option, $old_value, $value ) { } foreach ( $changed_options as $properties ) { + $context = $properties['context']; self::log( __( '"%s" setting was updated', 'stream' ), $properties, null, array( - $properties['context'] => 'updated', + $context => 'updated', ) ); } From b851526eaba71c732c13f46861940cfdcca538fe Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 22:11:45 +0100 Subject: [PATCH 35/50] [issue-305] Syntax tweaks --- connectors/settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 65a70b68a..bc51ee8b6 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -227,7 +227,7 @@ public static function action_links( $links, $record ) { $field_name = get_stream_meta( $record->ID, 'option_key', true ); - if( '' === $field_name ) { + if ( '' === $field_name ) { $field_name = get_stream_meta( $record->ID, 'option', true ); } @@ -367,11 +367,11 @@ public static function callback_updated_option( $option, $old_value, $value ) { public static function stream_settings_url( $url, $record ) { if ( 'wp_stream' === $record->context ) { $option_key = get_stream_meta( $record->ID, 'option_key', true ); - $url_tab = null; + $url_tab = null; if ( $option_key !== '' ) { - foreach( WP_Stream_Settings::get_fields() as $tab_name => $tab_properties ) { - foreach( $tab_properties['fields'] as $field ) { + foreach ( WP_Stream_Settings::get_fields() as $tab_name => $tab_properties ) { + foreach ( $tab_properties['fields'] as $field ) { $field_key = sprintf( '%s_%s', $tab_name, $field['name'] ); if ( $field_key === $option_key ) { $url_tab = $tab_name; From 9b16e979b4d15e9c50ac4716ccb826d3b66a7af4 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 22:14:33 +0100 Subject: [PATCH 36/50] [issue-309] Syntax tweaks --- classes/connector.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/classes/connector.php b/classes/connector.php index 5159ac5ea..14452fec4 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -149,11 +149,11 @@ public static function get_changed_keys( $old_value, $new_value ) { return array(); } - if( ! is_array( $old_value ) ) { + if ( ! is_array( $old_value ) ) { return array_keys( $new_value ); } - if( ! is_array( $new_value ) ) { + if ( ! is_array( $new_value ) ) { return array_keys( $old_value ); } From f530250471415d6dcf97a36ef8cb6fd2f40e7c6b Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Sun, 9 Mar 2014 22:21:50 +0100 Subject: [PATCH 37/50] [issue-305] Improve JS syntax --- ui/admin.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/admin.js b/ui/admin.js index 5eaff7144..d69814fc2 100644 --- a/ui/admin.js +++ b/ui/admin.js @@ -219,7 +219,7 @@ jQuery(function($){ $panels = $('table.form-table'), $activeTab = $tabs.find('.nav-tab-active'), defaultIndex = $activeTab.length > 0 ? $tabs.find('a').index( $activeTab ) : 0, - hashIndex = window.location.hash.match(/^#(\d+)$/); + hashIndex = window.location.hash.match(/^#(\d+)$/), currentHash = ( hashIndex !== null ? hashIndex[1] : defaultIndex ), syncFormAction = function( index ) { var $optionsForm = $('input[name="option_page"][value="wp_stream"]').parent('form'); @@ -230,7 +230,7 @@ jQuery(function($){ $tabs.on('click', 'a', function(){ var index = $tabs.find('a').index( $(this) ), - hashIndex = window.location.hash.match(/^#(\d+)$/); + hashIndex = window.location.hash.match(/^#(\d+)$/); $panels.hide().eq(index).show(); $tabs.find('a').removeClass('nav-tab-active').filter($(this)).addClass('nav-tab-active'); From 206ce8a5b1ed689f1ff03fd55dd5802723741b43 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 08:03:12 +0100 Subject: [PATCH 38/50] [issue-309] Use underscores instead of dashes --- connectors/settings.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index be8f512cc..0d23978b5 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -85,8 +85,8 @@ public static function get_context_labels() { 'media' => __( 'Media', 'stream' ), 'permalink' => __( 'Permalinks', 'stream' ), 'wp_stream' => __( 'Stream', 'stream' ), - 'custom-background' => __( 'Custom Background', 'stream' ), - 'custom-header' => __( 'Custom Header', 'stream' ), + 'custom_background' => __( 'Custom Background', 'stream' ), + 'custom_header' => __( 'Custom Header', 'stream' ), ); } @@ -98,7 +98,7 @@ public static function get_context_labels() { public static function get_context_by_key( $option_name, $key ) { $contexts = array( 'theme_mods' => array( - 'custom-background' => array( + 'custom_background' => array( 'background_image', 'background_image_thumb', 'background_position_x', @@ -106,7 +106,7 @@ public static function get_context_by_key( $option_name, $key ) { 'background_attachment', 'background_color', ), - 'custom-header' => array( + 'custom_header' => array( 'header_image', 'header_image_data', 'header_textcolor', From 9578ad5073ee1522d22eaf042732f1822424c4d1 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 08:31:43 +0100 Subject: [PATCH 39/50] [issue-309] Remove ignored fields --- connectors/settings.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 0d23978b5..a4ee31b6c 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -100,7 +100,6 @@ public static function get_context_by_key( $option_name, $key ) { 'theme_mods' => array( 'custom_background' => array( 'background_image', - 'background_image_thumb', 'background_position_x', 'background_repeat', 'background_attachment', @@ -108,7 +107,6 @@ public static function get_context_by_key( $option_name, $key ) { ), 'custom_header' => array( 'header_image', - 'header_image_data', 'header_textcolor', ), ), @@ -228,14 +226,12 @@ public static function get_serialized_field_label( $option_name, $field_key ) { 'theme_mods' => array( // Custom Background 'background_image' => __( 'Background Image', 'stream' ), - 'background_image_thumb' => __( 'Background Image Data', 'stream' ), 'background_position_x' => __( 'Background Position', 'stream' ), 'background_repeat' => __( 'Background Repeat', 'stream' ), 'background_attachment' => __( 'Background Attachment', 'stream' ), 'background_color' => __( 'Background Color', 'stream' ), // Custom Header 'header_image' => __( 'Header Image', 'stream' ), - 'header_image_data' => __( 'Header Image Data', 'stream' ), 'header_textcolor' => __( 'Text Color', 'stream' ), ), ); From 94f481cc29a78931abaae4673084d1b791bbf5f6 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 08:37:28 +0100 Subject: [PATCH 40/50] [issue-309] Add `is_key_ignored` method --- connectors/settings.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/connectors/settings.php b/connectors/settings.php index a4ee31b6c..cfbd6d586 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -123,6 +123,26 @@ public static function get_context_by_key( $option_name, $key ) { return false; } + /** + * Find out if the option key should be ignored and not logged + * + * @return bool Whether option key is ignored or not + */ + public static function is_key_ignored( $option_name, $key ) { + $ignored = array( + 'theme_mods' => array( + 'background_image_thumb', + 'header_image_data', + ), + ); + + if ( isset( $ignored[$option_name] ) ) { + return in_array( $key, $ignored[$option_name] ) ); + } + + return false; + } + /** * Return translated labels for all default Settings fields found in WordPress. * From 9bcad14de7eb8aedd977c798e189d72f15a594f3 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 08:42:40 +0100 Subject: [PATCH 41/50] [issue-309] Fix parentheses --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index cfbd6d586..97fe39c69 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -137,7 +137,7 @@ public static function is_key_ignored( $option_name, $key ) { ); if ( isset( $ignored[$option_name] ) ) { - return in_array( $key, $ignored[$option_name] ) ); + return in_array( $key, $ignored[$option_name] ); } return false; From cafa5b9bae92e660b6d55fe4c986ccb0c522dcc6 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 08:44:57 +0100 Subject: [PATCH 42/50] [issue-309] Don't log ignored keys --- connectors/settings.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 97fe39c69..568ff02ba 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -381,15 +381,17 @@ public static function callback_updated_option( $option, $old_value, $value ) { if ( is_array( $old_value ) || is_array( $value ) ) { foreach ( self::get_changed_keys( $old_value, $value ) as $field_key ) { - $key_context = self::get_context_by_key( $option, $field_key ); - $changed_options[] = array( - 'label' => self::get_serialized_field_label( $option, $field_key ), - 'option' => $option, - 'context' => ( false !== $key_context ? $key_context : $context ), - // Prevent fatal error when saving option as array - 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, - 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, - ); + if ( ! self::is_key_ignored( $option, $field_key ) ) { + $key_context = self::get_context_by_key( $option, $field_key ); + $changed_options[] = array( + 'label' => self::get_serialized_field_label( $option, $field_key ), + 'option' => $option, + 'context' => ( false !== $key_context ? $key_context : $context ), + // Prevent fatal error when saving option as array + 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, + 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, + ); + } } } else { $changed_options[] = array( From 975cca934a6c1be7324d08e758209a88ad0d8add Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 09:13:43 +0100 Subject: [PATCH 43/50] [issue-309] Improve spacing in Settings connector --- connectors/settings.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 568ff02ba..49ce1c0d0 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -112,8 +112,8 @@ public static function get_context_by_key( $option_name, $key ) { ), ); - if ( isset( $contexts[$option_name] ) ) { - foreach ( $contexts[$option_name] as $context => $keys ) { + if ( isset( $contexts[ $option_name ] ) ) { + foreach ( $contexts[ $option_name ] as $context => $keys ) { if ( in_array( $key, $keys ) ) { return $context; } @@ -136,8 +136,8 @@ public static function is_key_ignored( $option_name, $key ) { ), ); - if ( isset( $ignored[$option_name] ) ) { - return in_array( $key, $ignored[$option_name] ); + if ( isset( $ignored[ $option_name ] ) ) { + return in_array( $key, $ignored[ $option_name ] ); } return false; @@ -219,8 +219,8 @@ public static function get_field_label( $field_key ) { 'tag_base' => __( 'Tag base', 'stream' ), ); - if ( isset( $labels[$field_key] ) ) { - return $labels[$field_key]; + if ( isset( $labels[ $field_key ] ) ) { + return $labels[ $field_key ]; } return $field_key; @@ -264,8 +264,8 @@ public static function get_serialized_field_label( $option_name, $field_key ) { */ $labels = apply_filters( 'wp_stream_serialized_labels', $labels ); - if ( isset( $labels[$option_name] ) && isset( $labels[$option_name][$field_key] ) ) { - return $labels[$option_name][$field_key]; + if ( isset( $labels[ $option_name ] ) && isset( $labels[ $option_name ][ $field_key ] ) ) { + return $labels[ $option_name ][ $field_key ]; } return $field_key; @@ -293,7 +293,7 @@ public static function action_links( $links, $record ) { if ( ! empty( $found_submenus ) ) { $target_submenu = array_pop( $found_submenus ); if ( current_user_can( $target_submenu[1] ) ) { - $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[$record->context] ); + $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[ $record->context ] ); $url = admin_url( $submenu_slug ); $field_name = get_stream_meta( $record->ID, 'option', true ); @@ -388,8 +388,8 @@ public static function callback_updated_option( $option, $old_value, $value ) { 'option' => $option, 'context' => ( false !== $key_context ? $key_context : $context ), // Prevent fatal error when saving option as array - 'old_value' => isset( $old_value[$field_key] ) ? maybe_serialize( $old_value[$field_key] ) : null, - 'value' => isset( $value[$field_key] ) ? maybe_serialize( $value[$field_key] ) : null, + 'old_value' => isset( $old_value[ $field_key ] ) ? maybe_serialize( $old_value[ $field_key ] ) : null, + 'value' => isset( $value[ $field_key ] ) ? maybe_serialize( $value[ $field_key ] ) : null, ); } } From 9891d30ca2b601e93bf032d6cf7664dbc56db2c2 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Mon, 10 Mar 2014 09:16:26 +0100 Subject: [PATCH 44/50] [issue-309] Improve spacing in Connector class --- classes/connector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/connector.php b/classes/connector.php index 14452fec4..315e71d3c 100644 --- a/classes/connector.php +++ b/classes/connector.php @@ -124,7 +124,7 @@ public static function delayed_log( $handle ) { $args = func_get_args(); array_shift( $args ); - self::$delayed[$handle] = $args; + self::$delayed[ $handle ] = $args; add_action( 'shutdown', array( __CLASS__, 'delayed_log_commit' ) ); } From 45fad3606dd35138db5b6f4728566527726f819a Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Mon, 10 Mar 2014 14:25:56 -0500 Subject: [PATCH 45/50] Use Yoda style --- connectors/settings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index fb38ac8d4..b927d3a6b 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -224,7 +224,7 @@ public static function action_links( $links, $record ) { array( 2 => $submenu_slug ) ); - if ( ! empty( $found_submenus ) || $record->context === 'wp_stream' ) { + if ( ! empty( $found_submenus ) || 'wp_stream' === $record->context ) { $target_submenu = array_pop( $found_submenus ); if ( current_user_can( $target_submenu[1] ) ) { @@ -374,7 +374,7 @@ public static function stream_settings_url( $url, $record ) { $option_key = get_stream_meta( $record->ID, 'option_key', true ); $url_tab = null; - if ( $option_key !== '' ) { + if ( '' !== $option_key ) { foreach ( WP_Stream_Settings::get_fields() as $tab_name => $tab_properties ) { foreach ( $tab_properties['fields'] as $field ) { $field_key = sprintf( '%s_%s', $tab_name, $field['name'] ); From 0240b1790d18f7831409cb3f7205e782e66b333c Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Mon, 10 Mar 2014 14:58:42 -0500 Subject: [PATCH 46/50] Fix undefined var notice caused by merge --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 267fa4eeb..dbe56fc85 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -417,7 +417,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { __( '"%s" setting was updated', 'stream' ), $properties, null, - array( $current_key => 'updated' ) + array( $context => 'updated' ) ); } } From dd8df71619ebc8a863977f2701b859d6f0e2b100 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Tue, 11 Mar 2014 07:37:18 +0100 Subject: [PATCH 47/50] [issue-305] Check if submenu data is array --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index b927d3a6b..12ea17847 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -227,7 +227,7 @@ public static function action_links( $links, $record ) { if ( ! empty( $found_submenus ) || 'wp_stream' === $record->context ) { $target_submenu = array_pop( $found_submenus ); - if ( current_user_can( $target_submenu[1] ) ) { + if ( is_array( $target_submenu ) && current_user_can( $target_submenu[1] ) ) { $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[$record->context] ); $url = apply_filters( 'wp_stream_action_link_url', admin_url( $submenu_slug ), $record ); From ff88ed811f1281103b1d04692388ff5668509653 Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Tue, 11 Mar 2014 07:56:11 +0100 Subject: [PATCH 48/50] [issue-305] Improve condition logic --- connectors/settings.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connectors/settings.php b/connectors/settings.php index 12ea17847..2bf4ef2d8 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -227,7 +227,7 @@ public static function action_links( $links, $record ) { if ( ! empty( $found_submenus ) || 'wp_stream' === $record->context ) { $target_submenu = array_pop( $found_submenus ); - if ( is_array( $target_submenu ) && current_user_can( $target_submenu[1] ) ) { + if ( ! is_array( $target_submenu ) || current_user_can( $target_submenu[1] ) ) { $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[$record->context] ); $url = apply_filters( 'wp_stream_action_link_url', admin_url( $submenu_slug ), $record ); From 6795fe574385c8447cc574bfa718193236dbf58a Mon Sep 17 00:00:00 2001 From: Krzysztof Powelski Date: Tue, 11 Mar 2014 09:32:22 +0100 Subject: [PATCH 49/50] [issue-309] Generate valid URLs for action links --- connectors/settings.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index ff2c58e9c..01e64b899 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -292,8 +292,8 @@ public static function action_links( $links, $record ) { 'submenu_slug' => function( $record ) { return str_replace( '_', '-', $record->context ); }, - 'url' => function( $destination ) { - return add_query_arg( $destination['url'], 'page', $destination['menu_slug'] ); + 'url' => function( $rule, $record ) { + return add_query_arg( 'page', $rule['submenu_slug']( $record ), admin_url( $rule['menu_slug'] ) ); }, 'applicable' => function( $submenu, $record ) { return in_array( $record->context, array( 'custom_header', 'custom_background' ) ); @@ -304,8 +304,8 @@ public static function action_links( $links, $record ) { 'submenu_slug' => function( $record ) { return sprintf( 'options-%s.php', $record->context ); }, - 'url' => function( $destination ) { - return $destination['url']; + 'url' => function( $rule, $record ) { + return admin_url( $rule['submenu_slug']( $record ) ); }, 'applicable' => function( $submenu, $record ) { return ! empty( $submenu['options-general.php'] ); @@ -325,16 +325,19 @@ function( $rule ) use ( $submenu, $record ) { if ( ! empty( $applicable_rules ) ) { // The first applicable rule wins - $rule = array_shift( $applicable_rules ); + $rule = array_shift( $applicable_rules ); + $menu_slug = $rule['menu_slug']; + $submenu_slug = $rule['submenu_slug']( $record ); + $url = $rule['url']( $rule, $record ); $found_submenus = wp_list_filter( - $submenu[$rule['menu_slug']], - array( 2 => $rule['submenu_slug'] ) + $submenu[ $menu_slug ], + array( 2 => $submenu_slug ) ); if ( ! empty( $found_submenus ) ) { $target_submenu = array_pop( $found_submenus ); - list( $section_label, $capability, $section_page ) = $target_submenu; + list( $menu_title, $capability ) = $target_submenu; if ( current_user_can( $capability ) ) { $text = sprintf( __( 'Edit %s Settings', 'stream' ), $context_labels[ $record->context ] ); From e366c3f97b82df570af2925c703555fa24e75ed0 Mon Sep 17 00:00:00 2001 From: Frankie Jarrett Date: Tue, 11 Mar 2014 13:14:12 -0500 Subject: [PATCH 50/50] Cast second var as an array inside array_merge --- connectors/settings.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/connectors/settings.php b/connectors/settings.php index 01e64b899..a0ed17780 100644 --- a/connectors/settings.php +++ b/connectors/settings.php @@ -400,7 +400,7 @@ public static function callback_update_option_tag_base( $old_value, $value ) { * @action updated_option */ public static function callback_updated_option( $option, $old_value, $value ) { - global $new_whitelist_options, $whitelist_options; + global $whitelist_options, $new_whitelist_options; if ( 0 === strpos( $option, '_transient_' ) ) { return; @@ -408,7 +408,7 @@ public static function callback_updated_option( $option, $old_value, $value ) { $options = array_merge( (array) $whitelist_options, - $new_whitelist_options, + (array) $new_whitelist_options, array( 'permalink' => self::$permalink_options ) );