Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

this is what im doing... In BuddyPress, before delete user account, if a user has attachments previously uploaded, he or she will be redirected to their own attachments list:

function custom_get_count_before_delete() {

    global $bp, $wpdb;

    $user_id = $bp->loggedin_user->id;

    return $wpdb->get_var( $wpdb->prepare( "
      SELECT COUNT(DISTINCT p.ID) 
        FROM $wpdb->posts p 
        WHERE p.post_author = %d 
          AND p.post_status = 'inherit' 
          AND p.post_type = 'attachment'", $user_id
    ) );

}


function custom_check_delete_account () {

    global $bp;

    if ( $bp->current_component == 'settings' && $bp->current_action == 'delete-account' ) {

        if ( $count = custom_get_count_before_delete() ) {

            wp_redirect('http://www.mysite.lh/wp-admin/upload.php', 301 ); exit;

        }

    }


}

add_action('init', 'custom_check_delete_account', 11);

My question is: How do I set or inject a message or warning message before to redirect and print it after redirect on the "/wp-admin/upload.php" list of attachments?

Thanks in advance.

share|improve this question
    
Try setting message var `mysite.lh/wp-admin/upload.php?message=YOUR_MESSAGE –  Bainternet Jun 9 '11 at 7:41
    
Thanks. I just did it but doesnt print or display any message. Theres some error or message class or something to set before redirect? –  José Pablo Orozco Marín Jun 9 '11 at 13:07
    
Message query var display warnings with values ?message=1, ?message=2 or ?message=3 but not with a custom string. –  José Pablo Orozco Marín Jun 9 '11 at 14:01
add comment

1 Answer

up vote 0 down vote accepted

I got it:

function custom_get_count_before_delete() {

    global $bp, $wpdb;

    $user_id = $bp->loggedin_user->id;

    return $wpdb->get_var( $wpdb->prepare( "
      SELECT COUNT(DISTINCT p.ID) 
        FROM $wpdb->posts p 
        WHERE p.post_author = %d 
          AND p.post_status = 'inherit' 
          AND p.post_type = 'attachment'", $user_id
    ) );

}


function custom_check_delete_account() {

    global $bp;

    if ( $bp->current_component == 'settings' && $bp->current_action == 'delete-account' ) {

        if ( $count = custom_get_count_before_delete() ) {

            $message = 'please_delete_your_media_before_delete_your_account';

            wp_redirect('http://www.mysite.lh/wp-admin/upload.php?message=' . $message, 301 ); 

            exit;

        }

    }


}

add_action('init', 'custom_check_delete_account', 11);


function custom_upload_notice() {

    echo '<div id="message" class="updated below-h2">
       <h2>Primer paso:</h2><p>Para borrar su cuenta, por favor borre todos sus Chaines primero.</p>
    </div>';

    remove_action('admin_notices', 'custom_upload_notice');

}


function custom_check_delete_account_upload() {

    global $pagenow;

    if ( !isset($_REQUEST['deleted']) ) {

        if ( 'please_delete_your_media_before_delete_your_account' == $_REQUEST['message'] && 'upload.php' == $pagenow ) {

            add_action('admin_notices', 'custom_upload_notice');

        }

    }

}

add_action('admin_init', 'custom_check_delete_account_upload', 11);

Please let me know what you think or if there exist a better way to do it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.