[wp-hackers] On slug change, do something

Haluk Karamete halukkaramete at gmail.com
Tue Jul 30 20:59:52 UTC 2013


Thank you Nicholas,

Whenever I need to write a hook, I always get confused as to how many args
I can pass to my hooked function from the core.
And in edit_terms, I faced that too.
For this very issue, codex has this;

To find out the number and name of arguments for an action, simply search
> the code base for the matching do_action() call. For example, if you are
> hooking into 'save_post', you would find it in post.php:
> <?php do_action( 'save_post', $post_ID, $post ); ?>
>
> Your add_action call would look like:
> <?php add_action( 'save_post', 'my_save_post', 10, 2 ); ?>
> And your function would be:
> function my_save_post( $post_ID, $post )
> {
> // do stuff here
> }


so from that, it looks easy. But when I locate the code in the core,
reaching a final conclusion is hard;

as this URI ( http://adambrown.info/p/wp_hooks/hook/save_post ) demonstrates
that there are just too many occurrences and in one instance save_post gets
to be used with one arg (
http://adambrown.info/p/wp_hooks/hook/save_post?version=2.0&file=wp-includes/functions-post.php
 )

edit_terms is another good example to illustrate this frustration;

I searched the core, in one instance, the core uses it as

do_action("edit_term", $term_id, $tt_id);


and in another instance, as

do_action("edit_term", $term_id, $tt_id, $taxonomy);


as you see, in the former, the action takes 2 args whereas in the latter
does it with 3.

Now the question becomes do I need to check all occurrences of the
"do_action edit_terms" in the core to find out what's available in the most
detailed case, otherwise it's a hit and miss?

for example, if I were to only spot do_action("edit_term", $term_id,
$tt_id), then how would I have know that it is also possible to get the 3rd
arg as $taxonomy?

So I write my own function ( the do_something function below), how will I
know how many args available to me from the core?

add_action( 'edit_terms', 'do_something' );

function do_something($var1,$var2,$var3,,,,$varN){
}

do you see what I mean?



On Tue, Jul 30, 2013 at 7:41 AM, Nicholas Ciske <nl at thoughtrefinery.com>wrote:

>
> permalink_structure_changed fires when the permalink structure is changed
> on the Settings page -- not when a slug is updated.
>
> You're probably looking for the edit_terms action which fires just before
> the term slug is updated (keep in mind that one term can be in multiple
> taxonomies). This gets run in wp_update_term() in wp-includes/taxonomy.php.
>
> This triggers every time a term is updated, you'll need to write some code
> to determine if the slug has actually changed or not.
>
> _________________________
> Nick Ciske
> http://thoughtrefinery.com/
> @nciske
>
> On Jul 29, 2013, at 9:44 PM, Haluk Karamete wrote:
>
> > I'd like to hook into the event when a tag slug changes, I can fire an
> > action - for the sake of simplicity, let's say, I want to send en email
> > when a tag slug is modified.
> >
> > I tried the  following piece of code but that did not do the trick. I'm
> > curious to know what is it that I need to do?
> >
> > add_action("permalink_structure_changed","do_something");
> >
> > function do_something($data){
> >
> > wp_mail( 'an_email_address_here', 'subject_here', 'some text here');
> > }
> >
> >
> > To try this, I changed the slug of a post_tag, but no email was fired.
> > I also tried changing the permalink of a post, that did not fired an
> email
> > neither.
> >
> > What's the hook to tap into when a slug is changed? I'm particularly
> > interested in post_tag slugs change,
> >
> > Thanks
>
> _______________________________________________
> 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