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 35ba235 + 6d54094 commit 727c31a
Show file tree
Hide file tree
Showing 3 changed files with 477 additions and 537 deletions.
140 changes: 0 additions & 140 deletions lib/functions/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,146 +12,6 @@
// Prevent direct file access.
defined( 'ABSPATH' ) || die;

/**
* Returns asset version with filetime.
*
* @since 0.1.0
*
* @param string $file File path.
*
* @return string
*/
function mai_get_asset_version( $file ) {
$file = str_replace( content_url(), WP_CONTENT_DIR, $file );
$version = mai_get_version();

if ( file_exists( $file ) ) {
$version .= '.' . date( 'njYHi', filemtime( $file ) );
}

return $version;
}

/**
* Returns minified version of asset if in dev mode.
*
* @since 0.1.0
* @since 2.4.0 Removed min dir if CSS file. Always return minified CSS.
*
* @param string $file File base name (relative to type directory).
*
* @return string
*/
function mai_get_asset_url( $file ) {
$type = false !== strpos( $file, '.js' ) ? 'js' : 'css';
$name = str_replace( [ '.js', '.css' ], '', $file );
$uri = mai_get_url();
$default = "${uri}assets/${type}/${name}.${type}";
$dir = 'js' === $type ? '/min/' : '/';
$min = "${uri}assets/${type}${dir}${name}.min.${type}";

return mai_is_in_dev_mode() && 'js' === $type ? $default : $min;
}

/**
* Returns the active child theme's sub config.
*
* @since 0.1.0
* @since 2.11.0 Add static caching.
*
* @param string $sub_config Name of config to get.
*
* @return array
*/
function mai_get_config( $sub_config ) {
static $configs = null;

if ( is_array( $configs ) && isset( $configs[ $sub_config ] ) ) {
return $configs[ $sub_config ];
}

if ( ! is_array( $configs ) ) {
$configs = [];
}

$config = mai_get_full_config();
$value = isset( $config[ $sub_config ] ) ? $config[ $sub_config ] : [];
$configs[ $sub_config ] = apply_filters( "mai_{$sub_config}_config", $value );

return $configs[ $sub_config ];
}

/**
* Returns the active child theme's full config.
*
* @access private
*
* @since 2.11.0
*
* @return array
*/
function mai_get_full_config() {
static $config = null;

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

$config = require mai_get_dir() . 'config/_default.php';
$theme = mai_get_active_theme();
$theme = ( 'default' === $theme ) ? '_default' : $theme;
$path = mai_get_dir() . 'config/' . $theme . '.php';

if ( is_readable( $path ) ) {
$new = require $path;
$config = array_replace_recursive( $config, $new );
if ( isset( $new['settings']['content-archives'] ) ) {
foreach ( $new['settings']['content-archives'] as $key => $settings ) {
if ( ! ( isset( $new['settings']['content-archives'][ $key ]['show'] ) && isset( $config['settings']['content-archives'][ $key ]['show'] ) ) ) {
continue;
}
$config['settings']['content-archives'][ $key ]['show'] = $new['settings']['content-archives'][ $key ]['show'];
}
}
if ( isset( $new['settings']['single-content'] ) ) {
foreach ( $new['settings']['single-content'] as $key => $settings ) {
if ( ! ( isset( $new['settings']['single-content'][ $key ]['show'] ) && isset( $config['settings']['single-content'][ $key ]['show'] ) ) ) {
continue;
}
$config['settings']['single-content'][ $key ]['show'] = $new['settings']['single-content'][ $key ]['show'];
}
}
}

// Allow users to override from within actual child theme.
$child = get_stylesheet_directory() . '/config.php';

if ( is_readable( $child ) ) {
$new = require $child;
$config = array_replace_recursive( $config, $new );
if ( isset( $new['settings']['content-archives'] ) ) {
foreach ( $new['settings']['content-archives'] as $key => $settings ) {
if ( ! ( isset( $new['settings']['content-archives'][ $key ]['show'] ) && isset( $config['settings']['content-archives'][ $key ]['show'] ) ) ) {
continue;
}
$config['settings']['content-archives'][ $key ]['show'] = $new['settings']['content-archives'][ $key ]['show'];
}
}
if ( isset( $new['settings']['single-content'] ) ) {
foreach ( $new['settings']['single-content'] as $key => $settings ) {
if ( ! ( isset( $new['settings']['single-content'][ $key ]['show'] ) && isset( $config['settings']['single-content'][ $key ]['show'] ) ) ) {
continue;
}
$config['settings']['single-content'][ $key ]['show'] = $new['settings']['single-content'][ $key ]['show'];
}
}
}

$config = apply_filters( 'mai_config', $config );

return $config;
}

/**
* Adds slug to plugin data array.
* Slug is used as the key so mai_get_config can merge default
Expand Down
Loading

0 comments on commit 727c31a

Please sign in to comment.