Problem with action override

This topic contains 12 reply and 2 voices, and was last updated by Tareq Hasan 10 years, 11 months ago
Viewing 12 Posts - 1 through 12 (of 12 total)
Author Posts
May 13, 2013 at 8:17 am 3535
Tareq Hasan Hi, First of all - that is great plugin. I have a problem with add_action... I want to send e-mail to administrator when task is added without anybody in assign. My code:
function my_task_new( $list_id, $task_id, $data ) {

		 $project_id = intval( $_POST['project_id'] );

        //notification is not selected or no one is assigned
        if ( $_POST['task_assign'] == '-1' ) {
        	$to = get_bloginfo( 'admin_email' );
            $user = wp_get_current_user();
        }
        else
        {
        	$user = get_user_by( 'id', intval( $_POST['task_assign'] ) );
        	$to = sprintf( '%s <%s>', $user->display_name, $user->user_email );
        }
       
        $template_vars = array(
            '%SITE%' => wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES ), 
            '%PROJECT_NAME%' => get_post_field( 'post_title', $project_id ),
            '%PROJECT_URL%' => cpm_url_project_details( $project_id ),
            '%AUTHOR%' => $user->display_name,
            '%AUTHOR_EMAIL%' => $user->user_email,
            '%TASKLIST_URL%' => cpm_url_single_tasklist($project_id, $list_id),
            '%TASK_URL%' => cpm_url_single_task( $project_id, $list_id, $task_id ),
            '%TASK%' => $data['post_content'],
            '%IP%' => get_ipaddress()
        );

        $subject = cpm_get_option( 'new_task_sub' );
        $message = cpm_get_option( 'new_task_body' );

        // subject
        foreach ($template_vars as $key => $value) {
            $subject = str_replace( $key, $value, $subject );
        }

        // message
        foreach ($template_vars as $key => $value) {
            $message = str_replace( $key, $value, $message );
        }

        CPM_Notification::send( $to, $subject, $message );
    }

remove_action('cpm_task_new', array('CPM_Notification', 'new_task'), 10, 3);
add_action('cpm_task_new', 'my_task_new', 10, 3);
The problem is that the mail reaches two times. How I can fix that?
May 14, 2013 at 7:58 am 3585
Tareq Hasan Tareq Hasan

Are you sure this mail reaches twice? It shouldn’t, otherwise the default mail also should be sent twice.

May 15, 2013 at 12:05 pm 3650
kpodemski kpodemski

Unfortunately, after adding the add_action all messages reach several times.

May 15, 2013 at 3:06 pm 3680
Tareq Hasan Tareq Hasan

Thats really weird, every hooks should be fired only once.

May 15, 2013 at 3:48 pm 3681
kpodemski kpodemski

Yep, my goal is to have e-mail to blog admin after every action, after add task, after add comment etc.

May 16, 2013 at 9:41 pm 3726
kpodemski kpodemski

You could look at it? Unfortunately, for some reason, the action is called twice, and I do not want to make changes directly in your code and then lose them after the update…

May 16, 2013 at 9:49 pm 3729
Tareq Hasan Tareq Hasan

Haven’t found the time yet, my be try not using the CPM_Notification::send( $to, $subject, $message );, use a simple wp_mail function and see what happens.

May 16, 2013 at 10:08 pm 3731
kpodemski kpodemski

Ok, I test & changed the subject in its my overwritten function that uses like you handled wp_mail…

The conclusion is that they are sending two emails, the first being sent my way, and your second.

Looks like the WordPress doesn’t remove action and my action is second added to same hook 🙁

!!!UPDATE!!!

I get it!

Instead of remove_action I use that function: https://github.com/herewithme/wp-filters-extras/

First example working fine.

May 16, 2013 at 10:14 pm 3733
Tareq Hasan Tareq Hasan

Try increasing or decreasing the priority of the remove action hook.

May 16, 2013 at 10:23 pm 3735
kpodemski kpodemski

Unfortunately, another problem is that after edit project even selected the “Notify collaborators” added the co-worker does not receive notification with link to project etc.

I see there is no function for “cpm_project_update” hook, of course I’m going to add that function by myself but I think is must have for next version of plugin.

May 16, 2013 at 10:28 pm 3736
Tareq Hasan Tareq Hasan

Why don’t you fork the plugin in github and send a pull request? Also if you think there should be some features in the plugin, feel free to contribute.

May 16, 2013 at 10:36 pm 3737
kpodemski kpodemski

Yep, I’ll do it as soon as I finish my code that improves your plugin.

The elements to be added in my version:
– notification to specific e-mail after every action in plugin
– possible to attach FTP, MySQL and other “significant” datas to project with two way encryption using Blowfish (for specific users only)
– possible to assign messages, files to specific user – more advanced rights manage

May 16, 2013 at 10:41 pm 3738
Tareq Hasan Tareq Hasan

Also take a look here

Viewing 12 Posts - 1 through 12 (of 12 total)