wp/wp-admin/includes/taxonomy.php
author ymh <ymh.work@gmail.com>
Fri, 05 Sep 2025 18:40:08 +0200
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
permissions -rw-r--r--
Add CLAUDE.md documentation and sync WordPress core files - Add comprehensive CLAUDE.md documentation file with project architecture, development setup, database operations, WordPress CLI usage, file sync procedures, and Mercurial commands - Update WordPress core files from wordpress/ to wp/ directory - Sync latest WordPress admin interface, includes, and core functionality - Update plugins: portfolio plugin with latest BWS framework and fancybox integration - Maintain custom configuration and theme files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Taxonomy Administration API.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
//
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    10
// Category.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    14
 * Checks whether a category exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    18
 * @see term_exists()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    19
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    20
 * @param int|string $cat_name        Category name.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    21
 * @param int        $category_parent Optional. ID of parent category.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    22
 * @return string|null Returns the category ID as a numeric string if the pairing exists, null if not.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    24
function category_exists( $cat_name, $category_parent = null ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    25
	$id = term_exists( $cat_name, 'category', $category_parent );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    26
	if ( is_array( $id ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
		$id = $id['term_id'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    28
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    33
 * Gets category object for given ID and 'edit' filter context.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    37
 * @param int $id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    38
 * @return object
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
function get_category_to_edit( $id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
	$category = get_term( $id, 'category', OBJECT, 'edit' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
	_make_cat_compat( $category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
	return $category;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    47
 * Adds a new category to the database if it does not already exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
 *
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    51
 * @param int|string $cat_name        Category name.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    52
 * @param int        $category_parent Optional. ID of parent category.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    53
 * @return int|WP_Error
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    55
function wp_create_category( $cat_name, $category_parent = 0 ) {
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    56
	$id = category_exists( $cat_name, $category_parent );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    57
	if ( $id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		return $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    59
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    61
	return wp_insert_category(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    62
		array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    63
			'cat_name'        => $cat_name,
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
    64
			'category_parent' => $category_parent,
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    65
		)
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    66
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
    70
 * Creates categories for the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    74
 * @param string[] $categories Array of category names to create.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    75
 * @param int      $post_id    Optional. The post ID. Default empty.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    76
 * @return int[] Array of IDs of categories assigned to the given post.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    78
function wp_create_categories( $categories, $post_id = '' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    79
	$cat_ids = array();
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    80
	foreach ( $categories as $category ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    81
		$id = category_exists( $category );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    82
		if ( $id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
			$cat_ids[] = $id;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    84
		} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    85
			$id = wp_create_category( $category );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    86
			if ( $id ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    87
				$cat_ids[] = $id;
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    88
			}
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    89
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    92
	if ( $post_id ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    93
		wp_set_post_categories( $post_id, $cat_ids );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    94
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	return $cat_ids;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
 * Updates an existing Category or creates a new Category.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
 * @since 2.0.0
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   103
 * @since 2.5.0 $wp_error parameter was added.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   104
 * @since 3.0.0 The 'taxonomy' argument was added.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   106
 * @param array $catarr {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
 *     Array of arguments for inserting a new category.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   108
 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   109
 *     @type int        $cat_ID               Category ID. A non-zero value updates an existing category.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
 *                                            Default 0.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   111
 *     @type string     $taxonomy             Taxonomy slug. Default 'category'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   112
 *     @type string     $cat_name             Category name. Default empty.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
 *     @type string     $category_description Category description. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
 *     @type string     $category_nicename    Category nice (display) name. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
 *     @type int|string $category_parent      Category parent ID. Default empty.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   116
 * }
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
 * @param bool  $wp_error Optional. Default false.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   118
 * @return int|WP_Error The ID number of the new or updated Category on success. Zero or a WP_Error on failure,
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   119
 *                      depending on param `$wp_error`.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
 */
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
function wp_insert_category( $catarr, $wp_error = false ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   122
	$cat_defaults = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   123
		'cat_ID'               => 0,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   124
		'taxonomy'             => 'category',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   125
		'cat_name'             => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   126
		'category_description' => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   127
		'category_nicename'    => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   128
		'category_parent'      => '',
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   129
	);
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   130
	$catarr       = wp_parse_args( $catarr, $cat_defaults );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   132
	if ( '' === trim( $catarr['cat_name'] ) ) {
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   133
		if ( ! $wp_error ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			return 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   135
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   136
			return new WP_Error( 'cat_name', __( 'You did not enter a category name.' ) );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   137
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   140
	$catarr['cat_ID'] = (int) $catarr['cat_ID'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
	// Are we updating or creating?
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   143
	$update = ! empty( $catarr['cat_ID'] );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   145
	$name        = $catarr['cat_name'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   146
	$description = $catarr['category_description'];
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   147
	$slug        = $catarr['category_nicename'];
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   148
	$parent      = (int) $catarr['category_parent'];
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   149
	if ( $parent < 0 ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   150
		$parent = 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   151
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   153
	if ( empty( $parent )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   154
		|| ! term_exists( $parent, $catarr['taxonomy'] )
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   155
		|| ( $catarr['cat_ID'] && term_is_ancestor_of( $catarr['cat_ID'], $parent, $catarr['taxonomy'] ) ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		$parent = 0;
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   157
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   159
	$args = compact( 'name', 'slug', 'parent', 'description' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   161
	if ( $update ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   162
		$catarr['cat_ID'] = wp_update_term( $catarr['cat_ID'], $catarr['taxonomy'], $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   163
	} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   164
		$catarr['cat_ID'] = wp_insert_term( $catarr['cat_name'], $catarr['taxonomy'], $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   167
	if ( is_wp_error( $catarr['cat_ID'] ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   168
		if ( $wp_error ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   169
			return $catarr['cat_ID'];
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   170
		} else {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   171
			return 0;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   172
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   173
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   174
	return $catarr['cat_ID']['term_id'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
 * Aliases wp_insert_category() with minimal args.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
 * If you want to update only some fields of an existing category, call this
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
 * function with only the new values set inside $catarr.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
 * @since 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
 * @param array $catarr The 'cat_ID' value is required. All other keys are optional.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   186
 * @return int|false The ID number of the new or updated Category on success. Zero or FALSE on failure.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   188
function wp_update_category( $catarr ) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   189
	$cat_id = (int) $catarr['cat_ID'];
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   191
	if ( isset( $catarr['category_parent'] ) && ( $cat_id === (int) $catarr['category_parent'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   193
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   195
	// First, get all of the original fields.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   196
	$category = get_term( $cat_id, 'category', ARRAY_A );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
	_make_cat_compat( $category );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
	// Escape data pulled from DB.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   200
	$category = wp_slash( $category );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
	// Merge old and new fields with new fields overwriting old ones.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   203
	$catarr = array_merge( $category, $catarr );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   205
	return wp_insert_category( $catarr );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
//
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   209
// Tags.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
//
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   213
 * Checks whether a post tag with a given name exists.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   217
 * @param int|string $tag_name
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   218
 * @return mixed Returns null if the term does not exist.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   219
 *               Returns an array of the term ID and the term taxonomy ID if the pairing exists.
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   220
 *               Returns 0 if term ID 0 is passed to the function.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   222
function tag_exists( $tag_name ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   223
	return term_exists( $tag_name, 'post_tag' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   227
 * Adds a new tag to the database if it does not already exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   231
 * @param int|string $tag_name
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   232
 * @return array|WP_Error
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   234
function wp_create_tag( $tag_name ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   235
	return wp_create_term( $tag_name, 'post_tag' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   239
 * Gets comma-separated list of tags available to edit.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
 * @since 2.3.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   243
 * @param int    $post_id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   244
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   245
 * @return string|false|WP_Error
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
function get_tags_to_edit( $post_id, $taxonomy = 'post_tag' ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   248
	return get_terms_to_edit( $post_id, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   252
 * Gets comma-separated list of terms available to edit for the given post ID.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   256
 * @param int    $post_id
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   257
 * @param string $taxonomy Optional. The taxonomy for which to retrieve terms. Default 'post_tag'.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   258
 * @return string|false|WP_Error
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
function get_terms_to_edit( $post_id, $taxonomy = 'post_tag' ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
	$post_id = (int) $post_id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   262
	if ( ! $post_id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   264
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   266
	$terms = get_object_term_cache( $post_id, $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	if ( false === $terms ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
		$terms = wp_get_object_terms( $post_id, $taxonomy );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
		wp_cache_add( $post_id, wp_list_pluck( $terms, 'term_id' ), $taxonomy . '_relationships' );
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   270
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   272
	if ( ! $terms ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   273
		return false;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   274
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   275
	if ( is_wp_error( $terms ) ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   276
		return $terms;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   277
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
	$term_names = array();
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	foreach ( $terms as $term ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   280
		$term_names[] = $term->name;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   281
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   282
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
   283
	$terms_to_edit = esc_attr( implode( ',', $term_names ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   285
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   286
	 * Filters the comma-separated list of terms available to edit.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   287
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   288
	 * @since 2.8.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   289
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   290
	 * @see get_terms_to_edit()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   291
	 *
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   292
	 * @param string $terms_to_edit A comma-separated list of term names.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   293
	 * @param string $taxonomy      The taxonomy name for which to retrieve terms.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   294
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   295
	$terms_to_edit = apply_filters( 'terms_to_edit', $terms_to_edit, $taxonomy );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   296
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   297
	return $terms_to_edit;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
/**
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   301
 * Adds a new term to the database if it does not already exist.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
 * @since 2.8.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   305
 * @param string $tag_name The term name.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   306
 * @param string $taxonomy Optional. The taxonomy within which to create the term. Default 'post_tag'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   307
 * @return array|WP_Error
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   309
function wp_create_term( $tag_name, $taxonomy = 'post_tag' ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   310
	$id = term_exists( $tag_name, $taxonomy );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   311
	if ( $id ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		return $id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   313
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   315
	return wp_insert_term( $tag_name, $taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
}