Skip to content

Instantly share code, notes, and snippets.

@5A5K1A
Created March 2, 2017 18:40
Show Gist options
  • Save 5A5K1A/3c2ce9cd035f24fb9e740f917e20c0ae to your computer and use it in GitHub Desktop.
Save 5A5K1A/3c2ce9cd035f24fb9e740f917e20c0ae to your computer and use it in GitHub Desktop.
WordPress Generic Object
<?php
/**
* Registers all ShortCode_* methods
*/
static public function Register_ShortCodes() {
// part of string to search for
$keyword = 'ShortCode_';
// loop all class methods
foreach( get_class_methods(__CLASS__) as $method ) {
// test method name for keyword
if( substr($method, 0, strlen($keyword)) == $keyword ) {
// this is a shortcode method! register it
$shortcode = str_replace( $keyword, '', $method );
add_shortcode( $shortcode, array(__CLASS__, $method) );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment