最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Child theme, how to cut the functions.php file into several classes?

programmeradmin2浏览0评论

The functions.php file of my Child Theme is a mess...
I'd like to use classes in a separate folder (like /inc) but I would like to keep a maximum of security.
For now everything works as excepted, but is my code safe enough to use in production ?

  • functions.php

    // Include our classes.  
    require_once( get_stylesheet_directory() . '/inc/class.my-class-1.php' );  
    require_once( get_stylesheet_directory() . '/inc/class.my-class-2.php' );  
    ...  
    
    // Instantiate our classes.  
    $my_class_1 = new My_Class_1();  
    $my_class_2 = new My_Class_2();  
    
    // Hooks goes here.  
    add_action( 'hook_i_want', array( $my_class_1, 'my_function_in_class_1'), 10 );  
    add_filter( 'other_hook_i_want', array( $my_class_2, 'my_function_in_class_2' ) );  
    ...
    

Or maybe a better idea ?

发布评论

评论列表(0)

  1. 暂无评论