diff --git a/assets/css/src/blocks/_categories.scss b/assets/css/src/blocks/_categories.scss index 0511630..7af573f 100644 --- a/assets/css/src/blocks/_categories.scss +++ b/assets/css/src/blocks/_categories.scss @@ -10,7 +10,7 @@ li { margin: 5px; - background-color: var(--wp--preset--color--raft-bg-alt); + background-color: var(--wp--preset--color--ti-bg-alt); border-radius: 25px; padding: 8px 24px; } diff --git a/assets/css/src/blocks/_image.scss b/assets/css/src/blocks/_image.scss index a7c95da..746abcd 100644 --- a/assets/css/src/blocks/_image.scss +++ b/assets/css/src/blocks/_image.scss @@ -28,7 +28,7 @@ figure.wp-block-image { figcaption { @extend %figcaption; - color: var(--wp--preset--color--raft-fg); + color: var(--wp--preset--color--ti-fg); opacity: 0.6; } } diff --git a/assets/css/src/blocks/_navigation.scss b/assets/css/src/blocks/_navigation.scss index 172568c..9155a05 100644 --- a/assets/css/src/blocks/_navigation.scss +++ b/assets/css/src/blocks/_navigation.scss @@ -1,7 +1,7 @@ // Overwrite the selector... .wp-block-navigation:not(.has-background) .wp-block-navigation__responsive-container.is-menu-open { - background: var(--wp--preset--color--raft-bg); - color: var(--wp--preset--color--raft-fg); + background: var(--wp--preset--color--ti-bg); + color: var(--wp--preset--color--ti-fg); } .wp-block-navigation__responsive-container.is-menu-open { diff --git a/assets/css/src/blocks/_post-terms.scss b/assets/css/src/blocks/_post-terms.scss index 6b401f1..0e5de62 100644 --- a/assets/css/src/blocks/_post-terms.scss +++ b/assets/css/src/blocks/_post-terms.scss @@ -7,7 +7,7 @@ a { padding: 8px 24px; margin: 5px; - background-color: var(--wp--preset--color--raft-bg-alt); + background-color: var(--wp--preset--color--ti-bg-alt); border-radius: 25px; } diff --git a/assets/css/src/blocks/_search.scss b/assets/css/src/blocks/_search.scss index 899afd1..1866d3d 100644 --- a/assets/css/src/blocks/_search.scss +++ b/assets/css/src/blocks/_search.scss @@ -6,9 +6,9 @@ } .wp-block-search__button { - background: var(--wp--preset--color--raft-accent); - color: var(--wp--preset--color--raft-fg-alt); - border-color: var(--wp--preset--color--raft-accent); + background: var(--wp--preset--color--ti-accent); + color: var(--wp--preset--color--ti-fg-alt); + border-color: var(--wp--preset--color--ti-accent); border-radius: 5px; } } diff --git a/assets/css/src/blocks/_table.scss b/assets/css/src/blocks/_table.scss index 6bbd123..1dc0561 100644 --- a/assets/css/src/blocks/_table.scss +++ b/assets/css/src/blocks/_table.scss @@ -1,7 +1,7 @@ .wp-block-table { &.is-style-stripes tbody tr:nth-child(odd) { - background-color: var(--wp--preset--color--raft-bg-alt); + background-color: var(--wp--preset--color--ti-bg-alt); } thead { @@ -14,7 +14,7 @@ figcaption { font-size: var(--wp--preset--font-size--small); - color: var(--wp--preset--color--raft-fg); + color: var(--wp--preset--color--ti-fg); opacity: 0.6; } } diff --git a/assets/css/src/common/_color-migration.scss b/assets/css/src/common/_color-migration.scss new file mode 100644 index 0000000..ec51710 --- /dev/null +++ b/assets/css/src/common/_color-migration.scss @@ -0,0 +1,19 @@ +//.has-raft-fg-alt-color +//.has-raft-accent-background-color +$colors: ( + raft-bg : ti-bg, + raft-fg: ti-fg, + raft-bg-alt: ti-bg-alt, + raft-fg-alt: ti-fg-alt, + raft-accent: ti-accent, +); + +// remap color css variables to has-*-color and has-*-background-color +@each $raft, $generic in $colors { + .has-#{$raft}-color { + color: var(--wp--preset--color--#{$generic}); + } + .has-#{$raft}-background-color { + background-color: var(--wp--preset--color--#{$generic}); + } +} diff --git a/assets/css/src/editor.scss b/assets/css/src/editor.scss index 065bd5f..bad6ce2 100644 --- a/assets/css/src/editor.scss +++ b/assets/css/src/editor.scss @@ -4,6 +4,7 @@ @import "common/generic"; @import "common/typography"; + @import "common/color-migration"; @import "blocks/main"; @import "elements/main"; @import "editor/blocks/main"; diff --git a/assets/css/src/elements/_extends.scss b/assets/css/src/elements/_extends.scss index c9f0dda..86e8090 100644 --- a/assets/css/src/elements/_extends.scss +++ b/assets/css/src/elements/_extends.scss @@ -1,8 +1,8 @@ %input-base { border-radius: 5px; - color: var(--wp--preset--color--raft-fg); - background: var(--wp--preset--color--raft-bg); - border: 2px solid var(--wp--preset--color--raft-fg); + color: var(--wp--preset--color--ti-fg); + background: var(--wp--preset--color--ti-bg); + border: 2px solid var(--wp--preset--color--ti-fg); } @mixin button-base { @@ -17,7 +17,7 @@ %button { @include button-base; - color: var(--wp--preset--color--raft-fg-alt); - background: var(--wp--preset--color--raft-accent); - border-color: var(--wp--preset--color--raft-accent); + color: var(--wp--preset--color--ti-fg-alt); + background: var(--wp--preset--color--ti-accent); + border-color: var(--wp--preset--color--ti-accent); } diff --git a/assets/css/src/style.scss b/assets/css/src/style.scss index 1e8293c..30b6568 100644 --- a/assets/css/src/style.scss +++ b/assets/css/src/style.scss @@ -1,5 +1,6 @@ @import "common/generic"; @import "common/typography"; +@import "common/color-migration"; @import "common/vars"; @import "elements/main"; @import "blocks/main"; diff --git a/inc/Core.php b/inc/Core.php index 9aee36a..82a3be8 100644 --- a/inc/Core.php +++ b/inc/Core.php @@ -44,6 +44,7 @@ public function __construct() { new Admin(); new Block_Patterns(); new Block_Styles(); + new Migration(); } /** diff --git a/inc/Migration.php b/inc/Migration.php new file mode 100644 index 0000000..c94bcaa --- /dev/null +++ b/inc/Migration.php @@ -0,0 +1,155 @@ + 'raft_colors_migration', + ); + + /** + * Migration Constructor + */ + public function __construct() { + if ( $this->was_migrated( 'colors' ) ) { + return; + } + + $this->setup_properties(); + + add_action( 'init', array( $this, 'migrate_old_colors' ) ); + } + + + /** + * Setup the properties. + * + * @return void + */ + private function setup_properties() { + $args = array( + 'posts_per_page' => 1, + 'orderby' => 'date', + 'order' => 'desc', + 'post_type' => 'wp_global_styles', + 'post_status' => 'publish', + 'ignore_sticky_posts' => true, + 'no_found_rows' => true, + 'tax_query' => array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query + array( + 'taxonomy' => 'wp_theme', + 'field' => 'name', + 'terms' => 'raft', + ), + ), + ); + + $global_style_query = new \WP_Query(); + $recent_posts = $global_style_query->query( $args ); + + if ( empty( $recent_posts ) ) { + return; + } + + $this->global_styles_data = json_decode( $recent_posts[0]->post_content, true ); + $this->global_styles_post_id = $recent_posts[0]->ID; + } + + /** + * Migrate the old color slugs. + * + * @return void + */ + public function migrate_old_colors() { + if ( $this->was_migrated( 'colors' ) ) { + return; + } + + if ( 0 === $this->global_styles_post_id || empty( $this->global_styles_data ) ) { + return; + } + + if ( + ! isset( $this->global_styles_data['settings'] ) || + ! isset( $this->global_styles_data['settings']['color'] ) || + ! isset( $this->global_styles_data['settings']['color']['palette'] ) || + ! isset( $this->global_styles_data['settings']['color']['palette']['theme'] ) + ) { + return; + } + + $colors = $this->global_styles_data['settings']['color']['palette']['theme']; + + array_walk( + $colors, + function ( &$color ) { + $color['slug'] = str_replace( 'raft-', 'ti-', $color['slug'] ); + + return $color; + } + ); + + $this->global_styles_data['settings']['color']['palette']['theme'] = $colors; + + $update = wp_update_post( + array( + 'ID' => $this->global_styles_post_id, + 'post_content' => wp_json_encode( $this->global_styles_data ), + ) + ); + + if ( is_wp_error( $update ) ) { + return; + } + + $this->set_migrated( 'colors' ); + } + + /** + * Check if a migration was already done. + * + * @param string $key The migration key. + * + * @return bool + */ + private function was_migrated( $key ) { + return get_option( self::MIGRATION_FLAGS[ $key ], false ) === true; + } + + /** + * Set a migration as done. + * + * @param string $key The migration key. + * + * @return void + */ + private function set_migrated( $key ) { + update_option( self::MIGRATION_FLAGS[ $key ], true ); + } +} diff --git a/inc/patterns/alternating-feature-columns.php b/inc/patterns/alternating-feature-columns.php index fc0ce10..8391fd8 100644 --- a/inc/patterns/alternating-feature-columns.php +++ b/inc/patterns/alternating-feature-columns.php @@ -47,16 +47,16 @@ - -
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore.
- -