Need A Hook (or advice)

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Need A Hook (or advice)

Garett Harnish
I need a way for a plugin to add a page to wp_list_pages.   I know no
hook exists to do this, and the only way I can think of duplicating this
functionality is ugly.

I could have the plugin insert a page into the blog, but I just need the
page listed, I don't want it to be displayed like page.  I want the
contents to be PHP code from the plugin and I want the page to remove
itself if the plugin has been disabled (since it won't work).

The other option is to have the user manually make the changes, but I
don't like that either.

Does anyone have any other suggestions?  I want the user to have to do
as few things as humanly possible (since it minimizes the risk of them
messing it up).

Thanks,
Garett
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Andy Skelton
On 2/27/06, Garett Harnish <[hidden email]> wrote:
> I need a way for a plugin to add a page to wp_list_pages.   I know no
> hook exists to do this, and the only way I can think of duplicating this
> functionality is ugly.

With the new post_type and post_status columns in the posts table, and
imminent (I think) removal of enums, you might just create a page with
an odd status that's ignored by the usual queries. It's all very Alpha
though.

Andy
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Mark Jaquith
In reply to this post by Garett Harnish
On Feb 27, 2006, at 3:47 PM, Garett Harnish wrote:

> I need a way for a plugin to add a page to wp_list_pages.   I know  
> no hook exists to do this, and the only way I can think of  
> duplicating this functionality is ugly.

There's a wp_list_pages hook, but it operates on the text output of  
the entire function.  What I'd like eventually is to have  
wp_list_pages pass a hierarchial array through a different filter  
first, so you could use simple array manipulation to insert your  
stuff, instead of search/replace.

> I could have the plugin insert a page into the blog, but I just  
> need the page listed, I don't want it to be displayed like page.  I  
> want the contents to be PHP code from the plugin and I want the  
> page to remove itself if the plugin has been disabled (since it  
> won't work).

Does the page need to have a "nice" URI?  Or is it okay if the page  
points directly to your plugin?

In any case, you can use the wp_list_pages hook to do something like  
this:

> function add_garetts_link($text) {
> return $text . '<li class="page_item"><a href="' .  
> get_garetts_page_link() . '" title="Garett's Title">Link Text</a></
> li>';
> }
>
> add_filter('wp_list_pages', 'add_garetts_link', 50); // high number  
> so that other plugins get to have their way first

obviously you'd have to write get_garetts_page_link().

But anyway, that'll append your link to the end in the same style  
that wp_list_pages() adds page links.  It's a simplistic method, but  
it might do for your needs.  If you need the URI to look pretty, you  
have a lot more coding to do as you need to add a rewrite rule, and  
have the link generate the fancy version only if rewrite rules are  
being used, etc.

--
Mark Jaquith
http://txfx.net/


_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Rob Miller-4
Mark Jaquith wrote:

> On Feb 27, 2006, at 3:47 PM, Garett Harnish wrote:
>
>> I need a way for a plugin to add a page to wp_list_pages.   I know no
>> hook exists to do this, and the only way I can think of duplicating
>> this functionality is ugly.
>
> There's a wp_list_pages hook, but it operates on the text output of
> the entire function.  What I'd like eventually is to have
> wp_list_pages pass a hierarchial array through a different filter
> first, so you could use simple array manipulation to insert your
> stuff, instead of search/replace.

This would make my life much, much easier with something I'm working on
at the moment. I think I'll stop working on it until this is added :)

--
Rob Miller
http://robm.me.uk/ | http://kantian.co.uk/

_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Garett Harnish
In reply to this post by Mark Jaquith
Mark Jaquith wrote:
> In any case, you can use the wp_list_pages hook to do something like this:
>> function add_garetts_link($text) {
>>     return $text . '<li class="page_item"><a href="' .
>> get_garetts_page_link() . '" title="Garett's Title">Link Text</a></li>';
>> }
>>
>> add_filter('wp_list_pages', 'add_garetts_link', 50); // high number so
>> that other plugins get to have their way first

That's brilliant.  A filter hook, I hadn't thought of that.  It is
exactly what I'm looking for.   Thank you.

 > If you need the URI to look pretty, you have a lot
> more coding to do as you need to add a rewrite rule, and have the link
> generate the fancy version only if rewrite rules are being used, etc.

I'm not really concerned about the URI looking pretty, just that the end
user doesn't have to do anything to make the page appear.

Is there a full list of hooks around?  I couldn't find anything to do
with wp_list_pages on the Codex ... or does every function that returns
output have a filter/hook attached to it?

--
Garett
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Dave Cohen-2

> I'm not really concerned about the URI looking pretty, just that the
> end user doesn't have to do anything to make the page appear.
http://wphooks.flatearth.org/
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Dave Cohen-2
In reply to this post by Garett Harnish
Oops, meant to reply to this:

Garett Harnish wrote:
> Is there a full list of hooks around?  I couldn't find anything to do
> with wp_list_pages on the Codex ... or does every function that
> returns output have a filter/hook attached to it?

http://wphooks.flatearth.org/
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Garett Harnish
Dave Cohen wrote:
> Oops, meant to reply to this:
>
> Garett Harnish wrote:
>> Is there a full list of hooks around?  I couldn't find anything to do
>> with wp_list_pages on the Codex ... or does every function that
>> returns output have a filter/hook attached to it?
>
> http://wphooks.flatearth.org/

Excellent.  Exactly what I was looking for.  Thanks.

--
Garett
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

David House
In reply to this post by Mark Jaquith
On 28/02/06, Mark Jaquith <[hidden email]> wrote:
> There's a wp_list_pages hook, but it operates on the text output of
> the entire function.  What I'd like eventually is to have
> wp_list_pages pass a hierarchial array through a different filter
> first, so you could use simple array manipulation to insert your
> stuff, instead of search/replace.

http://trac.wordpress.org/ticket/2328

Does it for cats, a simple analogous patch would do well here.

--
-David House, [hidden email], http://xmouse.ithium.net
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers
Reply | Threaded
Open this post in threaded view
|

Re: Need A Hook (or advice)

Ryan Boren
David House wrote:

> On 28/02/06, Mark Jaquith <[hidden email]> wrote:
>
>>There's a wp_list_pages hook, but it operates on the text output of
>>the entire function.  What I'd like eventually is to have
>>wp_list_pages pass a hierarchial array through a different filter
>>first, so you could use simple array manipulation to insert your
>>stuff, instead of search/replace.
>
>
> http://trac.wordpress.org/ticket/2328
>
> Does it for cats, a simple analogous patch would do well here.

I've been cleaning up the wp_list_*() and wp_dropdown_*() template
functions in trunk.  While we're in there, we can add filters for the
array of arguments passed to these functions, the array of
categories/pages returned from the query, and whatever other filters may
be useful.  We could even allow changing the callbacks passed to the
tree walker.

Ryan
_______________________________________________
wp-hackers mailing list
[hidden email]
http://lists.automattic.com/mailman/listinfo/wp-hackers