Function Reference: geodirectory_before_featured_image_delete
Summary
temp function to delete media post.
Global Values
- $wpdb
- (object) (required) WordPress Database object.
- Default: None
- $plugin_prefix
- (string) (required) Geodirectory plugin table prefix.
- Default: None
Package
GeoDirectory
Parameters
- $attachment_id
- (int) (required) Attachment ID.
- Default: None
Return Values
- (bool|void)
- Returns false on failure.
Change Log
Since: 1.0.0
Source File
geodirectory_before_featured_image_delete() is located in geodirectory_hooks_actions.php [Line: 2191]
Source Code
function geodirectory_before_featured_image_delete($attachment_id) { global $wpdb, $plugin_prefix; $post_id = get_post_field('post_parent', $attachment_id); $attachment_url = wp_get_attachment_url($attachment_id); if ($post_id > 0 && (isset($_REQUEST['action']) && $_REQUEST['action'] == 'delete')) { $post_type = get_post_type($post_id); $all_postypes = geodir_get_posttypes(); if (!in_array($post_type, $all_postypes) || !is_admin()) return false; $uploads = wp_upload_dir(); $split_img_path = explode($uploads['baseurl'], $attachment_url); $split_img_file_path = isset($split_img_path[1]) ? $split_img_path[1] : ''; $wpdb->query( $wpdb->prepare("DELETE FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id = %d AND file=%s ", array($post_id, $split_img_file_path) ) ); $attachment_data = $wpdb->get_row( $wpdb->prepare("SELECT ID, MIN(`menu_order`) FROM " . GEODIR_ATTACHMENT_TABLE . " WHERE post_id=%d", array($post_id) ) ); if (!empty($attachment_data)) { $wpdb->query("UPDATE " . GEODIR_ATTACHMENT_TABLE . " SET menu_order=1 WHERE ID=" . $attachment_data->ID); } $table_name = $plugin_prefix . $post_type . '_detail'; $wpdb->query("UPDATE " . $table_name . " SET featured_image='' WHERE post_id =" . $post_id); geodir_set_wp_featured_image($post_id); } }