Skip to content

Commit

Permalink
Added several bugfixes and additions
Browse files Browse the repository at this point in the history
Changes:
* ( lib/class-method-layout.php ) Added new methods for loading and retrieving term meta: load_term_meta(), unload_term_meta(), get_loaded_term_meta()
* ( lib/class-method-layout.php ) Added new property, loaded_term_meta, for storing term meta
* ( lib/class-method-layout.php ) Added a new method, check_array_key(), for checking whether an array key exists. This essentially accomplishes the same end as check_key(), but is cleaner (no undefined errors) and has slightly different syntax. check_key() is still available, but should now be considered deprecated
* ( lib/class-method-layout.php ) Refactored methods calling the check_key() method to use check_array_key() instead
* ( lib/class-method-layout.php ) Added a new method, check_array(), for seeing if a specific key exists and is set in the first key of an indexed array
* ( lib/class-method-layout.php ) Fixed an issue in the inject_bs_modal() method that could potentially trigger an undefined variable warning
* ( lib/class-method-layout.php ) The build_page() and init_page() methods now set the 'is_front' key of the $attr property to false before evaluating whether it should be true, so that it always has a value
  • Loading branch information
pixelwatt committed Feb 17, 2023
1 parent 18bfb28 commit 487d410
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 26 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## 1.3.9

Changes:
* ( lib/class-method-layout.php ) Added new methods for loading and retrieving term meta: load_term_meta(), unload_term_meta(), get_loaded_term_meta()
* ( lib/class-method-layout.php ) Added new property, loaded_term_meta, for storing term meta
* ( lib/class-method-layout.php ) Added a new method, check_array_key(), for checking whether an array key exists. This essentially accomplishes the same end as check_key(), but is cleaner (no undefined errors) and has slightly different syntax. check_key() is still available, but should now be considered deprecated
* ( lib/class-method-layout.php ) Refactored methods calling the check_key() method to use check_array_key() instead
* ( lib/class-method-layout.php ) Added a new method, check_array(), for seeing if a specific key exists and is set in the first key of an indexed array
* ( lib/class-method-layout.php ) Fixed an issue in the inject_bs_modal() method that could potentially trigger an undefined variable warning
* ( lib/class-method-layout.php ) The build_page() and init_page() methods now set the 'is_front' key of the $attr property to false before evaluating whether it should be true, so that it always has a value

---

## 1.3.8

Changes:
Expand Down
2 changes: 1 addition & 1 deletion lib/admin-customization.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function method_admin_scripts() {
$wp_scripts = wp_scripts();
wp_enqueue_script( 'jquery-ui-dialog' );
wp_enqueue_style( 'jquery-ui', 'https://ajax.googleapis.com/ajax/libs/jqueryui/' . $wp_scripts->registered['jquery-ui-core']->ver . '/themes/smoothness/jquery-ui.css', '', '', false );
wp_enqueue_style( 'method', get_template_directory_uri() . '/assets/css/admin-styles.css', '', '1.3.8' );
wp_enqueue_style( 'method', get_template_directory_uri() . '/assets/css/admin-styles.css', '', '1.3.9' );
}

add_action( 'admin_enqueue_scripts', 'method_admin_scripts' );
Expand Down
111 changes: 90 additions & 21 deletions lib/class-method-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,40 @@

//======================================================================
//
// METHOD LAYOUT CLASS v1.3.8
// METHOD LAYOUT CLASS v1.3.9
//
// You probably don't want or need to edit this file.
//
//======================================================================

abstract class Method_Layout {
protected $meta = array();
protected $loaded_meta = array();
protected $opts = array();
protected $meta = array();
protected $loaded_meta = array();
protected $loaded_term_meta = array();
protected $opts = array();
protected $id;
protected $html;
protected $modals;
protected $scripts;
protected $attr = array();
protected $attr = array();

//======================================================================
// CORE METHODS
//======================================================================

public function build_page( $pid = '', $archive = false ) {
$this->set_opts();
$this->attr['is_front'] = false;
if ( true == $archive ) {
global $wp_query;
$this->attr['is_archive'] = true;
$this->attr['post_type'] = ( $this->check_key( $wp_query->query_vars['post_type'] ) ? $wp_query->query_vars['post_type'] : 'post' );
$this->attr['post_type'] = ( $this->check_array_key( $wp_query->query_vars, 'post_type' ) ? $wp_query->query_vars['post_type'] : 'post' );

if ( 'post' == $this->attr['post_type'] ) {
$this->attr['category'] = ( $this->check_key( $wp_query->queried_object->name ) ? $wp_query->queried_object->name : '' );
}

$this->attr['taxonomy'] = ( $this->check_key( $wp_query->query_vars['taxonomy'] ) ? $wp_query->query_vars['taxonomy'] : '' );
$this->attr['taxonomy'] = ( $this->check_array_key( $wp_query->query_vars, 'taxonomy' ) ? $wp_query->query_vars['taxonomy'] : '' );
$this->determine_attributes();
$this->build_layout();

Expand Down Expand Up @@ -71,6 +73,7 @@ protected function build_layout() {

public function init_page( $pid, $standalone = false ) {
$this->set_opts();
$this->attr['is_front'] = false;
$this->attr['standalone'] = $standalone;
$this->attr['is_archive'] = false;
$this->id = $pid;
Expand Down Expand Up @@ -219,8 +222,8 @@ protected function reset_markup() {

public function get_meta( $key, $fallback = '' ) {
$output = false;
if ( isset( $this->meta[ "{$key}" ][0] ) ) {
if ( ! empty( $this->meta[ "{$key}" ][0] ) ) {
if ( $this->check_array_key( $this->meta, $key ) ) {
if ( $this->check_array_key( $this->meta[ "{$key}" ], 0 ) ) {
$output = $this->meta[ "{$key}" ][0];
}
}
Expand All @@ -233,8 +236,8 @@ public function get_meta( $key, $fallback = '' ) {

public function get_serialized_meta( $key ) {
$output = false;
if ( isset( $this->meta[ "{$key}" ][0] ) ) {
if ( ! empty( $this->meta[ "{$key}" ][0] ) ) {
if ( $this->check_array_key( $this->meta, $key ) ) {
if ( $this->check_array_key( $this->meta[ "{$key}" ], 0 ) ) {
$output = maybe_unserialize( $this->meta[ "{$key}" ][0] );
}
}
Expand Down Expand Up @@ -290,8 +293,8 @@ public function unload_meta() {

public function get_loaded_meta( $key, $fallback = '' ) {
$output = false;
if ( isset( $this->loaded_meta[ "{$key}" ][0] ) ) {
if ( ! empty( $this->loaded_meta[ "{$key}" ][0] ) ) {
if ( $this->check_array_key( $this->loaded_meta, $key ) ) {
if ( $this->check_array_key( $this->loaded_meta[ "{$key}" ], 0 ) ) {
$output = $this->loaded_meta[ "{$key}" ][0];
}
}
Expand All @@ -304,8 +307,8 @@ public function get_loaded_meta( $key, $fallback = '' ) {

public function get_serialized_loaded_meta( $key ) {
$output = false;
if ( isset( $this->loaded_meta[ "{$key}" ][0] ) ) {
if ( ! empty( $this->loaded_meta[ "{$key}" ][0] ) ) {
if ( $this->check_array_key( $this->loaded_meta, $key ) ) {
if ( $this->check_array_key( $this->loaded_meta[ "{$key}" ], 0 ) ) {
$output = maybe_unserialize( $this->loaded_meta[ "{$key}" ][0] );
}
}
Expand Down Expand Up @@ -336,6 +339,39 @@ public function get_loaded_content( $key, $before, $after, $fallback = '' ) {
return $output;
}

//-----------------------------------------------------
// Load all meta for a specified term and store in the
// loaded_term_meta property.
//-----------------------------------------------------

public function load_term_meta( $id ) {
$this->loaded_term_meta = get_term_meta( $id );
return;
}

//-----------------------------------------------------
// Reset loaded_term_meta to an empty array.
//-----------------------------------------------------

public function unload_term_meta() {
$this->loaded_term_meta = array();
return;
}

//-----------------------------------------------------
// Get data for a meta key (loaded term meta)
//-----------------------------------------------------

public function get_loaded_term_meta( $key, $fallback = '' ) {
$output = false;
if ( $this->check_array_key( $this->loaded_term_meta, $key ) ) {
if ( $this->check_array_key( $this->loaded_term_meta[ "{$key}" ], 0 ) ) {
$output = $this->loaded_term_meta[ "{$key}" ][0];
}
}
return ( false === $output ? ( ! empty( $fallback ) ? $fallback : false ) : $output );
}

//======================================================================
// THEME OPTION METHODS
//======================================================================
Expand All @@ -346,10 +382,8 @@ public function get_loaded_content( $key, $before, $after, $fallback = '' ) {

public function get_option( $key, $fallback = '' ) {
$output = false;
if ( isset( $this->opts[ "{$key}" ] ) ) {
if ( ! empty( $this->opts[ "{$key}" ] ) ) {
$output = $this->opts[ "{$key}" ];
}
if ( $this->check_array_key( $this->opts, $key ) ) {
$output = $this->opts[ "{$key}" ];
}
return ( false === $output ? ( ! empty( $fallback ) ? $fallback : false ) : $output );
}
Expand Down Expand Up @@ -469,6 +503,41 @@ public function check_key( $key ) {
return $output;
}

//-----------------------------------------------------
// Check to see if an array key exists, more cleanly.
//-----------------------------------------------------

public function 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.
//-----------------------------------------------------

public function 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;
}


//-----------------------------------------------------
// Run a string through WordPress' content filter
//-----------------------------------------------------
Expand Down Expand Up @@ -533,7 +602,7 @@ public function inject_bs_modal( $args ) {
'return' => false,
);
$parsed = wp_parse_args( $args, $defaults );
$output .= '
$output = '
<div class="modal fade' . ( ! empty( $parsed['class'] ) ? ' ' . $parsed['class'] : '' ) . '" id="' . $parsed['id'] . '" tabindex="-1" role="dialog" aria-labelledby="' . $parsed['id'] . 'Label" aria-hidden="true">
<div class="modal-dialog' . ( $parsed['scrollable'] ? ' modal-dialog-scrollable' : '' ) . ( ! empty( $parsed['size'] ) ? ' modal-' . $parsed['size'] : '' ) . '" role="document">
<div class="modal-content">
Expand Down Expand Up @@ -685,7 +754,7 @@ public function build_social_icons( $class = 's-ics', $icon_size = 16 ) {
$social_links = $this->get_option( 'social_accounts' );
if ( ! empty( $social_links ) ) {
if ( is_array( $social_links ) ) {
if ( $this->check_key( $social_links[0]['service'] ) ) {
if ( $this->check_array( $social_links, 'service' ) ) {
$output .= '<ul class="' . $class . '">';

foreach ( $social_links as $link ) {
Expand Down
4 changes: 2 additions & 2 deletions lib/theme-setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function method_register_custom_nav_menus() {
//-----------------------------------------------------

function method_scripts() {
wp_enqueue_style( 'method', get_template_directory_uri() . '/theme.min.css', '', '1.3.8' );
wp_enqueue_script( 'method', get_template_directory_uri() . '/assets/js/scripts.min.js', array( 'jquery' ), '1.3.8', false );
wp_enqueue_style( 'method', get_template_directory_uri() . '/theme.min.css', '', '1.3.9' );
wp_enqueue_script( 'method', get_template_directory_uri() . '/assets/js/scripts.min.js', array( 'jquery' ), '1.3.9', false );


}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "method",
"version": "1.3.8",
"version": "1.3.9",
"description": "A barebones foundation for custom theme development.",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Theme Name: Method
Theme URI: https://github.com/pixelwatt/method
Description: A barebones foundation for custom theme development.
Version: 1.3.8
Version: 1.3.9
License: GNU General Public License v2 or later,
Author: Rob Clark
Author URI: https://robclark.io/
Expand Down

0 comments on commit 487d410

Please sign in to comment.