[wp-hackers] Avoiding Side-effects in Filters & Actions (was:
Dispay none for different categories)
Mike Schinkel
mikeschinkel at newclarity.net
Wed Mar 25 19:53:19 GMT 2009
Gerhard:
Thanks for noting that.
That brings up a question I have for the list. WordPress' filter and action hooks are incredibly flexible but can also result in far too easy creation of unexpected and side effects. I've numerous times made a change using a filter only to find out that it "broke" something in a completely different part of the site and of course those breakages are usually found by the client and then they get frustrated with me for breaking "that which already works" and ask me "why were you working on that part when you were supposed to be working on this other part?" And in the case of releasing a general purpose plugin, such side-effects can cause a real nightmare for end-users of the plugin.
Is there a more robust way to pinpoint and isolate these kind of changes? I've reverted to testing the URLs via $_SERVER['REQUEST_URI'] but that just doesn't feel very robust, and in the case of a widget isn't even a solution. How do you guys address these issues, and is there even a good way to do so?
-Mike Schinkel
Custom Wordpress Plugins
http://mikeschinkel.com/custom-wordpress-plugins
----- Original Message -----
From: "Gerhard Brauckmann" <Gerhard.Brauckmann at mi-verlag.de>
To: wp-hackers at lists.automattic.com
Sent: Wednesday, March 25, 2009 9:18:19 AM GMT -05:00 US/Canada Eastern
Subject: Antwort: Re: [wp-hackers] Dispay none for different categories
Mike, Frank,
yepp there are side effects. The main "category" management page is
affected with this filter. (categories.php)
regards
Gerhard
_____________________________________________
Mike Schinkel <mikeschinkel at newclarity.net>
Gesendet von: wp-hackers-bounces at lists.automattic.com
25.03.2009 08:03
Bitte antworten an
wp-hackers at lists.automattic.com
An
wp-hackers at lists.automattic.com
Kopie
Thema
Re: [wp-hackers] Dispay none for different categories
Frank:
I'm still not 100% sure exactly what you want since you didn't get
examples of categories, but I think the following *might* give you what
you need. I tested it in the templates functions.php file but it will
likely work the same in a plugin. I used a hypothetical addition to the
were clause that limits to categories with the slugs 'news', 'charity',
and 'events':
add_filter('list_terms_exclusions','my_list_terms_exclusions');
function my_list_terms_exclusions($args) {
$where = " AND t.slug IN ('news','charity','events')";
return $where;
}
This is the SQL statement that it is adding to the WHERE clause:
SELECT
t.term_id,
t.name,
t.slug,
t.term_group,
tt.term_taxonomy_id,
tt.term_id,
tt.taxonomy,
tt.description,
tt.parent,
tt.count
FROM
wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE
tt.taxonomy IN ('category') AND
tt.count > 0
Thus the SQL statement will look conceptually like this when the above
filter is in place:
SELECT
t.term_id,
t.name,
t.slug,
t.term_group,
tt.term_taxonomy_id,
tt.term_id,
tt.taxonomy,
tt.description,
tt.parent,
tt.count
FROM
wp_terms AS t
INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id
WHERE
tt.taxonomy IN ('category') AND
tt.count > 0 AND
t.slug IN ('news','charity','events')
Of course that filter might cause unexpected side effects elsewhere so
you'll need to test it throughout and also you might need to ensure that
the action is only called where it is needed.
Let me know if this is actually what you needed or if not please explain
why not and give some examples of what you'd want to see.
Hope this helps.
-Mike Schinkel
http://mikeschinkel.com/
----- Original Message -----
From: "Frank Bueltge" <frank at bueltge.de>
To: wp-hackers at lists.automattic.com
Sent: Tuesday, March 24, 2009 5:04:02 PM GMT -05:00 US/Canada Eastern
Subject: Re: [wp-hackers] Dispay none for different categories
Soory for my bad english.
On the post-page in admin, the meta box category list all categories with
wp_category_checklist().
I will exclude several categories on this list. All categories have an id
and a class, so it is possible exclude with javascipt or css. I will
exlude
several categories in the select-query of wp_category_checklist().
Thanks a lot
On Tue, Mar 24, 2009 at 6:32 PM, Mike Schinkel
<mikeschinkel at newclarity.net>wrote:
> Frank:
>
> I'm not clear on what you are trying to do exactly. Can you explain it
> differently?
>
> -Mike Schinkel
> http://mikeschinkel.com/
>
> ----- Original Message -----
> From: "Frank Bueltge" <frank at bueltge.de>
> To: wp-hackers at lists.automattic.com
> Sent: Tuesday, March 24, 2009 7:51:05 AM GMT -05:00 US/Canada Eastern
> Subject: [wp-hackers] Dispay none for different categories
>
> Hello,
>
> any one have a idea?
> I will display none for a categories in edit post on admin-area.
> I have not found a hook for the select and think, it is possible to
display
> none with css or javascript an load admin.
> A this is not ao easy for a users with many categories in wordpress.
>
> It is possible to hook an the meta box for categories and reduce the
select
> for categories ind the meta box on edit post?
>
> Thanks for your ideas
> Best regards
> Frank
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers
_______________________________________________
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