Created
August 19, 2018 22:14
-
-
Save janzikmund/cfa88e1a619b576d750561b060df5793 to your computer and use it in GitHub Desktop.
WordPress class for automatically registered shortcode functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom shortcodes | |
*/ | |
class LHShortcodes | |
{ | |
/** | |
* Constructor | |
*/ | |
public function __construct() | |
{ | |
// register all methods as shortcodes | |
$skip = ['__construct']; | |
$methods = get_class_methods($this); | |
foreach($methods as $method) { | |
if(in_array($method, $skip)) continue; | |
add_shortcode(str_replace('_', '-', $method), [$this, $method]); | |
} | |
} | |
// actual year | |
public function actual_year($atts, $content = "") { | |
return date('Y'); | |
} | |
/* | |
// image grid | |
public function tb_image_grid($atts, $content = "") { | |
$atts = shortcode_atts( array( | |
'bg' => false, | |
'align' => false, | |
), $atts, str_replace('_', '-', __FUNCTION__) ); | |
ob_start(); ?> | |
<div class="tb-row tb-align-<?php echo $atts['align']; ?>"> | |
<img src="<?php echo $atts['bg']; ?>"> | |
<div class="tb-content"> | |
<?php echo apply_filters('the_content', $content); ?> | |
</div> | |
</div> | |
<?php return ob_get_clean(); | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment