Trigger an error when a required include fails to be included...#1042
Trigger an error when a required include fails to be included...#1042QWp6t merged 1 commit intoroots:masterfrom al-the-x:better-partial-includes
Conversation
|
👍 But I have a feeling that the roots folks are gonna balk at your closure. You'll notice that closures are not used anywhere in roots. |
|
I feel ya. I've mentioned both here and in Bedrock repo that I think all of the Roots projects shouldn't be afraid to just use modern PHP syntax. I think using short syntax for arrays, closures where appropriate, etc., shouldn't be considered controversial, and it's consistent with @swalkinshaw's quest to "drag WordPress into 2014." On the other hand, it's harder to reach a wide audience when you start leaving people behind because their shared hosting account doesn't make modern versions of PHP available to them. |
|
Yeah, I agree for the most part, but the last few versions of PHP have contained very major language changes and been released much faster than previous versions. It will take some time to build up momentum when your language runs 80% of the internet. ;) |
|
We'll probably switch a PHP 5.3 requirement soon since we want to use namespaces. Nothing I hate more than prefixing function names. |
|
^ 👍 |
|
Support for 5.3 ends next month. So that's still a bit old, but I suspect it's a good compromise between the old and new. Hell yeah for namespacing. I ALMOST submitted a pull request for Soil to add namespacing because |
|
On second look, you don't need to array_map this at all. I think this belongs in a v6.x$roots_includes = array(
'/lib/utils.php', // Utility functions
'/lib/init.php', // Initial theme setup and constants
'/lib/wrapper.php', // Theme wrapper class
'/lib/sidebar.php', // Sidebar class
'/lib/config.php', // Configuration
'/lib/activation.php', // Theme activation
'/lib/titles.php', // Page titles
'/lib/cleanup.php', // Cleanup
'/lib/nav.php', // Custom nav modifications
'/lib/gallery.php', // Custom [gallery] modifications
'/lib/comments.php', // Custom comments modifications
'/lib/relative-urls.php', // Root relative URLs
'/lib/widgets.php', // Sidebars and widgets
'/lib/scripts.php', // Scripts and stylesheets
'/lib/custom.php', // Custom functions
);v7.x$roots_includes = array(
'/lib/utils.php', // Utility functions
'/lib/init.php', // Initial theme setup and constants
'/lib/wrapper.php', // Theme wrapper class
'/lib/sidebar.php', // Sidebar class
'/lib/config.php', // Configuration
'/lib/activation.php', // Theme activation
'/lib/titles.php', // Page titles
'/lib/nav.php', // Custom nav modifications
'/lib/gallery.php', // Custom [gallery] modifications
'/lib/comments.php', // Custom comments modifications
'/lib/scripts.php', // Scripts and stylesheets
'/lib/extras.php', // Custom functions
);Note that I separated the array out into a variable for readability purposes, but also in case anyone wants to manipulate it before the loop.
|
|
My primary motivation of this ticket was to avoid relying on the I proposed using a map operation to remove some of the repetition (require Although debating the validity of scope isolation is off-topic a bit and
|
|
You're correct that the scope should be isolated, and I personally isolate it on my end, but it might yield unexpected results for certain users which is why I opted not to make that change in my post above. Also, This would give you the results you want, yeah?: foreach($roots_includes as $file){
if($filepath = locate_template($file)) {
require_once($filepath);
} else {
trigger_error("Error locating `$file` for inclusion!", E_USER_ERROR);
}
} |
|
You make a good point about WP devs being surprised by an isolated scope. That's just how WP rolls, amirite? If I might refactor your proposal... I prefer guards to foreach($roots_includes as $file){
if ( ! $filepath = locate_template($file) ) {
trigger_error("Error locating `$file` for inclusion!", E_USER_ERROR);
}
require_once $filepath;
}Since I still prefer the brevity of my original proposal, but I can definitely concede your points. |
|
If you can squash all of this into one commit and submit it as the following (to make it stylistically consistent with the rest of Roots), I've been given the green light to merge it. $roots_includes = array(
'/lib/utils.php', // Utility functions
'/lib/init.php', // Initial theme setup and constants
'/lib/wrapper.php', // Theme wrapper class
'/lib/sidebar.php', // Sidebar class
'/lib/config.php', // Configuration
'/lib/activation.php', // Theme activation
'/lib/titles.php', // Page titles
'/lib/cleanup.php', // Cleanup
'/lib/nav.php', // Custom nav modifications
'/lib/gallery.php', // Custom [gallery] modifications
'/lib/comments.php', // Custom comments modifications
'/lib/relative-urls.php', // Root relative URLs
'/lib/widgets.php', // Sidebars and widgets
'/lib/scripts.php', // Scripts and stylesheets
'/lib/custom.php', // Custom functions
);
foreach($roots_includes as $file) {
if(!$filepath = locate_template($file)) {
trigger_error("Error locating `$file` for inclusion!", E_USER_ERROR);
}
require_once $filepath;
}
unset($file, $filepath); |
|
Happy to do it. Is there a style document for the project so I can avoid
|
|
Squashed. Merge at your convenience...! Happy dad's day, all. |
|
Rebased on |
Trigger an error when a required include fails to be included...
commit 88b663d Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:52:29 2014 -0400 Re-add Google Analytics commit 5f76ca9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 08:22:31 2014 -0400 use WP HTML5 markup for captions instead of Soil commit 3f0baa5 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 08:19:09 2014 -0400 Remove relative URLS commit c1b3108 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:50:36 2014 -0400 Remove vcard widgets commit eab0030 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 23:36:41 2014 -0400 Typo fix commit c6f4f1e Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:49:55 2014 -0400 Mirroring Roots LESS structure commit 01bada9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 21:16:12 2014 -0400 Remove extra forward slash after navbar home_url() Conflicts: templates/header.php commit 69ac35a Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:38:22 2014 -0400 Initiate the loop for template-custom.php Just as roots#1056 added a loop-start to page.php, this adds a loop-start to template-custom.php. commit 76f4141 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:36:01 2014 -0400 Add library comments Conflicts: functions.php commit 416bc63 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:34:02 2014 -0400 Changed esc_url to esc_url_raw in redirect commit 7cffb45 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:31:05 2014 -0400 Fixed search value, changed back to get_search_query, removed unnecessary check Conflicts: templates/searchform.php commit 7c4ba71 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:26:40 2014 -0400 Update lib/init.php commit c2b514c Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:43:35 2014 -0400 Updated all instances of home_url() with esc_url() Conflicts: templates/header-top-navbar.php templates/searchform.php commit bb3cdd9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:17:27 2014 -0400 Use `get_comment_date` instead of `comment_date` Because `comment_date` already displays / echo's it value. http://codex.wordpress.org/Function_Reference/comment_date http://codex.wordpress.org/Function_Reference/get_comment_date commit 3417c97 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:15:43 2014 -0400 Move comments.php conditionals inside <section> tags to ensure section#comments and section#respond are always present to avoid breaking comments_link() function Line 54 __( --> _e( Conflicts: templates/comments.php commit 85b5b5c Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:46:35 2014 -0400 Fix is_element_empty commit 9ed8985 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:46:02 2014 -0400 Update page.php Spacing edit commit 75b6e69 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:44:57 2014 -0400 Reducing duplication and better utilizing the WP built-in `locate_template()` Re recommendations from @QWp6t in roots#1042 commit 4aaf820 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:43:52 2014 -0400 Initiate the loop before the title is called on pages. Failing to do so causes checks that run on the loop's status to fail. commit cb74d48 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:42:49 2014 -0400 Remove footer copyright element Conflicts: templates/footer.php commit b5d7459 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:35:02 2014 -0400 Switch to filters with proper classes commit a404ef8 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:41:38 2014 -0400 Switch to SOIL
commit 88b663d Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:52:29 2014 -0400 Re-add Google Analytics commit 5f76ca9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 08:22:31 2014 -0400 use WP HTML5 markup for captions instead of Soil commit 3f0baa5 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 08:19:09 2014 -0400 Remove relative URLS commit c1b3108 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:50:36 2014 -0400 Remove vcard widgets commit eab0030 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 23:36:41 2014 -0400 Typo fix commit c6f4f1e Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:49:55 2014 -0400 Mirroring Roots LESS structure commit 01bada9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 21:16:12 2014 -0400 Remove extra forward slash after navbar home_url() Conflicts: templates/header.php commit 69ac35a Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:38:22 2014 -0400 Initiate the loop for template-custom.php Just as roots#1056 added a loop-start to page.php, this adds a loop-start to template-custom.php. commit 76f4141 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:36:01 2014 -0400 Add library comments Conflicts: functions.php commit 416bc63 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:34:02 2014 -0400 Changed esc_url to esc_url_raw in redirect commit 7cffb45 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:31:05 2014 -0400 Fixed search value, changed back to get_search_query, removed unnecessary check Conflicts: templates/searchform.php commit 7c4ba71 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:26:40 2014 -0400 Update lib/init.php commit c2b514c Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:43:35 2014 -0400 Updated all instances of home_url() with esc_url() Conflicts: templates/header-top-navbar.php templates/searchform.php commit bb3cdd9 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:17:27 2014 -0400 Use `get_comment_date` instead of `comment_date` Because `comment_date` already displays / echo's it value. http://codex.wordpress.org/Function_Reference/comment_date http://codex.wordpress.org/Function_Reference/get_comment_date commit 3417c97 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 20:15:43 2014 -0400 Move comments.php conditionals inside <section> tags to ensure section#comments and section#respond are always present to avoid breaking comments_link() function Line 54 __( --> _e( Conflicts: templates/comments.php commit 85b5b5c Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:46:35 2014 -0400 Fix is_element_empty commit 9ed8985 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:46:02 2014 -0400 Update page.php Spacing edit commit 75b6e69 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:44:57 2014 -0400 Reducing duplication and better utilizing the WP built-in `locate_template()` Re recommendations from @QWp6t in roots#1042 commit 4aaf820 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:43:52 2014 -0400 Initiate the loop before the title is called on pages. Failing to do so causes checks that run on the loop's status to fail. commit cb74d48 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:42:49 2014 -0400 Remove footer copyright element Conflicts: templates/footer.php commit b5d7459 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Mon Jul 28 19:35:02 2014 -0400 Switch to filters with proper classes commit a404ef8 Author: mAAdhaTTah <jamesorodig@gmail.com> Date: Tue Jul 29 17:41:38 2014 -0400 Switch to SOIL
|
Hello Every one i got the same error My php version is 5.3.5. |
|
@kuldeepphp This is not a support forum, you should ask for assistance on the Roots Discourse: |
I encountered this while attmepting to deploy a Roots-based theme to @wpengine via git. A global
.gitignorerule omitted the contents ofroots/lib/from the index, so none of therequire_oncelines fromfunctions.phpworked. Thelocate_template()function canrequirethe file, given appropriate flags, and returns an empty string if it can't find it. More useful would be an error message when this occurs. Whether this deservesE_USER_ERROR,E_USER_WARNINGorE_USER_NOTICEis a subject for debate. Please advise.