Skip to content

Instantly share code, notes, and snippets.

@uprise10
Created October 11, 2012 12:17
Show Gist options
  • Save uprise10/3871949 to your computer and use it in GitHub Desktop.
Save uprise10/3871949 to your computer and use it in GitHub Desktop.
<?php
// Load all widgets from /lib/widgets directory
$widgets_path = STYLESHEET_PATH . 'lib/widgets';
$widgets_dir = @opendir( $widgets_path );
$widgets = array();
if ($widgets_dir) {
while (($entry = @readdir($widgets_dir)) !== false) {
$full_dir_path = $widgets_path . "/" . $entry;
if( is_readable( $full_dir_path ) && is_dir( $full_dir_path ) && !in_array( $entry, array( '..' ) ) ) {
$module_dir = @opendir( $full_dir_path );
if ($module_dir) {
while (($module_entry = @readdir($module_dir)) !== false) {
if (strrchr($module_entry, '.') === '.php') {
require_once( $full_dir_path . '/' . $module_entry );
$widgets[] = str_replace( '.php', '', $module_entry );
}
}
}
}
}
@closedir($widgets_dir);
}
add_action( 'widgets_init', 'uprs_register_widgets' );
function uprs_register_widgets() {
global $widgets;
foreach( $widgets as $widget ) {
if( class_exists( $widget ) )
register_widget( $widget );
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment