現時点では、複数のヘルパー関数ファイルを含む functions.php を使用して Wordpress テーマに取り組んでいます。子テーマをテーマに基づいて作成する場合、このテーマは非常に柔軟でカスタマイズ可能であってほしいと考えています。
現在、functions.php に次のコードがあります。
add_action( 'template_redirect', 'wpf_contact' );
/**
* Include the logic/settings for tpl-contact.php.
*
* Includes the logic/settings for tpl-contact.php. It will load the child's
* mail.inc.php first if that is available.
*/
if ( ! function_exists( 'wpf_contact' ) ) {
function wpf_contact() {
if ( is_page_template( 'tpl-contact.php' ) && is_child_theme() && file_exists( get_stylesheet_directory() . '/inc/wpf/mail.inc.php' ) ) {
include( get_stylesheet_directory() . '/inc/wpf/mail.inc.php' );
} else {
include( get_template_directory() . '/inc/wpf/mail.inc.php');
}
} // end wpf_contact()
}
上記のコードが行うことは、ファイルが存在する場合、子から mail.inc.php をロードすることです。親テーマからロードしない場合。
そのようにロードしたい複数のファイルがあるからです。これを行う簡単な方法はないのではないかと考えていましたか?WordPressでこれを行う組み込み関数はありますか?
または、上記の関数を調整してパラメーターを追加し、他のファイルにも使用できるようにする必要がありますか? これが効率的かどうかはわかりません。