From 7768259a9120dc39dbccbb2c6b0591e0f0abc5b4 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Mon, 1 May 2023 13:18:00 -0500 Subject: [PATCH] Added helper functions for check_array_key and check_array --- build | 2 +- njk/assets/lib/helper-functions.php | 38 +++++++++++++++++++++++++++- njk/templates/_globals-defaults.html | 4 +-- 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/build b/build index 487d410..b01c37f 160000 --- a/build +++ b/build @@ -1 +1 @@ -Subproject commit 487d41008f070a4ebd5278d71d5d9426044178d6 +Subproject commit b01c37f970bf682180465ab23203552a031cdbf9 diff --git a/njk/assets/lib/helper-functions.php b/njk/assets/lib/helper-functions.php index 1ab6c11..fc47601 100644 --- a/njk/assets/lib/helper-functions.php +++ b/njk/assets/lib/helper-functions.php @@ -39,7 +39,7 @@ function {{globals.code_prefix}}filter_content( $content ) { //----------------------------------------------------- -// Check an array key to see if it exists +// DEPRECATED: Check an array key to see if it exists //----------------------------------------------------- function {{globals.code_prefix}}check_key( $key ) { @@ -53,6 +53,42 @@ function {{globals.code_prefix}}check_key( $key ) { } +//------------------------------------------------------------ +// Updated function to check an array key to see if it exists +//------------------------------------------------------------ + +function {{globals.code_prefix}}check_array_key( $item, $key ) { + $output = false; + if ( is_array( $item ) ) { + if ( array_key_exists( $key, $item ) ) { + if ( ! empty( $item["{$key}"] ) ) { + $output = true; + } + } + } + return $output; +} + + +//----------------------------------------------------- +// Check to see if an array has content. +//----------------------------------------------------- + +function {{globals.code_prefix}}check_array( $item, $key ) { + $output = false; + if ( $item ) { + if ( is_array( $item ) ) { + if ( 1 <=count( $item ) ) { + if ( $this->check_array_key( $item[0], $key ) ) { + $output = true; + } + } + } + } + return $output; +} + + //----------------------------------------------------- // Add the array_key_first() function for older PHP //----------------------------------------------------- diff --git a/njk/templates/_globals-defaults.html b/njk/templates/_globals-defaults.html index 0bb60fb..b976c10 100644 --- a/njk/templates/_globals-defaults.html +++ b/njk/templates/_globals-defaults.html @@ -10,7 +10,7 @@ {% set theme_name = "Method" %} {% set theme_uri = "https://github.com/pixelwatt/method" %} {% set theme_description = "A barebones foundation for custom theme development." %} -{% set theme_version = "1.3.9" %} +{% set theme_version = "1.3.10" %} {% set theme_license = "GNU General Public License v2 or later" %} {% set theme_author = "Rob Clark" %} {% set theme_author_uri = "https://robclark.io/" %} @@ -90,7 +90,7 @@ {# Local Development #} {# ---------------------------------------------------------------- #} -{% set localdev_url = "method.test:8080" %} +{% set localdev_url = "method.test" %} {# ---------------------------------------------------------------- #}