Refactoring

This commit is contained in:
thanghv 2020-05-05 20:13:38 +07:00
parent 159205b55d
commit bca98c3a1a
35 changed files with 340 additions and 285 deletions

View file

@ -16,11 +16,25 @@ if ( ! defined( 'MAINWP_CHILD_FILE' ) ) {
define( 'MAINWP_CHILD_FILE', __FILE__ );
}
if ( ! defined( 'MAINWP_CHILD_PLUGIN_DIR' ) ) {
define( 'MAINWP_CHILD_PLUGIN_DIR', plugin_dir_path( MAINWP_CHILD_FILE ) );
}
if ( ! defined( 'MAINWP_CHILD_URL' ) ) {
define( 'MAINWP_CHILD_URL', plugin_dir_url( MAINWP_CHILD_FILE ) );
}
function mainwp_child_autoload( $class_name ) {
if ( 0 !== strpos( $class_name, 'MainWP\Child' ) )
return;
// trip the namespace prefix: MainWP\Child\ .
$class_name = substr( $class_name, 13 );
if ( 0 !== strpos( $class_name, 'MainWP_' ) ) {
return;
}
$autoload_dir = \trailingslashit( dirname( __FILE__ ) . '/class' );
$autoload_path = sprintf( '%sclass-%s.php', $autoload_dir, strtolower( str_replace( '_', '-', $class_name ) ) );
@ -33,6 +47,8 @@ if ( function_exists( 'spl_autoload_register' ) ) {
spl_autoload_register( 'mainwp_child_autoload' );
}
$mainWPChild = new MainWP_Child( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) );
require_once MAINWP_CHILD_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'functions.php';
$mainWPChild = new MainWP\Child\MainWP_Child( WP_PLUGIN_DIR . DIRECTORY_SEPARATOR . plugin_basename( __FILE__ ) );
register_activation_hook( __FILE__, array( $mainWPChild, 'activation' ) );
register_deactivation_hook( __FILE__, array( $mainWPChild, 'deactivation' ) );