Comments (4)
There is no documentation for this task
Subtle. ;)
Leaving aside discussion about goodness of global variables
It's interesting how WP takes pride in zillion of plugins, but has zero mechanisms or conventions for them to interact. Is global a good thing? In general no. In WordPress it's not like there is clean and pretty way to do what it does without some singleton abomination. So could as well...
before $fragment_cache->run(); is called
I get that you consider this an issue, but you kind of omit why is this an issue? Neither handlers approach was designed with any regard to run()
timing or the method executing anything but hooks setup.
The benefits should be pretty clear: custom handlers can be added using that hook
One more way to do something already possible isn't necessarily benefit by default. You can use init
for this just as well and you don't have to learn/remember/debug custom plugin–specific hook,
can be used to disable specific handler initialization before it is enabled
So can init
be, same as above.
My conclusions on suggestion are roughly following:
- As addition to global this is a little of addition for the sake of addition. I had put a lot of effort into having very minimal code/API for the plugin and having it refined to the main function. It does only what it has to do.
- As replacement for the global this is backwards compatibility break (so no earlier than 2.0 because semver) and (in current form) it narrows timing of access to the instance to the load, which is inconvenient and (in this regard) inferior to global.
from fragment-cache.
It's interesting how WP takes pride in zillion of plugins, but has zero mechanisms or conventions for
them to interact. Is global a good thing? In general no. In WordPress it's not like there is clean and
pretty way to do what it does without some singleton abomination. So could as well...
I said "leaving aside" because really I know that in WordPress context that discussion make almost no sense: avoid global in plugins can't be a so great enhancement if WP itself has zillion of global vars. In addition I know that you can't remove the global, because actually is the only method to make plugin container accessible.
I get that you consider this an issue, but you kind of omit why is this an issue?
I don't think it is an issue, but I think my approach simplify the process.
If I'm not wrong (and it's reasonable that I am) the code needed is:
add_action( 'after_setup_theme', function() { // run before 'init', so we are in time
if ( ! class_exists('Rarst\Fragment_Cache\Plugin' ) ) {
return; // must check plugin is active
}
global $fragment_cache;
$fragment_cache->add_fragment_handler( 'gm-foo-bar', 'GM\\Foo\\Bar' );
} );
Using my approach code should be:
add_action( 'fragment_cache_init', function( $fragment_cache ) {
$fragment_cache->add_fragment_handler( 'gm-foo-bar', 'GM\\Foo\\Bar' );
} );
As said is not an issue, but make life easier for external developers and I bet it's easier to document, when and if you'll decide to do it ;P
That said, feel free to close the issue, I'm already working on the custom handler and I have to make it work that is far harder than add it to your plugin. And, I realised to didn't said that: thanks for it, it's really a good one.
from fragment-cache.
In addition I know that you can't remove the global, because actually is the only method to make plugin container accessible.
Actually passing instance through the filter is one of the ways to do without global. But in that case can only access it via that filter so only for anti-global purists mostly (cough toscho cough).
Using my approach code should be:
So the difference is basically the need to check if plugin exists. This is valid for developer experience and exactly what I was trying to get you to explain. :)
I guess I am not adding it right now, but I am keeping this in mind (for v2 if it makes sense to me at that point).
thanks for it, it's really a good one
You are very welcome. :) Keep me posted about how it works out for you.
from fragment-cache.
Actually passing instance through the filter is one of the ways to do without global. But in that case
can only access it via that filter so only for anti-global purists mostly
Yes, using a filter instead of an action you can make it accessible, I tried that approach sometimes but doesn't seem a very good one, for Brain I've used the classical Container::instance()
method, even if an action to allow adding variables to Pimple container (in a very similar way I suggested to you) is also available there.
So the difference is basically the need to check if plugin exists.
And globalize the container var :)
from fragment-cache.
Related Issues (11)
- Parse error: syntax error, unexpected end of file in fragment_cache.php on line 161 HOT 7
- The transient name never includes the menu name HOT 5
- Skip cache examples for each object type HOT 7
- Review handling of widgets in Customizer HOT 1
- Disable updates from WordPress.org HOT 8
- Clashes with Jetpack galleries HOT 13
- Consider style and script tracking HOT 1
- Update conflict with wordpress.org plugin HOT 6
- Use `pre_wp_nav_menu` for the menu HOT 2
- Changing menu via customizer does not invalidate cache HOT 1
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 fragment-cache.