Home Forums Plugin Support WP Project Manager Pro Problem with action override

This topic is: resolved

This topic contains 12 replies, has 2 voices, and was last updated by  Tareq Hasan 6 years, 1 month ago.

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #3535

    kpodemski
    Participant
    Post count: 10

    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?

    #3585

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #3650

    kpodemski
    Participant
    Post count: 10

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

    #3680

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #3681

    kpodemski
    Participant
    Post count: 10

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

    #3726

    kpodemski
    Participant
    Post count: 10

    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…

    #3729

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #3731

    kpodemski
    Participant
    Post count: 10

    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.

    #3733

    Tareq Hasan
    Keymaster
    Post count: 2831

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

    #3735

    kpodemski
    Participant
    Post count: 10

    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.

    #3736

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #3737

    kpodemski
    Participant
    Post count: 10

    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

    #3738

    Tareq Hasan
    Keymaster
    Post count: 2831

    Also take a look here

Viewing 13 posts - 1 through 13 (of 13 total)

The topic ‘Problem with action override’ is closed to new replies.