[wp-hackers] internal redirects
John Bloch
jbloch at olympianetworks.com
Thu Apr 29 11:10:38 UTC 2010
Or, since it seems you only need this on pages or single posts, why not use:
global $wp_query;
if( $wp_query->post->post_name == get_option( 'my_plugin_slug' ) ) {
add_action('wp_loaded', 'my_plugin_check');
add_shortcode('public-gallery', 'my_plugin');
}
John P. Bloch
On Thu, Apr 29, 2010 at 5:06 AM, capsx <capsx at team.lv> wrote:
> thx for the answers
>
> but - what is the best way to call function add_action('wp_loaded',
> 'function')
> only when the specific slug is called - let my_plugin_check function is
> executed only when it needs to be executed
>
> i made it like this:
>
> ---
> $plugin_call_slug = get_option('my_plugin_slug');
>
> $requested_uri = $_SERVER['REQUEST_URI'];
>
> $requested_page = get_page_by_path($requested_uri);
> $requested_page = $requested_page->post_name;
>
> if($requested_page == $plugin_call_slug)
> {
> add_action('wp_loaded', 'my_plugin_check');
> add_shortcode('public-gallery', 'my_plugin');
> }
>
> ---
>
> On Tue, 27 Apr 2010 19:02:04 +0100
>
> Peter Westwood <peter.westwood at ftwr.co.uk> wrote:
>
>>
>> On 27 Apr 2010, at 18:47, Otto wrote:
>>
>> If you're going to do redirects, best to do them as early as possible.
>>> I have plugin code that looks basically like this:
>>>
>>> if (array_key_exists('my_check_thingy', $_GET) &&
>>> $_GET['my_check_thingy'] == 1) { ?>
>>> ... logic for redirect ...
>>> }
>>>
>>> This happens right at plugin load. No waiting about, no loading the
>>> query, just do it. Works fine, speedy as heck.
>>>
>>
>>
>> Doing things as early as possible is good.
>>
>> Doing things when your plugin is included is not recommended.
>>
>> Better to use the earliest available suitable hook - plugins_loaded / init
>> / wp_loaded (3.0 and later only)
>>
>> That way you can ensure that all the WordPress core functionality you
>> might be relying on will always be available.
>>
>> --
>> Peter Westwood
>> http://blog.ftwr.co.uk | http://westi.wordpress.com
>> C53C F8FC 8796 8508 88D6 C950 54F4 5DCD A834 01C5
>>
>> _______________________________________________
>> wp-hackers mailing list
>> wp-hackers at lists.automattic.com
>> http://lists.automattic.com/mailman/listinfo/wp-hackers
>>
>
> -nonse response-
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list