Skip to content

Commit

Permalink
Merge branch 'release/2.31.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
JiveDig committed Jan 8, 2024
2 parents eefe87f + 4bfbdc0 commit 35ba235
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 213 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 2.31.2 (1/8/24)
* Changed: Now Load core getter functions immediately instead of `after_setup_theme`.
* Fixed: Cover block overlay was not rendering correctly when using Link as the overlay color.

## 2.31.1 (12/28/23)
* Added: Better PHP 8.2 compatibility.
* Changed: Element stacking via z-index is now less aggressive by default. This fixes some edge-case scenarios where floating elements are behind other elements on the page.
Expand Down
35 changes: 25 additions & 10 deletions lib/blocks/general.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,34 +89,49 @@ function mai_render_block_handle_link_color( $block_content, $block ) {
}

// Get color settings.
$text = mai_isset( $block['attrs'], 'textColor', false );
$bg = mai_isset( $block['attrs'], 'backgroundColor', false );
$text = mai_isset( $block['attrs'], 'textColor', false );
$bg = mai_isset( $block['attrs'], 'backgroundColor', false );
$overlay = mai_isset( $block['attrs'], 'overlayColor', false );

// Bail if no link colors.
if ( ! in_array( 'link', [ $text, $bg ], true ) ) {
if ( ! in_array( 'link', [ $text, $bg, $overlay ], true ) ) {
return $block_content;
}

// Find first instance of has-link-color and replace with has-links-color.
$tags = new WP_HTML_Tag_Processor( $block_content );

// Handle text color.
if ( 'link' === $text ) {
while ( $tags->next_tag( [ 'class_name' => 'has-link-color' ] ) ) {
$class = $tags->get_attribute( 'class' );
$class .= ' has-links-color';
$tags->set_attribute( 'class', $class );
// Get array of classes, add new, and flip.
$class = explode( ' ', $tags->get_attribute( 'class' ) );
$class[] = 'has-links-color';
$class = array_flip( $class );

// Remove link color class.
unset( $class['has-link-color'] );

$tags->set_attribute( 'class', implode( ' ', array_flip( $class ) ) );
break;
}
}

if ( 'link' === $bg ) {
// Handle background and overlay color.
if ( 'link' === $bg || 'link' === $overlay ) {
// Find first instance of has-link-background-color and replace with has-links-background-color.
$tags = new WP_HTML_Tag_Processor( $block_content );

while ( $tags->next_tag( [ 'class_name' => 'has-link-background-color' ] ) ) {
$class = $tags->get_attribute( 'class' );
$class .= ' has-links-background-color';
$tags->set_attribute( 'class', $class );
// Get array of classes, add new, and flip.
$class = explode( ' ', $tags->get_attribute( 'class' ) );
$class[] = 'has-links-background-color';
$class = array_flip( $class );

// Remove link background color class.
unset( $class['has-link-background-color'] );

$tags->set_attribute( 'class', implode( ' ', array_flip( $class ) ) );
break;
}
}
Expand Down
200 changes: 0 additions & 200 deletions lib/functions/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,151 +12,6 @@
// Prevent direct file access.
defined( 'ABSPATH' ) || die;

/**
* Returns the plugin directory.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_dir() {
static $dir = null;

if ( is_null( $dir ) ) {
$dir = trailingslashit( dirname( dirname( __DIR__ ) ) );
}

return $dir;
}

/**
* Returns the plugin URL.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_url() {
static $url = null;

if ( ! is_null( $url ) ) {
return $url;
}

$url = trailingslashit( plugins_url( basename( mai_get_dir() ) ) );

return $url;
}

/**
* Gets the plugin basename.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_base() {
static $base = null;

if ( ! is_null( $base ) ) {
return $base;
}

$dir = basename( dirname( dirname( __DIR__ ) ) );
$file = mai_get_handle() . '.php';
$base = $dir . DIRECTORY_SEPARATOR . $file;

return $base;
}

/**
* Returns an array of plugin data from the main plugin file.
*
* @since 0.1.0
*
* @param string $key Optionally return one key.
*
* @return array|string|null
*/
function mai_get_plugin_data( $key = '' ) {
static $data = null;

if ( is_null( $data ) ) {
$data = get_file_data(
mai_get_dir() . 'mai-engine.php',
[
'name' => 'Plugin Name',
'version' => 'Version',
'plugin-uri' => 'Plugin URI',
'text-domain' => 'Text Domain',
'description' => 'Description',
'author' => 'Author',
'author-uri' => 'Author URI',
'domain-path' => 'Domain Path',
'network' => 'Network',
],
'plugin'
);
}

if ( array_key_exists( $key, $data ) ) {
return $data[ $key ];
}

return $data;
}

/**
* Returns the plugin name.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_name() {
static $name = null;

if ( is_null( $name ) ) {
$name = mai_get_plugin_data( 'name' );
}

return $name;
}

/**
* Returns the plugin handle/text domain.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_handle() {
static $handle = null;

if ( is_null( $handle ) ) {
$handle = mai_get_plugin_data( 'text-domain' );
}

return $handle;
}

/**
* Returns the plugin version.
*
* @since 0.1.0
*
* @return string
*/
function mai_get_version() {
static $version = null;

if ( is_null( $version ) ) {
$version = mai_get_plugin_data( 'version' );
}

return $version;
}

/**
* Returns asset version with filetime.
*
Expand Down Expand Up @@ -1757,61 +1612,6 @@ function mai_get_entry_meta_setting_description() {
);
}

/**
* Gets the plugin updater icons.
* This may be used in additiona Mai Plugins.
*
* @since 2.11.0
*
* @return array
*/
function mai_get_updater_icons() {
$icons = [];
$standard = mai_get_logo_icon_1x();
$retina = mai_get_logo_icon_2x();
if ( $standard && $retina ) {
$icons = [
'1x' => $standard,
'2x' => $retina,
];
}
return $icons;
}

/**
* Gets the Mai Theme logo icon @1x for plugin updater.
*
* @since 2.11.0
*
* @return string
*/
function mai_get_logo_icon_1x() {
static $icon = null;
if ( ! is_null( $icon ) ) {
return $icon;
}
$file = 'assets/img/icon-128x128.png';
$icon = file_exists( mai_get_dir() . $file ) ? mai_get_url() . $file : '';
return $icon;
}

/**
* Gets the Mai Theme logo icon @1x for plugin updater.
*
* @since 2.11.0
*
* @return string
*/
function mai_get_logo_icon_2x() {
static $icon = null;
if ( ! is_null( $icon ) ) {
return $icon;
}
$file = 'assets/img/icon-256x256.png';
$icon = file_exists( mai_get_dir() . $file ) ? mai_get_url() . $file : '';
return $icon;
}

/**
* Gets a cart total that is ajax updated when new products are added to cart.
*
Expand Down
Loading

0 comments on commit 35ba235

Please sign in to comment.