Comments (3)
This could cause confusion for users so I've updated the readmes and external docs with a note
from gutenberg-ramp.
I recently merged a method to check if a post type can support Gutenberg
I can port it to the main class and we can check whther a post type can support Gutenberg before storing it in options.
However, checking for what a post type can do should wait for at least init
action because the Codex suggests that post types are registered at init:
register_post_type
Description
Create or modify a post type. register_post_type should only be invoked through the 'init' action. It will not work if called before 'init', and aspects of the newly created or modified post type will work incorrectly if called later.
This means that if we perform the post_type check in ramp_for_gutenberg_load_gutenberg
and the function is simply added in theme functions.php - ramp_for_gutenberg_load_gutenberg
will be called way before init
and will fail for post types that haven't yet been registered.
Rubber ducking: 🦆
Method 1
Modify the documentation and ask people to wait at least until init
to register ramp support, so, something like this:
add_action('init', function() {
ramp_for_gutenberg_load_gutenberg( array('post_types' => array('post') ) );
});
Caveats:
- People don't read the docs carefully and might miss that they have to wait for init
- It's lengthy to type out
Method 2
Turn the ramp_for_gutenberg_load_gutenberg
function into a wrapping function that automattically does everything on init hook. Something like this:
function ramp_for_gutenberg_load_gutenberg_public( $criteria ) {
if( did_action('init') ) {
echo "You're too late! Please move this execute this function before `init` hook.";
return false;
}
add_action('init', function() use ($criteria) {
ramp_for_gutenberg_load_gutenberg($criteria);
} );
}
Caveats:
- PHP 5.3 is required for this
Method 3
Store options instantly, perform an additional cleanup/check on shutdown
or init:priority = 10000
and remove post types that aren't supported. This would be messy on the back-end a bit, but PHP 5.2 compatible and with a clean interface function.
Caveats:
- A lot of database/cache touching
Method 4
Almost the same as Method 3, but instead - store all options in a Singleton class variable and on init:priority = 10000
or shutdown
save everything to options and make sure the post types can be stored in one go.
Caveats:
None? Rubber ducking worked nicely again.
from gutenberg-ramp.
@justnorris as you predicted I like method 4 ... ie: delay the saving of the criteria until late enough. I can't really think of any reason why this would be bad .. it doesn't really matter when the option is written as long as it happens in the same page generation.
from gutenberg-ramp.
Related Issues (20)
- In settings, improve checkbox UI for enabling custom post types HOT 6
- Cross linking an issue in regards to additional editing options HOT 1
- Suggested enhancements - to plugin or to documentation HOT 4
- generalize criteria for GB loading HOT 8
- Disable 'try Gutenberg' banner in wp 4.9.8, if using Ramp HOT 7
- Admin Alert when Gutenberg is off - dismissible forever HOT 1
- Autoloading ramp options HOT 3
- Does not support 'fallback' mode HOT 2
- allow opt-in to Gutenberg by post/page slug or tag HOT 2
- Bug: Gist embedding not displaying in editor HOT 1
- wpcom_vip_load_gutenberg doesn't allow meta boxes to be loaded HOT 3
- Disable Ramp when Gutenberg version requirements aren't met HOT 3
- All options in the UI should be greyed out in the cases where Ramp sets Gutenberg to always or never load
- Make Ramp + Classic Editor play nicer together HOT 2
- Make it clearer how to enable Gutenberg for all post types HOT 1
- Add some clarity to the documentation about Gutenberg requirement HOT 1
- "Greater Than" HOT 4
- Ability to modify admin screen access
- The UI isn't displaying at all. HOT 1
- Plugin always loads classic-editor when classic-editor plugin is installed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gutenberg-ramp.