Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Fix warnings and enqueue default styles early
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafael Nowrotek authored and Rafael Nowrotek committed Aug 9, 2019
1 parent 12a58d0 commit 8a86230
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bin/install-wp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ wp option update permalink_structure "/%year%/%monthnum%/%postname%/" --skip-the
wp plugin activate wordpress-importer

# Activate theme.
wp theme activate kicks-app
wp theme activate kicks-app-pro
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "benignware/wp-kicks-app-pro",
"version": "0.1.0-beta.11",
"version": "0.1.0-beta.12",
"type": "wordpress-theme",
"license": "MIT",
"description": "Wordpress Kickstarter Theme",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 44 additions & 13 deletions inc/customize-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ function adjustBrightness($hexCode, $adjustPercent) {
}
}

if (!is_array($rgb)) {
return '';
}

foreach ($rgb as & $color) {
$adjustableLimit = $normalized_percent < 0 ? $color : 255 - $color;
$adjustAmount = ceil($adjustableLimit * $normalized_percent);
Expand Down Expand Up @@ -140,7 +144,7 @@ function get_theme_fonts_x() {
}

$theme_fonts = array();
$theme_resources = get_theme_resources();
$theme_resources = get_theme_resources() ?: array();

foreach ($theme_resources as $theme_resource) {
$theme_fonts = array_unique(array_merge($theme_resource['fonts'], $theme_fonts));
Expand Down Expand Up @@ -275,11 +279,14 @@ function enqueue_theme_custom_css() {

wp_register_style( 'kicks-app-custom-style', false );
wp_enqueue_style( 'kicks-app-custom-style' );
wp_add_inline_style('kicks-app-custom-style', $css );

if ($css) {
wp_add_inline_style('kicks-app-custom-style', $css );
}
}

add_action( 'wp_enqueue_scripts', 'enqueue_theme_custom_css', 100);
add_action( 'enqueue_block_editor_assets', 'enqueue_theme_custom_css', 100);
add_action( 'wp_enqueue_scripts', 'enqueue_theme_custom_css', 9);
add_action( 'enqueue_block_editor_assets', 'enqueue_theme_custom_css', 9);


// Register sections
Expand Down Expand Up @@ -460,9 +467,6 @@ function get_theme_fonts() {
return array_merge($result, $current['fonts']);
}, array());

print_r($fonts);
exit;

return $fonts;
}

Expand Down Expand Up @@ -501,6 +505,10 @@ function get_theme_resources() {

$url = $urlinfo['scheme'] . '://' . $_SERVER['SERVER_ADDR'] . $urlinfo['path'] . ($urlinfo['query'] ? '?' . $urlinfo['query'] : '');

/*
echo $url;
exit;
*/

if (function_exists('curl_init')) {
$ch = curl_init();
Expand Down Expand Up @@ -570,14 +578,16 @@ function load_theme_manifest($file) {
}

function get_theme_defaults() {
$theme_resources = get_theme_resources();
$theme_resources = get_theme_resources() ?: array();

$defaults = array();
foreach ($theme_resources as $theme_resource) {

/*
echo 'GET DEFAULT VaLUES: ' . $theme_resource['url'];
echo '<br/>';
*/

$defaults = array_merge($defaults, $theme_resource['vars']);
}

Expand All @@ -587,7 +597,6 @@ function get_theme_defaults() {
function x_get_theme_vars() {
global $theme_vars;


$defaults = get_theme_defaults();
/*
echo '<pre>';
Expand All @@ -600,17 +609,35 @@ function x_get_theme_vars() {
$result = array();


// Process regular vars
// echo 'process regular vars<br/>';

foreach ($theme_vars as $key => $data) {
// $value = isset($data['value']) ? $data['value'] : $data['default'];
$value = isset($defaults[$key]) ? $defaults[$key] : $data['value'];
$implicit = isset($data['implicit']) ? $data['implicit'] : false;

if (!$implicit) {
$value = get_theme_mod($key, $value);
$result[$key] = $value;
if ($value && !$implicit) {
try {
// We cannot process url for some reason
if (preg_match('~url\s*\(~', $value)) {
continue;
}

// Go ahead
$value = get_theme_mod($key) ?: $value;
$result[$key] = $value;
} catch (Exception $e) {
echo 'Exception: ', $e->getMessage(), "\n";
exit;
}
}
}


// Process implicit vars
// echo 'process implicit vars<br/>';

$pattern = '~^\s*var\s*\(\s*--([a-zA-Z_-]*)\s*\)\s*$~';

foreach ($theme_vars as $key => $data) {
Expand Down Expand Up @@ -689,7 +716,6 @@ function x_get_theme_vars() {
function x_get_theme_custom_css() {
$theme_vars = x_get_theme_vars();


/*
echo '<pre>';
var_dump($theme_vars);
Expand All @@ -698,11 +724,16 @@ function x_get_theme_custom_css() {
exit;
*/


$css = <<<EOT
:root {
EOT;
foreach ($theme_vars as $name => $value) {
if (preg_match('~url\s*\(~', $value)) {
continue;
}

if ($value) {
$css.= <<<EOT
--$name: $value;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "wp-kicks-app-pro",
"version": "0.1.0-beta.11",
"version": "0.1.0-beta.12",
"description": "Wordpress theme",
"private": true,
"main": "dist/main.js",
Expand Down Expand Up @@ -64,7 +64,7 @@
"build:bootstrap-js": "cpx './node_modules/bootstrap/dist/js/**/*.*' dist/bootstrap/js",
"build:bootstrap-css": "node ./build.js",
"build:popper": "cpx './node_modules/popper.js/dist/**/*.*' dist/popper.js",
"build:fontawesome": "cpx './node_modules/@fortawesome/fontawesome-free/**/*.*' dist/fontawesome",
"build:fontawesome": "cpx './node_modules/@fortawesome/fontawesome-free/{css,webfonts}/*.*' dist/fontawesome",
"build:swiper-themes": "node-sass scss/swiper-themes.scss dist/swiper-themes.css --output-style expanded",
"build": "run-p \"build:*\""
},
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Theme Name: Kicks App Pro
Author: Rafael Nowrotek
Author URI: http://benignware.com
Description: Kickstarter Template
Version: 0.1.0-beta.11
Version: 0.1.0-beta.12
*/

* {
Expand Down

0 comments on commit 8a86230

Please sign in to comment.