Auto-loader like CMB2
Would love to see an auto-loader like CMB2 that loads the latest version always.
This is probably all you need: http://jtsternberg.github.io/wp-lib-loader/
Let me know if you have questions.
Basically, you'd replace the current contents of the CPT_Core.php file with the contents of the loader (which you can generate at that site), and then move the current CPT_Core.php file to lib folder (or anywhere really). This ensures all current code loading that file will still work, but the lib loader will kick in.
@jtsternberg from left field 😄 we were looking into this today and got side-tracked.
Hi @jtsternberg I'm trying to include WP Lib Loader in Taxonomy_Core and facing a problem with functions visibility. Here's the code I have so far: https://github.com/WebDevStudios/Taxonomy_Core/commit/179a122c3856f78a2ea9170a6e58232b93ba5418 so when I load Taxonomy_Core with this:
require_once 'Taxonomy_Core/Taxonomy_Core.php';
$genres = register_via_taxonomy_core( array(
__( 'Genre', 'your-text-domain' ), // Singular
__( 'Genres', 'your-text-domain' ), // Plural
'genre' // Registered name
) );`
both auto-loader and library seems to be loaded, though register_via_taxonomy_core() call fails with Fatal error: Uncaught Error: Call to undefined function register_via_taxonomy_core()
I'm not sure why it happens and if I missed something. Could you please take a look?
Thanks, Pavel
Your require_once needs to happen outside of any hook. Do you have it that way?
This should work:
require_once 'Taxonomy_Core/Taxonomy_Core.php';
function myprefix_register_taxonomies() {
$genres = register_via_taxonomy_core( array(
__( 'Genre', 'your-text-domain' ), // Singular
__( 'Genres', 'your-text-domain' ), // Plural
'genre' // Registered name
) );
}
add_action( 'taxonomy_core_load', 'myprefix_register_taxonomies', TAXONOMY_CORE_LOADED + 1 );
@jtsternberg yes, that's helped. Thanks a lot! :+1: @JayWood with this change we'll need to update all the documentation for the library and flag it as important, because library initiation method had changed.
@JayWood I have added the same update to CPT Core library, though I can't think of any usage examples inside of a class for Readme file. We probably will have to change library's construct to allow class initiation on its load? Otherwise there's no way for classes to extend it after its files were incuded in PHP.