Created
December 5, 2015 13:57
-
-
Save merianos/5a6e23746c5160d56b50 to your computer and use it in GitHub Desktop.
PageBuilder final result
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
function register_my_widgets_folder( $folders = array() ) { | |
$folders[] = dirname( __FILE__ ) . '/widgets/'; | |
return $folders; | |
} | |
add_filter( 'siteorigin_widgets_widget_folders', 'register_my_widgets_folder' ); | |
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 ); | |
function register_unique_namespace( $class_prefixes = array() ) { | |
$class_prefixes[] = 'My_Custom_Field_'; | |
return $class_prefixes; | |
} | |
add_filter( 'siteorigin_widgets_field_class_prefixes', 'register_unique_namespace' ); | |
function register_my_custom_fields_folder( $class_paths = array() ) { | |
$class_paths[] = dirname( __FILE__ ) . '/fields/'; | |
return $class_paths; | |
} | |
add_filter( 'siteorigin_widgets_field_class_paths', 'register_my_custom_fields_folder' ); | |
function load_custom_fields() { | |
$base_dir = dirname( __FILE__ ) . '/fields/'; | |
foreach ( glob( $base_dir . '*.php' ) as $file ) { | |
require_once $file; | |
} | |
} | |
add_action( 'admin_init', 'load_custom_fields' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment