[wp-trac] [WordPress Trac] #25542: Function "set_site_transient" is executed twice for plugins - Is it necessary?
WordPress Trac
noreply at wordpress.org
Fri Nov 1 22:52:34 UTC 2013
#25542: Function "set_site_transient" is executed twice for plugins - Is it
necessary?
-------------------------------------------------+-------------------------
Reporter: johnstonphilip | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting
Component: Performance | Review
Severity: trivial | Version: 3.6.1
Keywords: 2nd-opinion needs-testing dev- | Resolution:
feedback |
-------------------------------------------------+-------------------------
Comment (by johnstonphilip):
Hey @nacin - thanks for responding. I see what you're saying now.
I thought of caching it in my own transient - but there aren't any hooks
in the update check process that I can use to do so - at least none that I
have found. Is there an action hook I am missing that might be useful
here?
Just to play with it, I added an action hook on line 257 of update.php
tentatively called "custom_api_calls". Here's a paste bin with it added:
http://pastebin.com/WY7LLeUp
Then in my plugin I just add this function which is hooked to that action
to save all my custom plugin data in a transient:
{{{
function my_custom_api_calls_action() {
$custom_api_plugins = new stdClass();
$custom_api_plugins = apply_filters( 'my_custom_plugins_filter',
$custom_api_plugins );
set_site_transient( 'my_custom_plugins', $custom_api_plugins);
}
add_action( 'custom_api_calls', 'my_custom_api_calls_action' );
}}}
And then I feed that back into the "pre_set_site_transient_update_plugins"
filter using this function:
{{{
function pre_set_site_transient_update_plugins_filter( $_transient_data )
{
if( empty( $_transient_data ) ) return $_transient_data;
//Get the custom plugins we have added to our custom transient
$api_responses = get_site_transient('my_custom_plugins');
//Loop through each custom plugin in the custom transient object
foreach ( $api_responses->response as $plugin_name =>
$api_response ){
//Add each custom plugin to the
pre_set_site_transient_update_plugins value
$_transient_data->response[$plugin_name] = $api_response;
}
//Return the new array which includes all custom plugins and
WP.org plugins
return $_transient_data;
}
add_filter( 'pre_set_site_transient_update_plugins',
'pre_set_site_transient_update_plugins_filter' );
}}}
And it works like a charm :)
Do you think adding an action hook on line 257 is a possibility?
--
Ticket URL: <http://core.trac.wordpress.org/ticket/25542#comment:6>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list