php - Delete Buddypress Cover Image Button -


i trying have button on users profile > cover image page says "remove cover image". theme using template override of cover image seen here: http://pastebin.com/xqppivys

i know buddypress has option once user has uploaded cover image, option delete available after upload how can add button in allows them delete cover photo @ anytime instead of directly after upload?

i know dont want edit core found action responsible this. there way can create button call action , remove users cover photo?

in buddypress/bp-core/bp-core-attachments.php:

/**  * ajax delete cover image given object , item id.  *  * @since 2.4.0  *  * @return string|null json object containing success data if cover image deleted  *                     error message otherwise.  */ function bp_attachments_cover_image_ajax_delete() {     // bail if not post action.     if ( 'post' !== strtoupper( $_server['request_method'] ) ) {         wp_send_json_error();     }      $cover_image_data = $_post;      if ( empty( $cover_image_data['object'] ) || empty( $cover_image_data['item_id'] ) ) {         wp_send_json_error();     }      // check nonce     check_admin_referer( 'bp_delete_cover_image', 'nonce' );      // capability check     if ( ! bp_attachments_current_user_can( 'edit_cover_image', $cover_image_data ) ) {         wp_send_json_error();     }      // set object user's case     if ( 'user' === $cover_image_data['object'] ) {         $component = 'xprofile';         $dir       = 'members';      // set other cases     } else {         $component = $cover_image_data['object'] . 's';         $dir       = $component;     }      // handle delete     if ( bp_attachments_delete_file( array( 'item_id' => $cover_image_data['item_id'], 'object_dir' => $dir, 'type' => 'cover-image' ) ) ) {          // defaults no cover image         $response = array(             'reset_url'     => '',             'feedback_code' => 3 ,         );          // cover image settings in case there's default header         $cover_params = bp_attachments_get_cover_image_settings( $component );          // check if there's default cover         if ( ! empty( $cover_params['default_cover'] ) ) {             $response['reset_url'] = $cover_params['default_cover'];         }          // send reset url         wp_send_json_success( $response );      } else {         wp_send_json_error( array(             'feedback_code' => 2,         ) );     } } add_action( 'wp_ajax_bp_cover_image_delete', 'bp_attachments_cover_image_ajax_delete' ); 

and lastly know cover images stored in members/{id}/cover-image/ folder, worse case scenario when click button grabs user id , deletes appropriate file or directory?

i got started. works , can modified , built suit worked me:

<?php  $id = get_current_user_id(); if(isset($_get['delete'])){     $filefull = 'coverphoto-full.jpg';     $filethumb = 'coverphoto-thumb.jpg';     $upload_dir = wp_upload_dir();     $user_dirname = $upload_dir['basedir'].'/avatars/'.$id.'/';     unlink($user_dirname . $filefull);     unlink($user_dirname . $filethumb); }  ?> <a href="?delete=<?php echo $id; ?>" onclick="return confirm('are sure?')">delete cover image</a> 

note: have template on ride cover images stored in uploads/avatars/{id}/coverphoto-full.jpg. average bp user $user_dirname filepath may need change buddypress/members/{id}/cover-image/... or variant of that.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -