Skip to content

Commit

Permalink
Added helper functions for check_array_key and check_array
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelwatt committed May 1, 2023
1 parent cc0a4d5 commit 7768259
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build
38 changes: 37 additions & 1 deletion njk/assets/lib/helper-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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
//-----------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions njk/templates/_globals-defaults.html
Original file line number Diff line number Diff line change
Expand Up @@ -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/" %}
Expand Down Expand Up @@ -90,7 +90,7 @@
{# Local Development #}
{# ---------------------------------------------------------------- #}

{% set localdev_url = "method.test:8080" %}
{% set localdev_url = "method.test" %}


{# ---------------------------------------------------------------- #}
Expand Down

0 comments on commit 7768259

Please sign in to comment.