Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/clone/wp-inclu...
File: post.php
*
[6000] Fix | Delete
* $children contains parent-children relations
[6001] Fix | Delete
*
[6002] Fix | Delete
* @since 2.9.0
[6003] Fix | Delete
* @access private
[6004] Fix | Delete
*
[6005] Fix | Delete
* @see _page_traverse_name()
[6006] Fix | Delete
*
[6007] Fix | Delete
* @param int $page_id Page ID.
[6008] Fix | Delete
* @param array $children Parent-children relations (passed by reference).
[6009] Fix | Delete
* @param string[] $result Array of page names keyed by ID (passed by reference).
[6010] Fix | Delete
*/
[6011] Fix | Delete
function _page_traverse_name( $page_id, &$children, &$result ) {
[6012] Fix | Delete
if ( isset( $children[ $page_id ] ) ) {
[6013] Fix | Delete
foreach ( (array) $children[ $page_id ] as $child ) {
[6014] Fix | Delete
$result[ $child->ID ] = $child->post_name;
[6015] Fix | Delete
_page_traverse_name( $child->ID, $children, $result );
[6016] Fix | Delete
}
[6017] Fix | Delete
}
[6018] Fix | Delete
}
[6019] Fix | Delete
[6020] Fix | Delete
/**
[6021] Fix | Delete
* Builds the URI path for a page.
[6022] Fix | Delete
*
[6023] Fix | Delete
* Sub pages will be in the "directory" under the parent page post name.
[6024] Fix | Delete
*
[6025] Fix | Delete
* @since 1.5.0
[6026] Fix | Delete
* @since 4.6.0 The `$page` parameter was made optional.
[6027] Fix | Delete
*
[6028] Fix | Delete
* @param WP_Post|object|int $page Optional. Page ID or WP_Post object. Default is global $post.
[6029] Fix | Delete
* @return string|false Page URI, false on error.
[6030] Fix | Delete
*/
[6031] Fix | Delete
function get_page_uri( $page = 0 ) {
[6032] Fix | Delete
if ( ! $page instanceof WP_Post ) {
[6033] Fix | Delete
$page = get_post( $page );
[6034] Fix | Delete
}
[6035] Fix | Delete
[6036] Fix | Delete
if ( ! $page ) {
[6037] Fix | Delete
return false;
[6038] Fix | Delete
}
[6039] Fix | Delete
[6040] Fix | Delete
$uri = $page->post_name;
[6041] Fix | Delete
[6042] Fix | Delete
foreach ( $page->ancestors as $parent ) {
[6043] Fix | Delete
$parent = get_post( $parent );
[6044] Fix | Delete
if ( $parent && $parent->post_name ) {
[6045] Fix | Delete
$uri = $parent->post_name . '/' . $uri;
[6046] Fix | Delete
}
[6047] Fix | Delete
}
[6048] Fix | Delete
[6049] Fix | Delete
/**
[6050] Fix | Delete
* Filters the URI for a page.
[6051] Fix | Delete
*
[6052] Fix | Delete
* @since 4.4.0
[6053] Fix | Delete
*
[6054] Fix | Delete
* @param string $uri Page URI.
[6055] Fix | Delete
* @param WP_Post $page Page object.
[6056] Fix | Delete
*/
[6057] Fix | Delete
return apply_filters( 'get_page_uri', $uri, $page );
[6058] Fix | Delete
}
[6059] Fix | Delete
[6060] Fix | Delete
/**
[6061] Fix | Delete
* Retrieves an array of pages (or hierarchical post type items).
[6062] Fix | Delete
*
[6063] Fix | Delete
* @since 1.5.0
[6064] Fix | Delete
* @since 6.3.0 Use WP_Query internally.
[6065] Fix | Delete
*
[6066] Fix | Delete
* @param array|string $args {
[6067] Fix | Delete
* Optional. Array or string of arguments to retrieve pages.
[6068] Fix | Delete
*
[6069] Fix | Delete
* @type int $child_of Page ID to return child and grandchild pages of. Note: The value
[6070] Fix | Delete
* of `$hierarchical` has no bearing on whether `$child_of` returns
[6071] Fix | Delete
* hierarchical results. Default 0, or no restriction.
[6072] Fix | Delete
* @type string $sort_order How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'.
[6073] Fix | Delete
* @type string $sort_column What columns to sort pages by, comma-separated. Accepts 'post_author',
[6074] Fix | Delete
* 'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order',
[6075] Fix | Delete
* 'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'.
[6076] Fix | Delete
* 'post_' can be omitted for any values that start with it.
[6077] Fix | Delete
* Default 'post_title'.
[6078] Fix | Delete
* @type bool $hierarchical Whether to return pages hierarchically. If false in conjunction with
[6079] Fix | Delete
* `$child_of` also being false, both arguments will be disregarded.
[6080] Fix | Delete
* Default true.
[6081] Fix | Delete
* @type int[] $exclude Array of page IDs to exclude. Default empty array.
[6082] Fix | Delete
* @type int[] $include Array of page IDs to include. Cannot be used with `$child_of`,
[6083] Fix | Delete
* `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`.
[6084] Fix | Delete
* Default empty array.
[6085] Fix | Delete
* @type string $meta_key Only include pages with this meta key. Default empty.
[6086] Fix | Delete
* @type string $meta_value Only include pages with this meta value. Requires `$meta_key`.
[6087] Fix | Delete
* Default empty.
[6088] Fix | Delete
* @type string $authors A comma-separated list of author IDs. Default empty.
[6089] Fix | Delete
* @type int $parent Page ID to return direct children of. Default -1, or no restriction.
[6090] Fix | Delete
* @type string|int[] $exclude_tree Comma-separated string or array of page IDs to exclude.
[6091] Fix | Delete
* Default empty array.
[6092] Fix | Delete
* @type int $number The number of pages to return. Default 0, or all pages.
[6093] Fix | Delete
* @type int $offset The number of pages to skip before returning. Requires `$number`.
[6094] Fix | Delete
* Default 0.
[6095] Fix | Delete
* @type string $post_type The post type to query. Default 'page'.
[6096] Fix | Delete
* @type string|array $post_status A comma-separated list or array of post statuses to include.
[6097] Fix | Delete
* Default 'publish'.
[6098] Fix | Delete
* }
[6099] Fix | Delete
* @return WP_Post[]|false Array of pages (or hierarchical post type items). Boolean false if the
[6100] Fix | Delete
* specified post type is not hierarchical or the specified status is not
[6101] Fix | Delete
* supported by the post type.
[6102] Fix | Delete
*/
[6103] Fix | Delete
function get_pages( $args = array() ) {
[6104] Fix | Delete
$defaults = array(
[6105] Fix | Delete
'child_of' => 0,
[6106] Fix | Delete
'sort_order' => 'ASC',
[6107] Fix | Delete
'sort_column' => 'post_title',
[6108] Fix | Delete
'hierarchical' => 1,
[6109] Fix | Delete
'exclude' => array(),
[6110] Fix | Delete
'include' => array(),
[6111] Fix | Delete
'meta_key' => '',
[6112] Fix | Delete
'meta_value' => '',
[6113] Fix | Delete
'authors' => '',
[6114] Fix | Delete
'parent' => -1,
[6115] Fix | Delete
'exclude_tree' => array(),
[6116] Fix | Delete
'number' => '',
[6117] Fix | Delete
'offset' => 0,
[6118] Fix | Delete
'post_type' => 'page',
[6119] Fix | Delete
'post_status' => 'publish',
[6120] Fix | Delete
);
[6121] Fix | Delete
[6122] Fix | Delete
$parsed_args = wp_parse_args( $args, $defaults );
[6123] Fix | Delete
[6124] Fix | Delete
$number = (int) $parsed_args['number'];
[6125] Fix | Delete
$offset = (int) $parsed_args['offset'];
[6126] Fix | Delete
$child_of = (int) $parsed_args['child_of'];
[6127] Fix | Delete
$hierarchical = $parsed_args['hierarchical'];
[6128] Fix | Delete
$exclude = $parsed_args['exclude'];
[6129] Fix | Delete
$meta_key = $parsed_args['meta_key'];
[6130] Fix | Delete
$meta_value = $parsed_args['meta_value'];
[6131] Fix | Delete
$parent = $parsed_args['parent'];
[6132] Fix | Delete
$post_status = $parsed_args['post_status'];
[6133] Fix | Delete
[6134] Fix | Delete
// Make sure the post type is hierarchical.
[6135] Fix | Delete
$hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
[6136] Fix | Delete
if ( ! in_array( $parsed_args['post_type'], $hierarchical_post_types, true ) ) {
[6137] Fix | Delete
return false;
[6138] Fix | Delete
}
[6139] Fix | Delete
[6140] Fix | Delete
if ( $parent > 0 && ! $child_of ) {
[6141] Fix | Delete
$hierarchical = false;
[6142] Fix | Delete
}
[6143] Fix | Delete
[6144] Fix | Delete
// Make sure we have a valid post status.
[6145] Fix | Delete
if ( ! is_array( $post_status ) ) {
[6146] Fix | Delete
$post_status = explode( ',', $post_status );
[6147] Fix | Delete
}
[6148] Fix | Delete
if ( array_diff( $post_status, get_post_stati() ) ) {
[6149] Fix | Delete
return false;
[6150] Fix | Delete
}
[6151] Fix | Delete
[6152] Fix | Delete
$query_args = array(
[6153] Fix | Delete
'orderby' => 'post_title',
[6154] Fix | Delete
'order' => 'ASC',
[6155] Fix | Delete
'post__not_in' => wp_parse_id_list( $exclude ),
[6156] Fix | Delete
'meta_key' => $meta_key,
[6157] Fix | Delete
'meta_value' => $meta_value,
[6158] Fix | Delete
'posts_per_page' => -1,
[6159] Fix | Delete
'offset' => $offset,
[6160] Fix | Delete
'post_type' => $parsed_args['post_type'],
[6161] Fix | Delete
'post_status' => $post_status,
[6162] Fix | Delete
'update_post_term_cache' => false,
[6163] Fix | Delete
'update_post_meta_cache' => false,
[6164] Fix | Delete
'ignore_sticky_posts' => true,
[6165] Fix | Delete
'no_found_rows' => true,
[6166] Fix | Delete
);
[6167] Fix | Delete
[6168] Fix | Delete
if ( ! empty( $parsed_args['include'] ) ) {
[6169] Fix | Delete
$child_of = 0; // Ignore child_of, parent, exclude, meta_key, and meta_value params if using include.
[6170] Fix | Delete
$parent = -1;
[6171] Fix | Delete
unset( $query_args['post__not_in'], $query_args['meta_key'], $query_args['meta_value'] );
[6172] Fix | Delete
$hierarchical = false;
[6173] Fix | Delete
$query_args['post__in'] = wp_parse_id_list( $parsed_args['include'] );
[6174] Fix | Delete
}
[6175] Fix | Delete
[6176] Fix | Delete
if ( ! empty( $parsed_args['authors'] ) ) {
[6177] Fix | Delete
$post_authors = wp_parse_list( $parsed_args['authors'] );
[6178] Fix | Delete
[6179] Fix | Delete
if ( ! empty( $post_authors ) ) {
[6180] Fix | Delete
$query_args['author__in'] = array();
[6181] Fix | Delete
foreach ( $post_authors as $post_author ) {
[6182] Fix | Delete
// Do we have an author id or an author login?
[6183] Fix | Delete
if ( 0 == (int) $post_author ) {
[6184] Fix | Delete
$post_author = get_user_by( 'login', $post_author );
[6185] Fix | Delete
if ( empty( $post_author ) ) {
[6186] Fix | Delete
continue;
[6187] Fix | Delete
}
[6188] Fix | Delete
if ( empty( $post_author->ID ) ) {
[6189] Fix | Delete
continue;
[6190] Fix | Delete
}
[6191] Fix | Delete
$post_author = $post_author->ID;
[6192] Fix | Delete
}
[6193] Fix | Delete
$query_args['author__in'][] = (int) $post_author;
[6194] Fix | Delete
}
[6195] Fix | Delete
}
[6196] Fix | Delete
}
[6197] Fix | Delete
[6198] Fix | Delete
if ( is_array( $parent ) ) {
[6199] Fix | Delete
$post_parent__in = array_map( 'absint', (array) $parent );
[6200] Fix | Delete
if ( ! empty( $post_parent__in ) ) {
[6201] Fix | Delete
$query_args['post_parent__in'] = $post_parent__in;
[6202] Fix | Delete
}
[6203] Fix | Delete
} elseif ( $parent >= 0 ) {
[6204] Fix | Delete
$query_args['post_parent'] = $parent;
[6205] Fix | Delete
}
[6206] Fix | Delete
[6207] Fix | Delete
/*
[6208] Fix | Delete
* Maintain backward compatibility for `sort_column` key.
[6209] Fix | Delete
* Additionally to `WP_Query`, it has been supporting the `post_modified_gmt` field, so this logic will translate
[6210] Fix | Delete
* it to `post_modified` which should result in the same order given the two dates in the fields match.
[6211] Fix | Delete
*/
[6212] Fix | Delete
$orderby = wp_parse_list( $parsed_args['sort_column'] );
[6213] Fix | Delete
$orderby = array_map(
[6214] Fix | Delete
static function ( $orderby_field ) {
[6215] Fix | Delete
$orderby_field = trim( $orderby_field );
[6216] Fix | Delete
if ( 'post_modified_gmt' === $orderby_field || 'modified_gmt' === $orderby_field ) {
[6217] Fix | Delete
$orderby_field = str_replace( '_gmt', '', $orderby_field );
[6218] Fix | Delete
}
[6219] Fix | Delete
return $orderby_field;
[6220] Fix | Delete
},
[6221] Fix | Delete
$orderby
[6222] Fix | Delete
);
[6223] Fix | Delete
if ( $orderby ) {
[6224] Fix | Delete
$query_args['orderby'] = array_fill_keys( $orderby, $parsed_args['sort_order'] );
[6225] Fix | Delete
}
[6226] Fix | Delete
[6227] Fix | Delete
$order = $parsed_args['sort_order'];
[6228] Fix | Delete
if ( $order ) {
[6229] Fix | Delete
$query_args['order'] = $order;
[6230] Fix | Delete
}
[6231] Fix | Delete
[6232] Fix | Delete
if ( ! empty( $number ) ) {
[6233] Fix | Delete
$query_args['posts_per_page'] = $number;
[6234] Fix | Delete
}
[6235] Fix | Delete
[6236] Fix | Delete
/**
[6237] Fix | Delete
* Filters query arguments passed to WP_Query in get_pages.
[6238] Fix | Delete
*
[6239] Fix | Delete
* @since 6.3.0
[6240] Fix | Delete
*
[6241] Fix | Delete
* @param array $query_args Array of arguments passed to WP_Query.
[6242] Fix | Delete
* @param array $parsed_args Array of get_pages() arguments.
[6243] Fix | Delete
*/
[6244] Fix | Delete
$query_args = apply_filters( 'get_pages_query_args', $query_args, $parsed_args );
[6245] Fix | Delete
[6246] Fix | Delete
$pages = new WP_Query();
[6247] Fix | Delete
$pages = $pages->query( $query_args );
[6248] Fix | Delete
[6249] Fix | Delete
if ( $child_of || $hierarchical ) {
[6250] Fix | Delete
$pages = get_page_children( $child_of, $pages );
[6251] Fix | Delete
}
[6252] Fix | Delete
[6253] Fix | Delete
if ( ! empty( $parsed_args['exclude_tree'] ) ) {
[6254] Fix | Delete
$exclude = wp_parse_id_list( $parsed_args['exclude_tree'] );
[6255] Fix | Delete
foreach ( $exclude as $id ) {
[6256] Fix | Delete
$children = get_page_children( $id, $pages );
[6257] Fix | Delete
foreach ( $children as $child ) {
[6258] Fix | Delete
$exclude[] = $child->ID;
[6259] Fix | Delete
}
[6260] Fix | Delete
}
[6261] Fix | Delete
[6262] Fix | Delete
$num_pages = count( $pages );
[6263] Fix | Delete
for ( $i = 0; $i < $num_pages; $i++ ) {
[6264] Fix | Delete
if ( in_array( $pages[ $i ]->ID, $exclude, true ) ) {
[6265] Fix | Delete
unset( $pages[ $i ] );
[6266] Fix | Delete
}
[6267] Fix | Delete
}
[6268] Fix | Delete
}
[6269] Fix | Delete
[6270] Fix | Delete
/**
[6271] Fix | Delete
* Filters the retrieved list of pages.
[6272] Fix | Delete
*
[6273] Fix | Delete
* @since 2.1.0
[6274] Fix | Delete
*
[6275] Fix | Delete
* @param WP_Post[] $pages Array of page objects.
[6276] Fix | Delete
* @param array $parsed_args Array of get_pages() arguments.
[6277] Fix | Delete
*/
[6278] Fix | Delete
return apply_filters( 'get_pages', $pages, $parsed_args );
[6279] Fix | Delete
}
[6280] Fix | Delete
[6281] Fix | Delete
//
[6282] Fix | Delete
// Attachment functions.
[6283] Fix | Delete
//
[6284] Fix | Delete
[6285] Fix | Delete
/**
[6286] Fix | Delete
* Determines whether an attachment URI is local and really an attachment.
[6287] Fix | Delete
*
[6288] Fix | Delete
* For more information on this and similar theme functions, check out
[6289] Fix | Delete
* the {@link https://developer.wordpress.org/themes/basics/conditional-tags/
[6290] Fix | Delete
* Conditional Tags} article in the Theme Developer Handbook.
[6291] Fix | Delete
*
[6292] Fix | Delete
* @since 2.0.0
[6293] Fix | Delete
*
[6294] Fix | Delete
* @param string $url URL to check
[6295] Fix | Delete
* @return bool True on success, false on failure.
[6296] Fix | Delete
*/
[6297] Fix | Delete
function is_local_attachment( $url ) {
[6298] Fix | Delete
if ( ! str_contains( $url, home_url() ) ) {
[6299] Fix | Delete
return false;
[6300] Fix | Delete
}
[6301] Fix | Delete
if ( str_contains( $url, home_url( '/?attachment_id=' ) ) ) {
[6302] Fix | Delete
return true;
[6303] Fix | Delete
}
[6304] Fix | Delete
[6305] Fix | Delete
$id = url_to_postid( $url );
[6306] Fix | Delete
if ( $id ) {
[6307] Fix | Delete
$post = get_post( $id );
[6308] Fix | Delete
if ( 'attachment' === $post->post_type ) {
[6309] Fix | Delete
return true;
[6310] Fix | Delete
}
[6311] Fix | Delete
}
[6312] Fix | Delete
return false;
[6313] Fix | Delete
}
[6314] Fix | Delete
[6315] Fix | Delete
/**
[6316] Fix | Delete
* Inserts an attachment.
[6317] Fix | Delete
*
[6318] Fix | Delete
* If you set the 'ID' in the $args parameter, it will mean that you are
[6319] Fix | Delete
* updating and attempt to update the attachment. You can also set the
[6320] Fix | Delete
* attachment name or title by setting the key 'post_name' or 'post_title'.
[6321] Fix | Delete
*
[6322] Fix | Delete
* You can set the dates for the attachment manually by setting the 'post_date'
[6323] Fix | Delete
* and 'post_date_gmt' keys' values.
[6324] Fix | Delete
*
[6325] Fix | Delete
* By default, the comments will use the default settings for whether the
[6326] Fix | Delete
* comments are allowed. You can close them manually or keep them open by
[6327] Fix | Delete
* setting the value for the 'comment_status' key.
[6328] Fix | Delete
*
[6329] Fix | Delete
* @since 2.0.0
[6330] Fix | Delete
* @since 4.7.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure.
[6331] Fix | Delete
* @since 5.6.0 Added the `$fire_after_hooks` parameter.
[6332] Fix | Delete
*
[6333] Fix | Delete
* @see wp_insert_post()
[6334] Fix | Delete
*
[6335] Fix | Delete
* @param string|array $args Arguments for inserting an attachment.
[6336] Fix | Delete
* @param string|false $file Optional. Filename. Default false.
[6337] Fix | Delete
* @param int $parent_post_id Optional. Parent post ID or 0 for no parent. Default 0.
[6338] Fix | Delete
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
[6339] Fix | Delete
* @param bool $fire_after_hooks Optional. Whether to fire the after insert hooks. Default true.
[6340] Fix | Delete
* @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
[6341] Fix | Delete
*/
[6342] Fix | Delete
function wp_insert_attachment( $args, $file = false, $parent_post_id = 0, $wp_error = false, $fire_after_hooks = true ) {
[6343] Fix | Delete
$defaults = array(
[6344] Fix | Delete
'file' => $file,
[6345] Fix | Delete
'post_parent' => 0,
[6346] Fix | Delete
);
[6347] Fix | Delete
[6348] Fix | Delete
$data = wp_parse_args( $args, $defaults );
[6349] Fix | Delete
[6350] Fix | Delete
if ( ! empty( $parent_post_id ) ) {
[6351] Fix | Delete
$data['post_parent'] = $parent_post_id;
[6352] Fix | Delete
}
[6353] Fix | Delete
[6354] Fix | Delete
$data['post_type'] = 'attachment';
[6355] Fix | Delete
[6356] Fix | Delete
return wp_insert_post( $data, $wp_error, $fire_after_hooks );
[6357] Fix | Delete
}
[6358] Fix | Delete
[6359] Fix | Delete
/**
[6360] Fix | Delete
* Trashes or deletes an attachment.
[6361] Fix | Delete
*
[6362] Fix | Delete
* When an attachment is permanently deleted, the file will also be removed.
[6363] Fix | Delete
* Deletion removes all post meta fields, taxonomy, comments, etc. associated
[6364] Fix | Delete
* with the attachment (except the main post).
[6365] Fix | Delete
*
[6366] Fix | Delete
* The attachment is moved to the Trash instead of permanently deleted unless Trash
[6367] Fix | Delete
* for media is disabled, item is already in the Trash, or $force_delete is true.
[6368] Fix | Delete
*
[6369] Fix | Delete
* @since 2.0.0
[6370] Fix | Delete
*
[6371] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[6372] Fix | Delete
*
[6373] Fix | Delete
* @param int $post_id Attachment ID.
[6374] Fix | Delete
* @param bool $force_delete Optional. Whether to bypass Trash and force deletion.
[6375] Fix | Delete
* Default false.
[6376] Fix | Delete
* @return WP_Post|false|null Post data on success, false or null on failure.
[6377] Fix | Delete
*/
[6378] Fix | Delete
function wp_delete_attachment( $post_id, $force_delete = false ) {
[6379] Fix | Delete
global $wpdb;
[6380] Fix | Delete
[6381] Fix | Delete
$post = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $wpdb->posts WHERE ID = %d", $post_id ) );
[6382] Fix | Delete
[6383] Fix | Delete
if ( ! $post ) {
[6384] Fix | Delete
return $post;
[6385] Fix | Delete
}
[6386] Fix | Delete
[6387] Fix | Delete
$post = get_post( $post );
[6388] Fix | Delete
[6389] Fix | Delete
if ( 'attachment' !== $post->post_type ) {
[6390] Fix | Delete
return false;
[6391] Fix | Delete
}
[6392] Fix | Delete
[6393] Fix | Delete
if ( ! $force_delete && EMPTY_TRASH_DAYS && MEDIA_TRASH && 'trash' !== $post->post_status ) {
[6394] Fix | Delete
return wp_trash_post( $post_id );
[6395] Fix | Delete
}
[6396] Fix | Delete
[6397] Fix | Delete
/**
[6398] Fix | Delete
* Filters whether an attachment deletion should take place.
[6399] Fix | Delete
*
[6400] Fix | Delete
* @since 5.5.0
[6401] Fix | Delete
*
[6402] Fix | Delete
* @param WP_Post|false|null $delete Whether to go forward with deletion.
[6403] Fix | Delete
* @param WP_Post $post Post object.
[6404] Fix | Delete
* @param bool $force_delete Whether to bypass the Trash.
[6405] Fix | Delete
*/
[6406] Fix | Delete
$check = apply_filters( 'pre_delete_attachment', null, $post, $force_delete );
[6407] Fix | Delete
if ( null !== $check ) {
[6408] Fix | Delete
return $check;
[6409] Fix | Delete
}
[6410] Fix | Delete
[6411] Fix | Delete
delete_post_meta( $post_id, '_wp_trash_meta_status' );
[6412] Fix | Delete
delete_post_meta( $post_id, '_wp_trash_meta_time' );
[6413] Fix | Delete
[6414] Fix | Delete
$meta = wp_get_attachment_metadata( $post_id );
[6415] Fix | Delete
$backup_sizes = get_post_meta( $post->ID, '_wp_attachment_backup_sizes', true );
[6416] Fix | Delete
$file = get_attached_file( $post_id );
[6417] Fix | Delete
[6418] Fix | Delete
if ( is_multisite() && is_string( $file ) && ! empty( $file ) ) {
[6419] Fix | Delete
clean_dirsize_cache( $file );
[6420] Fix | Delete
}
[6421] Fix | Delete
[6422] Fix | Delete
/**
[6423] Fix | Delete
* Fires before an attachment is deleted, at the start of wp_delete_attachment().
[6424] Fix | Delete
*
[6425] Fix | Delete
* @since 2.0.0
[6426] Fix | Delete
* @since 5.5.0 Added the `$post` parameter.
[6427] Fix | Delete
*
[6428] Fix | Delete
* @param int $post_id Attachment ID.
[6429] Fix | Delete
* @param WP_Post $post Post object.
[6430] Fix | Delete
*/
[6431] Fix | Delete
do_action( 'delete_attachment', $post_id, $post );
[6432] Fix | Delete
[6433] Fix | Delete
wp_delete_object_term_relationships( $post_id, array( 'category', 'post_tag' ) );
[6434] Fix | Delete
wp_delete_object_term_relationships( $post_id, get_object_taxonomies( $post->post_type ) );
[6435] Fix | Delete
[6436] Fix | Delete
// Delete all for any posts.
[6437] Fix | Delete
delete_metadata( 'post', null, '_thumbnail_id', $post_id, true );
[6438] Fix | Delete
[6439] Fix | Delete
wp_defer_comment_counting( true );
[6440] Fix | Delete
[6441] Fix | Delete
$comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = %d ORDER BY comment_ID DESC", $post_id ) );
[6442] Fix | Delete
foreach ( $comment_ids as $comment_id ) {
[6443] Fix | Delete
wp_delete_comment( $comment_id, true );
[6444] Fix | Delete
}
[6445] Fix | Delete
[6446] Fix | Delete
wp_defer_comment_counting( false );
[6447] Fix | Delete
[6448] Fix | Delete
$post_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE post_id = %d ", $post_id ) );
[6449] Fix | Delete
foreach ( $post_meta_ids as $mid ) {
[6450] Fix | Delete
delete_metadata_by_mid( 'post', $mid );
[6451] Fix | Delete
}
[6452] Fix | Delete
[6453] Fix | Delete
/** This action is documented in wp-includes/post.php */
[6454] Fix | Delete
do_action( 'delete_post', $post_id, $post );
[6455] Fix | Delete
$result = $wpdb->delete( $wpdb->posts, array( 'ID' => $post_id ) );
[6456] Fix | Delete
if ( ! $result ) {
[6457] Fix | Delete
return false;
[6458] Fix | Delete
}
[6459] Fix | Delete
/** This action is documented in wp-includes/post.php */
[6460] Fix | Delete
do_action( 'deleted_post', $post_id, $post );
[6461] Fix | Delete
[6462] Fix | Delete
wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file );
[6463] Fix | Delete
[6464] Fix | Delete
clean_post_cache( $post );
[6465] Fix | Delete
[6466] Fix | Delete
return $post;
[6467] Fix | Delete
}
[6468] Fix | Delete
[6469] Fix | Delete
/**
[6470] Fix | Delete
* Deletes all files that belong to the given attachment.
[6471] Fix | Delete
*
[6472] Fix | Delete
* @since 4.9.7
[6473] Fix | Delete
*
[6474] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[6475] Fix | Delete
*
[6476] Fix | Delete
* @param int $post_id Attachment ID.
[6477] Fix | Delete
* @param array $meta The attachment's meta data.
[6478] Fix | Delete
* @param array $backup_sizes The meta data for the attachment's backup images.
[6479] Fix | Delete
* @param string $file Absolute path to the attachment's file.
[6480] Fix | Delete
* @return bool True on success, false on failure.
[6481] Fix | Delete
*/
[6482] Fix | Delete
function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
[6483] Fix | Delete
global $wpdb;
[6484] Fix | Delete
[6485] Fix | Delete
$uploadpath = wp_get_upload_dir();
[6486] Fix | Delete
$deleted = true;
[6487] Fix | Delete
[6488] Fix | Delete
if ( ! empty( $meta['thumb'] ) ) {
[6489] Fix | Delete
// Don't delete the thumb if another attachment uses it.
[6490] Fix | Delete
if ( ! $wpdb->get_row( $wpdb->prepare( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value LIKE %s AND post_id <> %d", '%' . $wpdb->esc_like( $meta['thumb'] ) . '%', $post_id ) ) ) {
[6491] Fix | Delete
$thumbfile = str_replace( wp_basename( $file ), $meta['thumb'], $file );
[6492] Fix | Delete
[6493] Fix | Delete
if ( ! empty( $thumbfile ) ) {
[6494] Fix | Delete
$thumbfile = path_join( $uploadpath['basedir'], $thumbfile );
[6495] Fix | Delete
$thumbdir = path_join( $uploadpath['basedir'], dirname( $file ) );
[6496] Fix | Delete
[6497] Fix | Delete
if ( ! wp_delete_file_from_directory( $thumbfile, $thumbdir ) ) {
[6498] Fix | Delete
$deleted = false;
[6499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function