Skip to content

Instantly share code, notes, and snippets.

@merianos
Last active December 5, 2015 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merianos/1e1a5b2fbef1a02a11bb to your computer and use it in GitHub Desktop.
Save merianos/1e1a5b2fbef1a02a11bb to your computer and use it in GitHub Desktop.
Explain Page Builder how to load your widgets
function manually_load_widgets() {
$widgets_folder = dirname( __FILE__ ) . '/widgets/';
$contents = scandir( $widgets_folder );
foreach( $contents as $item ) {
if ( '.' === $item || '..' === $item || !is_dir( $widgets_folder . $item ) ) {
continue;
}
foreach ( glob( $widgets_folder . $item . '/*.php' ) as $file ) {
$file_data = get_file_data(
$file,
array(
'Widget Name' => 'Widget Name',
'Description' => 'Description',
'Author' => 'Author',
'Author URI' => 'Author URI',
'Widget URI' => 'Widget URI',
'Video URI' => 'Video URI',
)
);
if ( isset( $file_data[ 'Widget Name' ] ) && ! empty( $file_data[ 'Widget Name' ] ) ) {
require_once $file;
}
}
}
}
add_action( 'after_setup_theme', array( $this, 'manually_load_widgets' ), 11 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment