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
* @global wpdb $wpdb WordPress database abstraction object.
[5000] Fix | Delete
*
[5001] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[5002] Fix | Delete
*/
[5003] Fix | Delete
function wp_publish_post( $post ) {
[5004] Fix | Delete
global $wpdb;
[5005] Fix | Delete
[5006] Fix | Delete
$post = get_post( $post );
[5007] Fix | Delete
[5008] Fix | Delete
if ( ! $post ) {
[5009] Fix | Delete
return;
[5010] Fix | Delete
}
[5011] Fix | Delete
[5012] Fix | Delete
if ( 'publish' === $post->post_status ) {
[5013] Fix | Delete
return;
[5014] Fix | Delete
}
[5015] Fix | Delete
[5016] Fix | Delete
$post_before = get_post( $post->ID );
[5017] Fix | Delete
[5018] Fix | Delete
// Ensure at least one term is applied for taxonomies with a default term.
[5019] Fix | Delete
foreach ( get_object_taxonomies( $post->post_type, 'object' ) as $taxonomy => $tax_object ) {
[5020] Fix | Delete
// Skip taxonomy if no default term is set.
[5021] Fix | Delete
if (
[5022] Fix | Delete
'category' !== $taxonomy &&
[5023] Fix | Delete
empty( $tax_object->default_term )
[5024] Fix | Delete
) {
[5025] Fix | Delete
continue;
[5026] Fix | Delete
}
[5027] Fix | Delete
[5028] Fix | Delete
// Do not modify previously set terms.
[5029] Fix | Delete
if ( ! empty( get_the_terms( $post, $taxonomy ) ) ) {
[5030] Fix | Delete
continue;
[5031] Fix | Delete
}
[5032] Fix | Delete
[5033] Fix | Delete
if ( 'category' === $taxonomy ) {
[5034] Fix | Delete
$default_term_id = (int) get_option( 'default_category', 0 );
[5035] Fix | Delete
} else {
[5036] Fix | Delete
$default_term_id = (int) get_option( 'default_term_' . $taxonomy, 0 );
[5037] Fix | Delete
}
[5038] Fix | Delete
[5039] Fix | Delete
if ( ! $default_term_id ) {
[5040] Fix | Delete
continue;
[5041] Fix | Delete
}
[5042] Fix | Delete
wp_set_post_terms( $post->ID, array( $default_term_id ), $taxonomy );
[5043] Fix | Delete
}
[5044] Fix | Delete
[5045] Fix | Delete
$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
[5046] Fix | Delete
[5047] Fix | Delete
clean_post_cache( $post->ID );
[5048] Fix | Delete
[5049] Fix | Delete
$old_status = $post->post_status;
[5050] Fix | Delete
$post->post_status = 'publish';
[5051] Fix | Delete
wp_transition_post_status( 'publish', $old_status, $post );
[5052] Fix | Delete
[5053] Fix | Delete
/** This action is documented in wp-includes/post.php */
[5054] Fix | Delete
do_action( "edit_post_{$post->post_type}", $post->ID, $post );
[5055] Fix | Delete
[5056] Fix | Delete
/** This action is documented in wp-includes/post.php */
[5057] Fix | Delete
do_action( 'edit_post', $post->ID, $post );
[5058] Fix | Delete
[5059] Fix | Delete
/** This action is documented in wp-includes/post.php */
[5060] Fix | Delete
do_action( "save_post_{$post->post_type}", $post->ID, $post, true );
[5061] Fix | Delete
[5062] Fix | Delete
/** This action is documented in wp-includes/post.php */
[5063] Fix | Delete
do_action( 'save_post', $post->ID, $post, true );
[5064] Fix | Delete
[5065] Fix | Delete
/** This action is documented in wp-includes/post.php */
[5066] Fix | Delete
do_action( 'wp_insert_post', $post->ID, $post, true );
[5067] Fix | Delete
[5068] Fix | Delete
wp_after_insert_post( $post, true, $post_before );
[5069] Fix | Delete
}
[5070] Fix | Delete
[5071] Fix | Delete
/**
[5072] Fix | Delete
* Publishes future post and make sure post ID has future post status.
[5073] Fix | Delete
*
[5074] Fix | Delete
* Invoked by cron 'publish_future_post' event. This safeguard prevents cron
[5075] Fix | Delete
* from publishing drafts, etc.
[5076] Fix | Delete
*
[5077] Fix | Delete
* @since 2.5.0
[5078] Fix | Delete
*
[5079] Fix | Delete
* @param int|WP_Post $post Post ID or post object.
[5080] Fix | Delete
*/
[5081] Fix | Delete
function check_and_publish_future_post( $post ) {
[5082] Fix | Delete
$post = get_post( $post );
[5083] Fix | Delete
[5084] Fix | Delete
if ( ! $post ) {
[5085] Fix | Delete
return;
[5086] Fix | Delete
}
[5087] Fix | Delete
[5088] Fix | Delete
if ( 'future' !== $post->post_status ) {
[5089] Fix | Delete
return;
[5090] Fix | Delete
}
[5091] Fix | Delete
[5092] Fix | Delete
$time = strtotime( $post->post_date_gmt . ' GMT' );
[5093] Fix | Delete
[5094] Fix | Delete
// Uh oh, someone jumped the gun!
[5095] Fix | Delete
if ( $time > time() ) {
[5096] Fix | Delete
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) ); // Clear anything else in the system.
[5097] Fix | Delete
wp_schedule_single_event( $time, 'publish_future_post', array( $post->ID ) );
[5098] Fix | Delete
return;
[5099] Fix | Delete
}
[5100] Fix | Delete
[5101] Fix | Delete
// wp_publish_post() returns no meaningful value.
[5102] Fix | Delete
wp_publish_post( $post->ID );
[5103] Fix | Delete
}
[5104] Fix | Delete
[5105] Fix | Delete
/**
[5106] Fix | Delete
* Uses wp_checkdate to return a valid Gregorian-calendar value for post_date.
[5107] Fix | Delete
* If post_date is not provided, this first checks post_date_gmt if provided,
[5108] Fix | Delete
* then falls back to use the current time.
[5109] Fix | Delete
*
[5110] Fix | Delete
* For back-compat purposes in wp_insert_post, an empty post_date and an invalid
[5111] Fix | Delete
* post_date_gmt will continue to return '1970-01-01 00:00:00' rather than false.
[5112] Fix | Delete
*
[5113] Fix | Delete
* @since 5.7.0
[5114] Fix | Delete
*
[5115] Fix | Delete
* @param string $post_date The date in mysql format (`Y-m-d H:i:s`).
[5116] Fix | Delete
* @param string $post_date_gmt The GMT date in mysql format (`Y-m-d H:i:s`).
[5117] Fix | Delete
* @return string|false A valid Gregorian-calendar date string, or false on failure.
[5118] Fix | Delete
*/
[5119] Fix | Delete
function wp_resolve_post_date( $post_date = '', $post_date_gmt = '' ) {
[5120] Fix | Delete
// If the date is empty, set the date to now.
[5121] Fix | Delete
if ( empty( $post_date ) || '0000-00-00 00:00:00' === $post_date ) {
[5122] Fix | Delete
if ( empty( $post_date_gmt ) || '0000-00-00 00:00:00' === $post_date_gmt ) {
[5123] Fix | Delete
$post_date = current_time( 'mysql' );
[5124] Fix | Delete
} else {
[5125] Fix | Delete
$post_date = get_date_from_gmt( $post_date_gmt );
[5126] Fix | Delete
}
[5127] Fix | Delete
}
[5128] Fix | Delete
[5129] Fix | Delete
// Validate the date.
[5130] Fix | Delete
$month = (int) substr( $post_date, 5, 2 );
[5131] Fix | Delete
$day = (int) substr( $post_date, 8, 2 );
[5132] Fix | Delete
$year = (int) substr( $post_date, 0, 4 );
[5133] Fix | Delete
[5134] Fix | Delete
$valid_date = wp_checkdate( $month, $day, $year, $post_date );
[5135] Fix | Delete
[5136] Fix | Delete
if ( ! $valid_date ) {
[5137] Fix | Delete
return false;
[5138] Fix | Delete
}
[5139] Fix | Delete
return $post_date;
[5140] Fix | Delete
}
[5141] Fix | Delete
[5142] Fix | Delete
/**
[5143] Fix | Delete
* Computes a unique slug for the post, when given the desired slug and some post details.
[5144] Fix | Delete
*
[5145] Fix | Delete
* @since 2.8.0
[5146] Fix | Delete
*
[5147] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[5148] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[5149] Fix | Delete
*
[5150] Fix | Delete
* @param string $slug The desired slug (post_name).
[5151] Fix | Delete
* @param int $post_id Post ID.
[5152] Fix | Delete
* @param string $post_status No uniqueness checks are made if the post is still draft or pending.
[5153] Fix | Delete
* @param string $post_type Post type.
[5154] Fix | Delete
* @param int $post_parent Post parent ID.
[5155] Fix | Delete
* @return string Unique slug for the post, based on $post_name (with a -1, -2, etc. suffix)
[5156] Fix | Delete
*/
[5157] Fix | Delete
function wp_unique_post_slug( $slug, $post_id, $post_status, $post_type, $post_parent ) {
[5158] Fix | Delete
if ( in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ), true )
[5159] Fix | Delete
|| ( 'inherit' === $post_status && 'revision' === $post_type ) || 'user_request' === $post_type
[5160] Fix | Delete
) {
[5161] Fix | Delete
return $slug;
[5162] Fix | Delete
}
[5163] Fix | Delete
[5164] Fix | Delete
/**
[5165] Fix | Delete
* Filters the post slug before it is generated to be unique.
[5166] Fix | Delete
*
[5167] Fix | Delete
* Returning a non-null value will short-circuit the
[5168] Fix | Delete
* unique slug generation, returning the passed value instead.
[5169] Fix | Delete
*
[5170] Fix | Delete
* @since 5.1.0
[5171] Fix | Delete
*
[5172] Fix | Delete
* @param string|null $override_slug Short-circuit return value.
[5173] Fix | Delete
* @param string $slug The desired slug (post_name).
[5174] Fix | Delete
* @param int $post_id Post ID.
[5175] Fix | Delete
* @param string $post_status The post status.
[5176] Fix | Delete
* @param string $post_type Post type.
[5177] Fix | Delete
* @param int $post_parent Post parent ID.
[5178] Fix | Delete
*/
[5179] Fix | Delete
$override_slug = apply_filters( 'pre_wp_unique_post_slug', null, $slug, $post_id, $post_status, $post_type, $post_parent );
[5180] Fix | Delete
if ( null !== $override_slug ) {
[5181] Fix | Delete
return $override_slug;
[5182] Fix | Delete
}
[5183] Fix | Delete
[5184] Fix | Delete
global $wpdb, $wp_rewrite;
[5185] Fix | Delete
[5186] Fix | Delete
$original_slug = $slug;
[5187] Fix | Delete
[5188] Fix | Delete
$feeds = $wp_rewrite->feeds;
[5189] Fix | Delete
if ( ! is_array( $feeds ) ) {
[5190] Fix | Delete
$feeds = array();
[5191] Fix | Delete
}
[5192] Fix | Delete
[5193] Fix | Delete
if ( 'attachment' === $post_type ) {
[5194] Fix | Delete
// Attachment slugs must be unique across all types.
[5195] Fix | Delete
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1";
[5196] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_id ) );
[5197] Fix | Delete
[5198] Fix | Delete
/**
[5199] Fix | Delete
* Filters whether the post slug would make a bad attachment slug.
[5200] Fix | Delete
*
[5201] Fix | Delete
* @since 3.1.0
[5202] Fix | Delete
*
[5203] Fix | Delete
* @param bool $bad_slug Whether the slug would be bad as an attachment slug.
[5204] Fix | Delete
* @param string $slug The post slug.
[5205] Fix | Delete
*/
[5206] Fix | Delete
$is_bad_attachment_slug = apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug );
[5207] Fix | Delete
[5208] Fix | Delete
if ( $post_name_check
[5209] Fix | Delete
|| in_array( $slug, $feeds, true ) || 'embed' === $slug
[5210] Fix | Delete
|| $is_bad_attachment_slug
[5211] Fix | Delete
) {
[5212] Fix | Delete
$suffix = 2;
[5213] Fix | Delete
do {
[5214] Fix | Delete
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
[5215] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_id ) );
[5216] Fix | Delete
++$suffix;
[5217] Fix | Delete
} while ( $post_name_check );
[5218] Fix | Delete
$slug = $alt_post_name;
[5219] Fix | Delete
}
[5220] Fix | Delete
} elseif ( is_post_type_hierarchical( $post_type ) ) {
[5221] Fix | Delete
if ( 'nav_menu_item' === $post_type ) {
[5222] Fix | Delete
return $slug;
[5223] Fix | Delete
}
[5224] Fix | Delete
[5225] Fix | Delete
/*
[5226] Fix | Delete
* Page slugs must be unique within their own trees. Pages are in a separate
[5227] Fix | Delete
* namespace than posts so page slugs are allowed to overlap post slugs.
[5228] Fix | Delete
*/
[5229] Fix | Delete
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
[5230] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_id, $post_parent ) );
[5231] Fix | Delete
[5232] Fix | Delete
/**
[5233] Fix | Delete
* Filters whether the post slug would make a bad hierarchical post slug.
[5234] Fix | Delete
*
[5235] Fix | Delete
* @since 3.1.0
[5236] Fix | Delete
*
[5237] Fix | Delete
* @param bool $bad_slug Whether the post slug would be bad in a hierarchical post context.
[5238] Fix | Delete
* @param string $slug The post slug.
[5239] Fix | Delete
* @param string $post_type Post type.
[5240] Fix | Delete
* @param int $post_parent Post parent ID.
[5241] Fix | Delete
*/
[5242] Fix | Delete
$is_bad_hierarchical_slug = apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent );
[5243] Fix | Delete
[5244] Fix | Delete
if ( $post_name_check
[5245] Fix | Delete
|| in_array( $slug, $feeds, true ) || 'embed' === $slug
[5246] Fix | Delete
|| preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )
[5247] Fix | Delete
|| $is_bad_hierarchical_slug
[5248] Fix | Delete
) {
[5249] Fix | Delete
$suffix = 2;
[5250] Fix | Delete
do {
[5251] Fix | Delete
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
[5252] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id, $post_parent ) );
[5253] Fix | Delete
++$suffix;
[5254] Fix | Delete
} while ( $post_name_check );
[5255] Fix | Delete
$slug = $alt_post_name;
[5256] Fix | Delete
}
[5257] Fix | Delete
} else {
[5258] Fix | Delete
// Post slugs must be unique across all posts.
[5259] Fix | Delete
$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1";
[5260] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_id ) );
[5261] Fix | Delete
[5262] Fix | Delete
$post = get_post( $post_id );
[5263] Fix | Delete
[5264] Fix | Delete
// Prevent new post slugs that could result in URLs that conflict with date archives.
[5265] Fix | Delete
$conflicts_with_date_archive = false;
[5266] Fix | Delete
if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) {
[5267] Fix | Delete
$slug_num = (int) $slug;
[5268] Fix | Delete
[5269] Fix | Delete
if ( $slug_num ) {
[5270] Fix | Delete
$permastructs = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
[5271] Fix | Delete
$postname_index = array_search( '%postname%', $permastructs, true );
[5272] Fix | Delete
[5273] Fix | Delete
/*
[5274] Fix | Delete
* Potential date clashes are as follows:
[5275] Fix | Delete
*
[5276] Fix | Delete
* - Any integer in the first permastruct position could be a year.
[5277] Fix | Delete
* - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
[5278] Fix | Delete
* - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
[5279] Fix | Delete
*/
[5280] Fix | Delete
if ( 0 === $postname_index ||
[5281] Fix | Delete
( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) ||
[5282] Fix | Delete
( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num )
[5283] Fix | Delete
) {
[5284] Fix | Delete
$conflicts_with_date_archive = true;
[5285] Fix | Delete
}
[5286] Fix | Delete
}
[5287] Fix | Delete
}
[5288] Fix | Delete
[5289] Fix | Delete
/**
[5290] Fix | Delete
* Filters whether the post slug would be bad as a flat slug.
[5291] Fix | Delete
*
[5292] Fix | Delete
* @since 3.1.0
[5293] Fix | Delete
*
[5294] Fix | Delete
* @param bool $bad_slug Whether the post slug would be bad as a flat slug.
[5295] Fix | Delete
* @param string $slug The post slug.
[5296] Fix | Delete
* @param string $post_type Post type.
[5297] Fix | Delete
*/
[5298] Fix | Delete
$is_bad_flat_slug = apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type );
[5299] Fix | Delete
[5300] Fix | Delete
if ( $post_name_check
[5301] Fix | Delete
|| in_array( $slug, $feeds, true ) || 'embed' === $slug
[5302] Fix | Delete
|| $conflicts_with_date_archive
[5303] Fix | Delete
|| $is_bad_flat_slug
[5304] Fix | Delete
) {
[5305] Fix | Delete
$suffix = 2;
[5306] Fix | Delete
do {
[5307] Fix | Delete
$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
[5308] Fix | Delete
$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_id ) );
[5309] Fix | Delete
++$suffix;
[5310] Fix | Delete
} while ( $post_name_check );
[5311] Fix | Delete
$slug = $alt_post_name;
[5312] Fix | Delete
}
[5313] Fix | Delete
}
[5314] Fix | Delete
[5315] Fix | Delete
/**
[5316] Fix | Delete
* Filters the unique post slug.
[5317] Fix | Delete
*
[5318] Fix | Delete
* @since 3.3.0
[5319] Fix | Delete
*
[5320] Fix | Delete
* @param string $slug The post slug.
[5321] Fix | Delete
* @param int $post_id Post ID.
[5322] Fix | Delete
* @param string $post_status The post status.
[5323] Fix | Delete
* @param string $post_type Post type.
[5324] Fix | Delete
* @param int $post_parent Post parent ID
[5325] Fix | Delete
* @param string $original_slug The original post slug.
[5326] Fix | Delete
*/
[5327] Fix | Delete
return apply_filters( 'wp_unique_post_slug', $slug, $post_id, $post_status, $post_type, $post_parent, $original_slug );
[5328] Fix | Delete
}
[5329] Fix | Delete
[5330] Fix | Delete
/**
[5331] Fix | Delete
* Truncates a post slug.
[5332] Fix | Delete
*
[5333] Fix | Delete
* @since 3.6.0
[5334] Fix | Delete
* @access private
[5335] Fix | Delete
*
[5336] Fix | Delete
* @see utf8_uri_encode()
[5337] Fix | Delete
*
[5338] Fix | Delete
* @param string $slug The slug to truncate.
[5339] Fix | Delete
* @param int $length Optional. Max length of the slug. Default 200 (characters).
[5340] Fix | Delete
* @return string The truncated slug.
[5341] Fix | Delete
*/
[5342] Fix | Delete
function _truncate_post_slug( $slug, $length = 200 ) {
[5343] Fix | Delete
if ( strlen( $slug ) > $length ) {
[5344] Fix | Delete
$decoded_slug = urldecode( $slug );
[5345] Fix | Delete
if ( $decoded_slug === $slug ) {
[5346] Fix | Delete
$slug = substr( $slug, 0, $length );
[5347] Fix | Delete
} else {
[5348] Fix | Delete
$slug = utf8_uri_encode( $decoded_slug, $length, true );
[5349] Fix | Delete
}
[5350] Fix | Delete
}
[5351] Fix | Delete
[5352] Fix | Delete
return rtrim( $slug, '-' );
[5353] Fix | Delete
}
[5354] Fix | Delete
[5355] Fix | Delete
/**
[5356] Fix | Delete
* Adds tags to a post.
[5357] Fix | Delete
*
[5358] Fix | Delete
* @see wp_set_post_tags()
[5359] Fix | Delete
*
[5360] Fix | Delete
* @since 2.3.0
[5361] Fix | Delete
*
[5362] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post.
[5363] Fix | Delete
* @param string|array $tags Optional. An array of tags to set for the post, or a string of tags
[5364] Fix | Delete
* separated by commas. Default empty.
[5365] Fix | Delete
* @return array|false|WP_Error Array of affected term IDs. WP_Error or false on failure.
[5366] Fix | Delete
*/
[5367] Fix | Delete
function wp_add_post_tags( $post_id = 0, $tags = '' ) {
[5368] Fix | Delete
return wp_set_post_tags( $post_id, $tags, true );
[5369] Fix | Delete
}
[5370] Fix | Delete
[5371] Fix | Delete
/**
[5372] Fix | Delete
* Sets the tags for a post.
[5373] Fix | Delete
*
[5374] Fix | Delete
* @since 2.3.0
[5375] Fix | Delete
*
[5376] Fix | Delete
* @see wp_set_object_terms()
[5377] Fix | Delete
*
[5378] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post.
[5379] Fix | Delete
* @param string|array $tags Optional. An array of tags to set for the post, or a string of tags
[5380] Fix | Delete
* separated by commas. Default empty.
[5381] Fix | Delete
* @param bool $append Optional. If true, don't delete existing tags, just add on. If false,
[5382] Fix | Delete
* replace the tags with the new tags. Default false.
[5383] Fix | Delete
* @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
[5384] Fix | Delete
*/
[5385] Fix | Delete
function wp_set_post_tags( $post_id = 0, $tags = '', $append = false ) {
[5386] Fix | Delete
return wp_set_post_terms( $post_id, $tags, 'post_tag', $append );
[5387] Fix | Delete
}
[5388] Fix | Delete
[5389] Fix | Delete
/**
[5390] Fix | Delete
* Sets the terms for a post.
[5391] Fix | Delete
*
[5392] Fix | Delete
* @since 2.8.0
[5393] Fix | Delete
*
[5394] Fix | Delete
* @see wp_set_object_terms()
[5395] Fix | Delete
*
[5396] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID of the global $post.
[5397] Fix | Delete
* @param string|array $terms Optional. An array of terms to set for the post, or a string of terms
[5398] Fix | Delete
* separated by commas. Hierarchical taxonomies must always pass IDs rather
[5399] Fix | Delete
* than names so that children with the same names but different parents
[5400] Fix | Delete
* aren't confused. Default empty.
[5401] Fix | Delete
* @param string $taxonomy Optional. Taxonomy name. Default 'post_tag'.
[5402] Fix | Delete
* @param bool $append Optional. If true, don't delete existing terms, just add on. If false,
[5403] Fix | Delete
* replace the terms with the new terms. Default false.
[5404] Fix | Delete
* @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
[5405] Fix | Delete
*/
[5406] Fix | Delete
function wp_set_post_terms( $post_id = 0, $terms = '', $taxonomy = 'post_tag', $append = false ) {
[5407] Fix | Delete
$post_id = (int) $post_id;
[5408] Fix | Delete
[5409] Fix | Delete
if ( ! $post_id ) {
[5410] Fix | Delete
return false;
[5411] Fix | Delete
}
[5412] Fix | Delete
[5413] Fix | Delete
if ( empty( $terms ) ) {
[5414] Fix | Delete
$terms = array();
[5415] Fix | Delete
}
[5416] Fix | Delete
[5417] Fix | Delete
if ( ! is_array( $terms ) ) {
[5418] Fix | Delete
$comma = _x( ',', 'tag delimiter' );
[5419] Fix | Delete
if ( ',' !== $comma ) {
[5420] Fix | Delete
$terms = str_replace( $comma, ',', $terms );
[5421] Fix | Delete
}
[5422] Fix | Delete
$terms = explode( ',', trim( $terms, " \n\t\r\0\x0B," ) );
[5423] Fix | Delete
}
[5424] Fix | Delete
[5425] Fix | Delete
/*
[5426] Fix | Delete
* Hierarchical taxonomies must always pass IDs rather than names so that
[5427] Fix | Delete
* children with the same names but different parents aren't confused.
[5428] Fix | Delete
*/
[5429] Fix | Delete
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
[5430] Fix | Delete
$terms = array_unique( array_map( 'intval', $terms ) );
[5431] Fix | Delete
}
[5432] Fix | Delete
[5433] Fix | Delete
return wp_set_object_terms( $post_id, $terms, $taxonomy, $append );
[5434] Fix | Delete
}
[5435] Fix | Delete
[5436] Fix | Delete
/**
[5437] Fix | Delete
* Sets categories for a post.
[5438] Fix | Delete
*
[5439] Fix | Delete
* If no categories are provided, the default category is used.
[5440] Fix | Delete
*
[5441] Fix | Delete
* @since 2.1.0
[5442] Fix | Delete
*
[5443] Fix | Delete
* @param int $post_id Optional. The Post ID. Does not default to the ID
[5444] Fix | Delete
* of the global $post. Default 0.
[5445] Fix | Delete
* @param int[]|int $post_categories Optional. List of category IDs, or the ID of a single category.
[5446] Fix | Delete
* Default empty array.
[5447] Fix | Delete
* @param bool $append If true, don't delete existing categories, just add on.
[5448] Fix | Delete
* If false, replace the categories with the new categories.
[5449] Fix | Delete
* @return array|false|WP_Error Array of term taxonomy IDs of affected categories. WP_Error or false on failure.
[5450] Fix | Delete
*/
[5451] Fix | Delete
function wp_set_post_categories( $post_id = 0, $post_categories = array(), $append = false ) {
[5452] Fix | Delete
$post_id = (int) $post_id;
[5453] Fix | Delete
$post_type = get_post_type( $post_id );
[5454] Fix | Delete
$post_status = get_post_status( $post_id );
[5455] Fix | Delete
[5456] Fix | Delete
// If $post_categories isn't already an array, make it one.
[5457] Fix | Delete
$post_categories = (array) $post_categories;
[5458] Fix | Delete
[5459] Fix | Delete
if ( empty( $post_categories ) ) {
[5460] Fix | Delete
/**
[5461] Fix | Delete
* Filters post types (in addition to 'post') that require a default category.
[5462] Fix | Delete
*
[5463] Fix | Delete
* @since 5.5.0
[5464] Fix | Delete
*
[5465] Fix | Delete
* @param string[] $post_types An array of post type names. Default empty array.
[5466] Fix | Delete
*/
[5467] Fix | Delete
$default_category_post_types = apply_filters( 'default_category_post_types', array() );
[5468] Fix | Delete
[5469] Fix | Delete
// Regular posts always require a default category.
[5470] Fix | Delete
$default_category_post_types = array_merge( $default_category_post_types, array( 'post' ) );
[5471] Fix | Delete
[5472] Fix | Delete
if ( in_array( $post_type, $default_category_post_types, true )
[5473] Fix | Delete
&& is_object_in_taxonomy( $post_type, 'category' )
[5474] Fix | Delete
&& 'auto-draft' !== $post_status
[5475] Fix | Delete
) {
[5476] Fix | Delete
$post_categories = array( get_option( 'default_category' ) );
[5477] Fix | Delete
$append = false;
[5478] Fix | Delete
} else {
[5479] Fix | Delete
$post_categories = array();
[5480] Fix | Delete
}
[5481] Fix | Delete
} elseif ( 1 === count( $post_categories ) && '' === reset( $post_categories ) ) {
[5482] Fix | Delete
return true;
[5483] Fix | Delete
}
[5484] Fix | Delete
[5485] Fix | Delete
return wp_set_post_terms( $post_id, $post_categories, 'category', $append );
[5486] Fix | Delete
}
[5487] Fix | Delete
[5488] Fix | Delete
/**
[5489] Fix | Delete
* Fires actions related to the transitioning of a post's status.
[5490] Fix | Delete
*
[5491] Fix | Delete
* When a post is saved, the post status is "transitioned" from one status to another,
[5492] Fix | Delete
* though this does not always mean the status has actually changed before and after
[5493] Fix | Delete
* the save. This function fires a number of action hooks related to that transition:
[5494] Fix | Delete
* the generic {@see 'transition_post_status'} action, as well as the dynamic hooks
[5495] Fix | Delete
* {@see '$old_status_to_$new_status'} and {@see '$new_status_$post->post_type'}. Note
[5496] Fix | Delete
* that the function does not transition the post object in the database.
[5497] Fix | Delete
*
[5498] Fix | Delete
* For instance: When publishing a post for the first time, the post status may transition
[5499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function