-
+ AB6349368BDFCD33C641759593FFBDEE3138ED7E1D6161237B299610048D767AF102EAB04C478F947BF59909DEECA67F4435584A8C2B3F17D296BAE6D68C1263
mp-wp/wp-admin/includes/taxonomy.php
(0 . 0)(1 . 242)
40694 <?php
40695 /**
40696 * WordPress Taxonomy Administration API.
40697 *
40698 * @package WordPress
40699 * @subpackage Administration
40700 */
40701
40702 //
40703 // Category
40704 //
40705
40706 /**
40707 * {@internal Missing Short Description}}
40708 *
40709 * @since unknown
40710 *
40711 * @param unknown_type $cat_name
40712 * @return unknown
40713 */
40714 function category_exists($cat_name) {
40715 $id = is_term($cat_name, 'category');
40716 if ( is_array($id) )
40717 $id = $id['term_id'];
40718 return $id;
40719 }
40720
40721 /**
40722 * {@internal Missing Short Description}}
40723 *
40724 * @since unknown
40725 *
40726 * @param unknown_type $id
40727 * @return unknown
40728 */
40729 function get_category_to_edit( $id ) {
40730 $category = get_category( $id, OBJECT, 'edit' );
40731 return $category;
40732 }
40733
40734 /**
40735 * {@internal Missing Short Description}}
40736 *
40737 * @since unknown
40738 *
40739 * @param unknown_type $cat_name
40740 * @param unknown_type $parent
40741 * @return unknown
40742 */
40743 function wp_create_category( $cat_name, $parent = 0 ) {
40744 if ( $id = category_exists($cat_name) )
40745 return $id;
40746
40747 return wp_insert_category( array('cat_name' => $cat_name, 'category_parent' => $parent) );
40748 }
40749
40750 /**
40751 * {@internal Missing Short Description}}
40752 *
40753 * @since unknown
40754 *
40755 * @param unknown_type $categories
40756 * @param unknown_type $post_id
40757 * @return unknown
40758 */
40759 function wp_create_categories($categories, $post_id = '') {
40760 $cat_ids = array ();
40761 foreach ($categories as $category) {
40762 if ($id = category_exists($category))
40763 $cat_ids[] = $id;
40764 else
40765 if ($id = wp_create_category($category))
40766 $cat_ids[] = $id;
40767 }
40768
40769 if ($post_id)
40770 wp_set_post_categories($post_id, $cat_ids);
40771
40772 return $cat_ids;
40773 }
40774
40775 /**
40776 * {@internal Missing Short Description}}
40777 *
40778 * @since unknown
40779 *
40780 * @param unknown_type $cat_ID
40781 * @return unknown
40782 */
40783 function wp_delete_category($cat_ID) {
40784 $cat_ID = (int) $cat_ID;
40785 $default = get_option('default_category');
40786
40787 // Don't delete the default cat
40788 if ( $cat_ID == $default )
40789 return 0;
40790
40791 return wp_delete_term($cat_ID, 'category', array('default' => $default));
40792 }
40793
40794 /**
40795 * {@internal Missing Short Description}}
40796 *
40797 * @since unknown
40798 *
40799 * @param unknown_type $catarr
40800 * @param unknown_type $wp_error
40801 * @return unknown
40802 */
40803 function wp_insert_category($catarr, $wp_error = false) {
40804 $cat_defaults = array('cat_ID' => 0, 'cat_name' => '', 'category_description' => '', 'category_nicename' => '', 'category_parent' => '');
40805 $catarr = wp_parse_args($catarr, $cat_defaults);
40806 extract($catarr, EXTR_SKIP);
40807
40808 if ( trim( $cat_name ) == '' ) {
40809 if ( ! $wp_error )
40810 return 0;
40811 else
40812 return new WP_Error( 'cat_name', __('You did not enter a category name.') );
40813 }
40814
40815 $cat_ID = (int) $cat_ID;
40816
40817 // Are we updating or creating?
40818 if ( !empty ($cat_ID) )
40819 $update = true;
40820 else
40821 $update = false;
40822
40823 $name = $cat_name;
40824 $description = $category_description;
40825 $slug = $category_nicename;
40826 $parent = $category_parent;
40827
40828 $parent = (int) $parent;
40829 if ( $parent < 0 )
40830 $parent = 0;
40831
40832 if ( empty($parent) || !category_exists( $parent ) || ($cat_ID && cat_is_ancestor_of($cat_ID, $parent) ) )
40833 $parent = 0;
40834
40835 $args = compact('name', 'slug', 'parent', 'description');
40836
40837 if ( $update )
40838 $cat_ID = wp_update_term($cat_ID, 'category', $args);
40839 else
40840 $cat_ID = wp_insert_term($cat_name, 'category', $args);
40841
40842 if ( is_wp_error($cat_ID) ) {
40843 if ( $wp_error )
40844 return $cat_ID;
40845 else
40846 return 0;
40847 }
40848
40849 return $cat_ID['term_id'];
40850 }
40851
40852 /**
40853 * {@internal Missing Short Description}}
40854 *
40855 * @since unknown
40856 *
40857 * @param unknown_type $catarr
40858 * @return unknown
40859 */
40860 function wp_update_category($catarr) {
40861 $cat_ID = (int) $catarr['cat_ID'];
40862
40863 if ( isset($catarr['category_parent']) && ($cat_ID == $catarr['category_parent']) )
40864 return false;
40865
40866 // First, get all of the original fields
40867 $category = get_category($cat_ID, ARRAY_A);
40868
40869 // Escape data pulled from DB.
40870 $category = add_magic_quotes($category);
40871
40872 // Merge old and new fields with new fields overwriting old ones.
40873 $catarr = array_merge($category, $catarr);
40874
40875 return wp_insert_category($catarr);
40876 }
40877
40878 //
40879 // Tags
40880 //
40881
40882 /**
40883 * {@internal Missing Short Description}}
40884 *
40885 * @since unknown
40886 *
40887 * @param unknown_type $post_id
40888 * @return unknown
40889 */
40890 function get_tags_to_edit( $post_id ) {
40891 $post_id = (int) $post_id;
40892 if ( !$post_id )
40893 return false;
40894
40895 $tags = wp_get_post_tags($post_id);
40896
40897 if ( !$tags )
40898 return false;
40899
40900 foreach ( $tags as $tag )
40901 $tag_names[] = $tag->name;
40902 $tags_to_edit = join( ',', $tag_names );
40903 $tags_to_edit = attribute_escape( $tags_to_edit );
40904 $tags_to_edit = apply_filters( 'tags_to_edit', $tags_to_edit );
40905 return $tags_to_edit;
40906 }
40907
40908 /**
40909 * {@internal Missing Short Description}}
40910 *
40911 * @since unknown
40912 *
40913 * @param unknown_type $tag_name
40914 * @return unknown
40915 */
40916 function tag_exists($tag_name) {
40917 return is_term($tag_name, 'post_tag');
40918 }
40919
40920 /**
40921 * {@internal Missing Short Description}}
40922 *
40923 * @since unknown
40924 *
40925 * @param unknown_type $tag_name
40926 * @return unknown
40927 */
40928 function wp_create_tag($tag_name) {
40929 if ( $id = tag_exists($tag_name) )
40930 return $id;
40931
40932 return wp_insert_term($tag_name, 'post_tag');
40933 }
40934
40935 ?>