Lưu ý rằng nếu chúng ta muốn sử dụng các lớp từ Simple Autoloader for WordPress 1 (ok)
require_once 'vendor/autoload.php';
spl_autoload_register( function($classname) {
// Loads any class placed within the classes folder, and namespaced correctly
$class = str_replace( '\\', DIRECTORY_SEPARATOR, str_replace( '_', '-', strtolower($classname) ) );
$classes = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classes' . DIRECTORY_SEPARATOR . $class . '.php';
// Loads classes from the vendor/makeitworkpress folder using autoloading
$vendor = str_replace( 'makeitworkpress' . DIRECTORY_SEPARATOR, '', $class );
$vendor = 'makeitworkpress' . DIRECTORY_SEPARATOR . preg_replace( '/\//', '/src/', $vendor, 1 ); // Replace the first slash for the src folder
$vendors = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . $vendor . '.php';
// Check if the files exist
if( file_exists($classes) ) {
require_once( $classes );
} elseif( file_exists($vendors) ) {
require_once( $vendors );
}
} );
$fields = MakeitWorkPress\WP_Custom_Fields\Framework::instance();
$fields->add('options', array(
'class' => 'tabs-left',
'id' => 'wp_custom_fields_options',
'title' => __('Theme Options', 'textdomain'),
'capability' => 'manage_options',
'menu_title' => __('Theme Options', 'textdomain'),
'menu_icon' => 'dashicons-admin-generic',
'menu_position' => 99,
'location' => 'menu',
'sections' => array(
array(
'id' => 'section_one',
'title' => __('Section One', 'textdomain'),
'icon' => 'camera_enhance',
'fields' => array(
array(
'columns' => 'half',
'id' => 'checkbox',
'title' => __('Example Title', 'textdomain'),
'description' => __('Example Description', 'textdomain'),
'type' => 'checkbox',
'style' => 'switcher',
'options' => array(
array('id' => 'thing_one', 'label' => __('Label One', 'textdomain')),
array('id' => 'thing_two', 'label' => __('Label Two', 'textdomain')),
),
),
),
),
),
));

wp-autoload
Introduction
Using WP Autoload
Using WP Autoload with Composer
PreviousUsing WP Autoload with Composer (ok)Next======= Start Sử dụng namespace & Autoload trong Plugin =======
Last updated