I figured it out! the problem is the path is not right! Thanks to this post : Alow users to delete uploaded images inside backend?
this function below helped :
function url_to_path_test($url){
$url=str_replace(rtrim(get_site_url(),"https://wordpress.stackexchange.com/")."https://wordpress.stackexchange.com/", ABSPATH, $url);
return $url;
}
So in my code if you change the remove previous image like this it will work :
//remove previous uploaded file
$author_profile_photo = get_author_profile_photo($user_id);
$url=str_replace(rtrim(get_site_url(),"https://wordpress.stackexchange.com/")."https://wordpress.stackexchange.com/", ABSPATH, $author_profile_photo["file"]);
@unlink($url);
Related Posts:
- Using media-upload.php to upload mp3 via custom fields
- Extend WP Customizer to make multiple image selection possible
- Saving Custom Field in Attachment Window in WordPress 3.5
- WordPress custom upload field error
- limit amount of photos uploaded per cpt post
- Metabox with multiple fields added by user and upload box
- Metabox image upload and custom field
- Custom image sizes for custom field media uploads
- wp_handle_upload error “Specified file failed upload test” but still creates attachment?
- Insert attachment ID in custom field from media uploader
- How to save media files under custom folder without changing wp-config.php or changing media settings
- How can I store a file in the database in the same way WordPress and ACF do?
- How do i save and retrieve custom attachment meta?
- Is there a simpler version of WP Media?
- Client PDF Upload (Catalogue) – Automatically update link to PDF
- How to add upload video option in wordpress for user?
- Uploading PDF using Media Uploader
- Select multiple images from custom field
- WordPress Media Uploader custom Javascript not working
- How to use media upload on metabox post page without breaking TinyMCE?
- Front-End User Profile
- Image upload and path to custom field
- How to delete file uploaded by Plupload
- Problem uploading different files as custom fields with front end post form
- How do I upload file through custom field, save it to database and get it
- Can you generate a featured image from two images from custom fields?
- want to add video upload option for front end user
- display custom media folders to wordpress media popup
- Custom Meta Boxes and Fields for WordPress: Change directory upload based on user-edit page
- Change path to child of page when uploading image via custom field
- How can I create more “create attachment” custom field – any idea?
- Upload image to wordpress
- Multiple image uploader under editor?
- Save Custom Meta Value on Media Upload
- Custom post meta field effect on the performance on the post
- Having different sidebar content for MANY pages?
- How can I fetch CSS from JSON WP REST API response
- How to set a default meta value for custom field
- How To Create a Metabox of HTML Content with Instructions For Editors When Editing a Post or Page?
- Plugins won’t recognize my plugin’s hidden custom fields
- wp_editor in add_meta_boxes does not show gallery
- Calling Specific Pages with wp query Part II
- How do I assign this filter to a variable? (Appending php & markup to the_content)
- If value present, order posts by two consecutive custom fields
- Copying Custom Meta Values from existing post to a duplicate post
- Save page data to an xml file
- List posts with common custom field value
- Create Posts using Import>RSS/WXR/XML and pass values to Custom Fields
- Best way to add custom / magic / flutter fields into RSS feed
- Importing users to Buddypress with custom fields
- How to save a ToggleControl value in a meta field?
- How to get customfield value by woocommerce product ID
- How do I get the url slug inside the dashboard for a custom post type?
- How do I use Ajax to build a dropdown of custom fields based on a post selected in previous dropdown?
- Register rest field for specific user
- Custom Field Suite A little problem
- Audio player shortcode not showing up when using variable
- Save the_content into custom field
- how to upload a image from frontend with wp_insert_post and also update_post_meta?
- Insert a custom field into a shortcode and use it in post(s)
- Sort alphabetically by custom field
- Why orderbyb meta_value_num won’t affect the generated SQL Query order?
- Sorting editor screen items
- get post id using custom filed value
- How Do I Display A Custom Field In The Sidebar Of All My Pages?
- Query_posts with custom field meta value
- Passing meta_box string to post__in?
- Can data from a Custom Field data be used by a shortcode on a per page/post basis?
- How can I modify RSS item titles to be either the title or a custom meta field?
- Move Title and the Content WYSIWYG editor position
- WordPress built in custom fields don’t validate or sanitize? Is there a way to fix this?
- wp custom field date format compare
- frontend submit post jQuery clone row won’t save
- WordPress colorpicker save both hex and RGB
- Can’t get video meta from wp_read_video_metadata()
- Best way to contruct a global custom field?
- Include one custom field in search results
- Custom search SQL Query to add custom field in result
- How to write specific HTML code with a specific custom field? [closed]
- How to style posts selecting a CSS post_class (added through custom_fields?)?
- Can wp_insert_post_data filter be used to save custom field data?
- Meta query relation ‘OR’ not working as expected
- How to hide custom fields added by a plugin?
- Create a new custom field for all posts based on current custom field
- Need to search a custom field (ingredients, one long string per post), but want it to allow phrases/non-exact matches
- Listing posts with a value in a custom field
- Using Customizer API vs Custom Meta Box for custom content
- WordPress admin area: select box with 12.000+ options
- Custom meta boxes – add php code inside?
- to create a custom post type with additionnal url field such as link to social network and an email field
- User custom meta delete by serialised key value
- Metabox value for post loop?
- Using ACF Custom Field value in a URL with do_shortcode() [closed]
- Register author, facebook connect, publish posts from front end
- Custom field and category query
- Empty the_content for all posts
- Display different category template if custom field is checked
- Custom Search, MySql Query Gone Wrong?
- Extract array from custom field
- extra post fields for url + youtube video / implementation