Skip to content

Commit

Permalink
Added a filter and action to allow for easily adding custom format ta…
Browse files Browse the repository at this point in the history
…gs, and adds an optional $fallback argument to the get_meta(), get_loaded_meta(), and get_option() methods
  • Loading branch information
pixelwatt committed Sep 25, 2021
1 parent 6b81c04 commit 16479bd
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
## 1.3.4

Changes:
* ( lib/class-method-layout.php ) Implemented a new filter, 'method_format_tags', which can be used to add format tags to the array of format tags found in the format_tags() method.
* ( lib/class-method-layout.php ) Added a new format tag, `[bull]`, which is converted to `<span class="method-bull">&bull;</span>` by the format_tags() method.
* ( lib/class-method-layout.php ) Added an optional $fallback argument to the get_meta(), get_loaded_meta(), and get_option() methods. If the requested key does not exist or is empty, the value of $fallback will be returned, if provided. Fallback values will not be processed in any way and support full html.
* ( lib/admin-customization.php ) Added a new action, 'method_after_tags_dialog_html', which can be used to inject html into the bottom of the format tags dialog.

---

## 1.3.3

Changes:
Expand Down
5 changes: 4 additions & 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.3' );
wp_enqueue_style( 'method', get_template_directory_uri() . '/assets/css/admin-styles.css', '', '1.3.4' );
}

add_action( 'admin_enqueue_scripts', 'method_admin_scripts' );
Expand Down Expand Up @@ -36,6 +36,9 @@ function method_admin_footer_function() {
<hr>
<h5>[br]</h5>
<p>This tags allows you to insert a line break. Use <code>[br]</code> for the line break to appear on all devices, <code>[mbr]</code> for the line break to only appear on mobile, and <code>[dbr]</code> for the break to only appear on desktop.<br><em>(Ex: "I want this text on line 1,[br]and this text on line 2.")</em></p>
';
do_action( 'method_after_tags_dialog_html' );
echo '
</div>
';
}
Expand Down
17 changes: 9 additions & 8 deletions lib/class-method-layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//======================================================================
//
// METHOD LAYOUT CLASS v1.3.3
// METHOD LAYOUT CLASS v1.3.4
//
// You probably don't want or need to edit this file.
//
Expand Down Expand Up @@ -204,14 +204,14 @@ protected function reset_markup() {
// Get data for a meta key (current post)
//-----------------------------------------------------

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

//-----------------------------------------------------
Expand Down Expand Up @@ -275,14 +275,14 @@ public function unload_meta() {
// Get data for a meta key (loaded meta)
//-----------------------------------------------------

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

//-----------------------------------------------------
Expand Down Expand Up @@ -331,14 +331,14 @@ public function get_loaded_content( $key, $before, $after, $fallback = '' ) {
// Get an option from retrieved theme options
//-----------------------------------------------------

public function get_option( $key ) {
public function get_option( $key, $fallback = '' ) {
$output = false;
if ( isset( $this->opts[ "{$key}" ] ) ) {
if ( ! empty( $this->opts[ "{$key}" ] ) ) {
$output = $this->opts[ "{$key}" ];
}
}
return $output;
return ( false === $output ? ( ! empty( $fallback ) ? $fallback : false ) : $output );
}

//-----------------------------------------------------
Expand Down Expand Up @@ -427,8 +427,9 @@ public function format_tags( $text ) {
'[/em]' => '</em>',
'[u]' => '<span class="method-underlined">',
'[/u]' => '</span>',
'[bull]' => '<span class="method-bull">&bull;</span>',
);
return $this->str_replace_assoc( $tags, $text );
return $this->str_replace_assoc( apply_filters( 'method_format_tags', $tags ), $text );
}

//-----------------------------------------------------
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.3' );
wp_enqueue_script( 'method', get_template_directory_uri() . '/assets/js/scripts.min.js', array( 'jquery' ), '1.3.3', false );
wp_enqueue_style( 'method', get_template_directory_uri() . '/theme.min.css', '', '1.3.4' );
wp_enqueue_script( 'method', get_template_directory_uri() . '/assets/js/scripts.min.js', array( 'jquery' ), '1.3.4', 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.3",
"version": "1.3.4",
"description": "A barebones foundation for custom theme development.",
"main": "index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
Theme Name: Method
Theme URI: https://github.com/pixelwatt/method
Description: A barebones foundation for custom theme development.
Version: 1.3.3
Version: 1.3.4
Author: Rob Clark
Author URI: https://robclark.io/
Tags: cmb2, bootstrap
Tags: CMB2, Bootstrap 5
*/

0 comments on commit 16479bd

Please sign in to comment.