Skip to content

Instantly share code, notes, and snippets.

@brentini
Forked from 5A5K1A/wordpress-hooks.php
Last active March 23, 2018 21:30
Show Gist options
  • Select an option

  • Save brentini/af1622932d20264b2bec23016126bb75 to your computer and use it in GitHub Desktop.

Select an option

Save brentini/af1622932d20264b2bec23016126bb75 to your computer and use it in GitHub Desktop.
WordPress Generic Object #wordpress
<?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