[ Index ]

PHP Cross Reference of BackPress

title

Body

[close]

/includes/ -> class.wp-taxonomy.php (summary)

Taxonomy API

File Size: 2082 lines (74 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

WP_Taxonomy:: (43 methods):
  WP_Taxonomy()
  __construct()
  __destruct()
  get_object_taxonomies()
  get_taxonomy()
  is_taxonomy()
  is_taxonomy_hierarchical()
  register_taxonomy()
  get_objects_in_term()
  get_term()
  get_term_by()
  get_term_children()
  get_term_field()
  get_term_to_edit()
  get_terms()
  is_term()
  sanitize_term_slug()
  format_to_edit()
  sanitize_term()
  sanitize_term_field()
  count_terms()
  delete_object_term_relationships()
  delete_term()
  get_object_terms()
  insert_term()
  set_object_terms()
  unique_term_slug()
  update_term()
  defer_term_counting()
  update_term_count()
  update_term_count_now()
  clean_object_term_cache()
  clean_term_cache()
  get_object_term_cache()
  update_object_term_cache()
  update_term_cache()
  _get_term_hierarchy()
  _get_term_children()
  _pad_term_counts()
  is_object_in_term()
  get_children_cache()
  set_children_cache()
  delete_children_cache()


Class: WP_Taxonomy  - X-Ref

WordPress Taxonomy based off of WordPress revision 8782.

WP_Taxonomy( &$db )   X-Ref
No description

__construct( &$db )   X-Ref
PHP5 constructor - Assigns the database to an attribute of the class.

param: unknown_type $db

__destruct()   X-Ref
Does nothing.


get_object_taxonomies($object_type)   X-Ref
Return all of the taxonomy names that are of $object_type.

It appears that this function can be used to find all of the names inside of
$this->taxonomies variable.

<code><?php $taxonomies = $this->get_object_taxonomies('post'); ?></code> Should
result in <code>Array('category', 'post_tag')</code>

param: array|string|object $object_type Name of the type of taxonomy object, or an object (row from posts)
since: 2.3.0
return: array The names of all taxonomy of $object_type.

get_taxonomy( $taxonomy )   X-Ref
Retrieves the taxonomy object of $taxonomy.

The get_taxonomy function will first check that the parameter string given
is a taxonomy object and if it is, it will return it.

param: string $taxonomy Name of taxonomy object to return
since: 2.3.0
return: object|bool The Taxonomy Object or false if $taxonomy doesn't exist

is_taxonomy( $taxonomy )   X-Ref
Checks that the taxonomy name exists.

param: string $taxonomy Name of taxonomy object
since: 2.3.0
return: bool Whether the taxonomy exists or not.

is_taxonomy_hierarchical($taxonomy)   X-Ref
Whether the taxonomy object is hierarchical.

Checks to make sure that the taxonomy is an object first. Then Gets the
object, and finally returns the hierarchical value in the object.

A false return value might also mean that the taxonomy does not exist.

param: string $taxonomy Name of taxonomy object
since: 2.3.0
return: bool Whether the taxonomy is hierarchical

register_taxonomy( $taxonomy, $object_type, $args = array()   X-Ref
Create or modify a taxonomy object. Do not use before init.

A simple function for creating or modifying a taxonomy object based on the
parameters given. The function will accept an array (third optional
parameter), along with strings for the taxonomy name and another string for
the object type.

The function keeps a default set, allowing for the $args to be optional but
allow the other functions to still work. It is possible to overwrite the
default set, which contains two keys: hierarchical and update_count_callback.

Nothing is returned, so expect error maybe or use is_taxonomy() to check
whether taxonomy exists.

Optional $args contents:

hierarachical - has some defined purpose at other parts of the API and is a
boolean value.

update_count_callback - works much like a hook, in that it will be called
when the count is updated.

param: string $taxonomy Name of taxonomy object
param: string $object_type Name of the object type for the taxonomy object.
param: array|string $args See above description for the two keys values.
since: 2.3.0

get_objects_in_term( $terms, $taxonomies, $args = null )   X-Ref
Retrieve object_ids of valid taxonomy and term.

The strings of $taxonomies must exist before this function will continue. On
failure of finding a valid taxonomy, it will return an WP_Error class, kind
of like Exceptions in PHP 5, except you can't catch them. Even so, you can
still test for the WP_Error class and get the error message.

The $terms aren't checked the same as $taxonomies, but still need to exist
for $object_ids to be returned.

It is possible to change the order that object_ids is returned by either
using PHP sort family functions or using the database by using $args with
either ASC or DESC array. The value should be in the key named 'order'.

param: string|array $terms String of term or array of string values of terms that will be used
param: string|array $taxonomies String of taxonomy name or Array of string values of taxonomy names
param: array|string $args Change the order of the object_ids, either ASC or DESC
since: 2.3.0
return: WP_Error|array If the taxonomy does not exist, then WP_Error will be returned. On success

get_term($term, $taxonomy, $output = OBJECT, $filter = 'raw')   X-Ref
Get all Term data from database by Term ID.

The usage of the get_term function is to apply filters to a term object. It
is possible to get a term object from the database before applying the
filters.

$term ID must be part of $taxonomy, to get from the database. Failure, might
be able to be captured by the hooks. Failure would be the same value as $this->db
returns for the get_row method.

There are two hooks, one is specifically for each term, named 'get_term', and
the second is for the taxonomy name, 'term_$taxonomy'. Both hooks gets the
term object, and the taxonomy name as parameters. Both hooks are expected to
return a Term object.

'get_term' hook - Takes two parameters the term Object and the taxonomy name.
Must return term object. Used in get_term() as a catch-all filter for every
$term.

'get_$taxonomy' hook - Takes two parameters the term Object and the taxonomy
name. Must return term object. $taxonomy will be the taxonomy name, so for
example, if 'category', it would be 'get_category' as the filter name. Useful
for custom taxonomies or plugging into default taxonomies.

param: int|object $term If integer, will get from database. If object will apply filters and return $term.
param: string $taxonomy Taxonomy name that $term is part of.
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
since: 2.3.0
return: mixed|null|WP_Error Term Row from database. Will return null if $term is empty. If taxonomy does not

get_term_by($field, $value, $taxonomy, $output = OBJECT, $filter = 'raw')   X-Ref
Get all Term data from database by Term field and data.

Warning: $value is not escaped for 'name' $field. You must do it yourself, if
required.

The default $field is 'id', therefore it is possible to also use null for
field, but not recommended that you do so.

If $value does not exist, the return value will be false. If $taxonomy exists
and $field and $value combinations exist, the Term will be returned.

param: string $field Either 'slug', 'name', 'id', or 'tt_id'
param: string|int $value Search for this term value
param: string $taxonomy Taxonomy Name
param: string $output Constant OBJECT, ARRAY_A, or ARRAY_N
param: string $filter Optional, default is raw or no WordPress defined filter will applied.
since: 2.3.0
return: mixed Term Row from database. Will return false if $taxonomy does not exist or $term was not found.

get_term_children( $term_id, $taxonomy )   X-Ref
Merge all term children into a single array of their IDs.

This recursive function will merge all of the children of $term into the same
array of term IDs. Only useful for taxonomies which are hierarchical.

Will return an empty array if $term does not exist in $taxonomy.

param: string $term ID of Term to get children
param: string $taxonomy Taxonomy Name
since: 2.3.0
return: array|WP_Error List of Term Objects. WP_Error returned if $taxonomy does not exist

get_term_field( $field, $term, $taxonomy, $context = 'display' )   X-Ref
Get sanitized Term field.

Does checks for $term, based on the $taxonomy. The function is for contextual
reasons and for simplicity of usage. See sanitize_term_field() for more
information.

param: string $field Term field to fetch
param: int $term Term ID
param: string $taxonomy Taxonomy Name
param: string $context Optional, default is display. Look at sanitize_term_field() for available options.
since: 2.3.0
return: mixed Will return an empty string if $term is not an object or if $field is not set in $term.

get_term_to_edit( $id, $taxonomy )   X-Ref
Sanitizes Term for editing.

Return value is sanitize_term() and usage is for sanitizing the term for
editing. Function is for contextual and simplicity.

param: int|object $id Term ID or Object
param: string $taxonomy Taxonomy Name
since: 2.3.0
return: mixed|null|WP_Error Will return empty string if $term is not an object.

get_terms($taxonomies, $args = '')   X-Ref
Retrieve the terms in a given taxonomy or list of taxonomies.

You can fully inject any customizations to the query before it is sent, as
well as control the output with a filter.

The 'get_terms' filter will be called when the cache has the term and will
pass the found term along with the array of $taxonomies and array of $args.
This filter is also called before the array of terms is passed and will pass
the array of terms, along with the $taxonomies and $args.

The 'list_terms_exclusions' filter passes the compiled exclusions along with
the $args.

The 'get_terms_orderby' filter passes the ORDER BY clause for the query
along with the $args array.

The 'get_terms_fields' filter passes the fields for the SELECT query
along with the $args array.

The list of arguments that $args can contain, which will overwrite the defaults:

orderby - Default is 'name'. Can be name, count, term_group, slug or nothing
(will use term_id), Passing a custom value other than these will cause it to
order based on the custom value.

order - Default is ASC. Can use DESC.

hide_empty - Default is true. Will not return empty terms, which means
terms whose count is 0 according to the given taxonomy.

exclude - Default is an empty string.  A comma- or space-delimited string
of term ids to exclude from the return array.  If 'include' is non-empty,
'exclude' is ignored.

include - Default is an empty string.  A comma- or space-delimited string
of term ids to include in the return array.

number - The maximum number of terms to return.  Default is empty.

offset - The number by which to offset the terms query.

fields - Default is 'all', which returns an array of term objects.
If 'fields' is 'ids' or 'names', returns an array of
integers or strings, respectively.

slug - Returns terms whose "slug" matches this value. Default is empty string.

hierarchical - Whether to include terms that have non-empty descendants
(even if 'hide_empty' is set to true).

search - Returned terms' names will contain the value of 'search',
case-insensitive.  Default is an empty string.

name__like - Returned terms' names will begin with the value of 'name__like',
case-insensitive. Default is empty string.

The argument 'pad_counts', if set to true will include the quantity of a term's
children in the quantity of each term's "count" object variable.

The 'get' argument, if set to 'all' instead of its default empty string,
returns terms regardless of ancestry or whether the terms are empty.

The 'child_of' argument, when used, should be set to the integer of a term ID.  Its default
is 0.  If set to a non-zero value, all returned terms will be descendants
of that term according to the given taxonomy.  Hence 'child_of' is set to 0
if more than one taxonomy is passed in $taxonomies, because multiple taxonomies
make term ancestry ambiguous.

The 'parent' argument, when used, should be set to the integer of a term ID.  Its default is
the empty string '', which has a different meaning from the integer 0.
If set to an integer value, all returned terms will have as an immediate
ancestor the term whose ID is specified by that integer according to the given taxonomy.
The 'parent' argument is different from 'child_of' in that a term X is considered a 'parent'
of term Y only if term X is the father of term Y, not its grandfather or great-grandfather, etc.

param: string|array Taxonomy name or list of Taxonomy names
param: string|array $args The values of what to search for when returning terms
since: 2.3.0
return: array|WP_Error List of Term Objects and their children. Will return WP_Error, if any of $taxonomies do not exist.

is_term($term, $taxonomy = '', $parent = 0)   X-Ref
Check if Term exists.

Returns the index of a defined term, or 0 (false) if the term doesn't exist.

param: int|string $term The term to check
param: string $taxonomy The taxonomy name to use
param: int $parent ID of parent term under which to confine the exists search.
since: 2.3.0
return: mixed Get the term id or Term Object, if exists.

sanitize_term_slug( $title, $taxonomy = '', $term_id = 0 )   X-Ref
No description

format_to_edit( $text )   X-Ref
No description

sanitize_term($term, $taxonomy, $context = 'display')   X-Ref
Sanitize Term all fields

Relies on sanitize_term_field() to sanitize the term. The difference
is that this function will sanitize <strong>all</strong> fields. The
context is based on sanitize_term_field().

The $term is expected to be either an array or an object.

param: array|object $term The term to check
param: string $taxonomy The taxonomy name to use
param: string $context Default is 'display'.
since: 2.3.0
return: array|object Term with all fields sanitized

sanitize_term_field($field, $value, $term_id, $taxonomy, $context)   X-Ref
Cleanse the field value in the term based on the context.

Passing a term field value through the function should be assumed to have
cleansed the value for whatever context the term field is going to be used.

If no context or an unsupported context is given, then default filters will
be applied.

There are enough filters for each context to support a custom filtering
without creating your own filter function. Simply create a function that
hooks into the filter you need.

param: string $field Term field to sanitize
param: string $value Search for this term value
param: int $term_id Term ID
param: string $taxonomy Taxonomy Name
param: string $context Either edit, db, display, attribute, or js.
since: 2.3.0
return: mixed sanitized field

count_terms( $taxonomy, $args = array()   X-Ref
Count how many terms are in Taxonomy.

Default $args is 'ignore_empty' which can be <code>'ignore_empty=true'</code>
or <code>array('ignore_empty' => true);</code>.

param: string $taxonomy Taxonomy name
param: array|string $args Overwrite defaults
since: 2.3.0
return: int How many terms are in $taxonomy

delete_object_term_relationships( $object_id, $taxonomies )   X-Ref
Will unlink the term from the taxonomy.

Will remove the term's relationship to the taxonomy, not the term or taxonomy
itself. The term and taxonomy will still exist. Will require the term's
object ID to perform the operation.

param: int $object_id The term Object Id that refers to the term
param: string|array $taxonomy List of Taxonomy Names or single Taxonomy name.
since: 2.3.0

delete_term( $term, $taxonomy, $args = array()   X-Ref
Removes a term from the database.

If the term is a parent of other terms, then the children will be updated to
that term's parent.

The $args 'default' will only override the terms found, if there is only one
term found. Any other and the found terms are used.

The $args 'force_default' will force the term supplied as default to be
assigned even if the object was not going to be termless
param: int $term Term ID
param: string $taxonomy Taxonomy Name
param: array|string $args Optional. Change 'default' term id and override found term ids.
since: 2.3.0
return: bool|WP_Error Returns false if not term; true if completes delete action.

get_object_terms($object_ids, $taxonomies, $args = array()   X-Ref
Retrieves the terms associated with the given object(s), in the supplied taxonomies.

The following information has to do the $args parameter and for what can be
contained in the string or array of that parameter, if it exists.

The first argument is called, 'orderby' and has the default value of 'name'.
The other value that is supported is 'count'.

The second argument is called, 'order' and has the default value of 'ASC'.
The only other value that will be acceptable is 'DESC'.

The final argument supported is called, 'fields' and has the default value of
'all'. There are multiple other options that can be used instead. Supported
values are as follows: 'all', 'ids', 'names', and finally
'all_with_object_id'.

The fields argument also decides what will be returned. If 'all' or
'all_with_object_id' is choosen or the default kept intact, then all matching
terms objects will be returned. If either 'ids' or 'names' is used, then an
array of all matching term ids or term names will be returned respectively.

param: int|array $object_id The id of the object(s) to retrieve.
param: string|array $taxonomies The taxonomies to retrieve terms from.
param: array|string $args Change what is returned
since: 2.3.0
return: array|WP_Error The requested term data or empty array if no terms found. WP_Error if $taxonomy does not exist.

insert_term( $term, $taxonomy, $args = array()   X-Ref
Adds a new term to the database. Optionally marks it as an alias of an existing term.

Error handling is assigned for the nonexistance of the $taxonomy and $term
parameters before inserting. If both the term id and taxonomy exist
previously, then an array will be returned that contains the term id and the
contents of what is returned. The keys of the array are 'term_id' and
'term_taxonomy_id' containing numeric values.

It is assumed that the term does not yet exist or the above will apply. The
term will be first added to the term table and then related to the taxonomy
if everything is well. If everything is correct, then several actions will be
run prior to a filter and then several actions will be run after the filter
is run.

The arguments decide how the term is handled based on the $args parameter.
The following is a list of the available overrides and the defaults.

'alias_of'. There is no default, but if added, expected is the slug that the
term will be an alias of. Expected to be a string.

'description'. There is no default. If exists, will be added to the database
along with the term. Expected to be a string.

'parent'. Expected to be numeric and default is 0 (zero). Will assign value
of 'parent' to the term.

'slug'. Expected to be a string. There is no default.

If 'slug' argument exists then the slug will be checked to see if it is not
a valid term. If that check succeeds (it is not a valid term), then it is
added and the term id is given. If it fails, then a check is made to whether
the taxonomy is hierarchical and the parent argument is not empty. If the
second check succeeds, the term will be inserted and the term id will be
given.

param: int|string $term The term to add or update.
param: string $taxonomy The taxonomy to which to add the term
param: array|string $args Change the values of the inserted term
since: 2.3.0
return: array|WP_Error The Term ID and Term Taxonomy ID

set_object_terms($object_id, $terms, $taxonomy, $append = false)   X-Ref
Create Term and Taxonomy Relationships.

Relates an object (post, link etc) to a term and taxonomy type. Creates the
term and taxonomy relationship if it doesn't already exist. Creates a term if
it doesn't exist (using the slug).

A relationship means that the term is grouped in or belongs to the taxonomy.
A term has no meaning until it is given context by defining which taxonomy it
exists under.

param: int $object_id The object to relate to.
param: array|int|string $term The slug or id of the term, will replace all existing
param: array|string $taxonomy The context in which to relate the term to the object.
param: bool $append If false will delete difference of terms.
since: 2.3.0
return: array|WP_Error Affected Term IDs

unique_term_slug($slug, $term)   X-Ref
Will make slug unique, if it isn't already.

The $slug has to be unique global to every taxonomy, meaning that one
taxonomy term can't have a matching slug with another taxonomy term. Each
slug has to be globally unique for every taxonomy.

The way this works is that if the taxonomy that the term belongs to is
heirarchical and has a parent, it will append that parent to the $slug.

If that still doesn't return an unique slug, then it try to append a number
until it finds a number that is truely unique.

The only purpose for $term is for appending a parent, if one exists.

param: string $slug The string that will be tried for a unique slug
param: object $term The term object that the $slug will belong too
since: 2.3.0
return: string Will return a true unique slug.

update_term( $term_id, $taxonomy, $args = array()   X-Ref
Update term based on arguments provided.

The $args will indiscriminately override all values with the same field name.
Care must be taken to not override important information need to update or
update will fail (or perhaps create a new term, neither would be acceptable).

Defaults will set 'alias_of', 'description', 'parent', and 'slug' if not
defined in $args already.

'alias_of' will create a term group, if it doesn't already exist, and update
it for the $term.

If the 'slug' argument in $args is missing, then the 'name' in $args will be
used. It should also be noted that if you set 'slug' and it isn't unique then
a WP_Error will be passed back. If you don't pass any slug, then a unique one
will be created for you.

For what can be overrode in $args, check the term scheme can contain and stay
away from the term keys.

param: int $term_id The ID of the term
param: string $taxonomy The context in which to relate the term to the object.
param: array|string $args Overwrite term field values
since: 2.3.0
return: array|WP_Error Returns Term ID and Taxonomy Term ID

defer_term_counting($defer=NULL)   X-Ref
Enable or disable term counting.

param: bool $defer Optional. Enable if true, disable if false.
since: 2.5.0
return: bool Whether term counting is enabled or disabled.

update_term_count( $terms, $taxonomy, $do_deferred=false )   X-Ref
Updates the amount of terms in taxonomy.

If there is a taxonomy callback applied, then it will be called for updating
the count.

The default action is to count what the amount of terms have the relationship
of term ID. Once that is done, then update the database.

param: int|array $terms The ID of the terms
param: string $taxonomy The context of the term.
since: 2.3.0
return: bool If no terms will return false, and if successful will return true.

update_term_count_now( $terms, $taxonomy )   X-Ref
Perform term count update immediately.

param: array $terms The term_taxonomy_id of terms to update.
param: string $taxonomy The context of the term.
since: 2.5.0
return: bool Always true when complete.

clean_object_term_cache($object_ids, $object_type)   X-Ref
Removes the taxonomy relationship to terms from the cache.

Will remove the entire taxonomy relationship containing term $object_id. The
term IDs have to exist within the taxonomy $object_type for the deletion to
take place.

param: int|array $object_ids Single or list of term object ID(s)
param: string $object_type The taxonomy object type
since: 2.3

clean_term_cache($ids, $taxonomy = '')   X-Ref
Will remove all of the term ids from the cache.

param: int|array $ids Single or list of Term IDs
param: string $taxonomy Can be empty and will assume tt_ids, else will use for context.
since: 2.3.0

get_object_term_cache($id, $taxonomy)   X-Ref
Retrieves the taxonomy relationship to the term object id.

param: int|array $id Term object ID
param: string $taxonomy Taxonomy Name
since: 2.3.0
return: bool|array Empty array if $terms found, but not $taxonomy. False if nothing is in cache for $taxonomy and $id.

update_object_term_cache($object_ids, $object_type)   X-Ref
Updates the cache for Term ID(s).

Will only update the cache for terms not already cached.

The $object_ids expects that the ids be separated by commas, if it is a
string.

It should be noted that update_object_term_cache() is very time extensive. It
is advised that the function is not called very often or at least not for a
lot of terms that exist in a lot of taxonomies. The amount of time increases
for each term and it also increases for each taxonomy the term belongs to.

param: string|array $object_ids Single or list of term object ID(s)
param: string $object_type The taxonomy object type
since: 2.3.0
return: null|bool Null value is given with empty $object_ids. False if

update_term_cache($terms, $taxonomy = '')   X-Ref
Updates Terms to Taxonomy in cache.

param: array $terms List of Term objects to change
param: string $taxonomy Optional. Update Term to this taxonomy in cache
since: 2.3.0

_get_term_hierarchy($taxonomy)   X-Ref
Retrieves children of taxonomy as Term IDs.

param: string $taxonomy Taxonomy Name
since: 2.3.0
return: array Empty if $taxonomy isn't hierarachical or returns children as Term IDs.

_get_term_children($term_id, $terms, $taxonomy)   X-Ref
Get the subset of $terms that are descendants of $term_id.

If $terms is an array of objects, then _get_term_children returns an array of objects.
If $terms is an array of IDs, then _get_term_children returns an array of IDs.

param: int $term_id The ancestor term: all returned terms should be descendants of $term_id.
param: array $terms The set of terms---either an array of term objects or term IDs---from which those that are descendants of $term_id will be chosen.
param: string $taxonomy The taxonomy which determines the hierarchy of the terms.
since: 2.3.0
return: array The subset of $terms that are descendants of $term_id.

_pad_term_counts(&$terms, $taxonomy)   X-Ref
Add count of children to parent count.

Recalculates term counts by including items from child terms. Assumes all
relevant children are already in the $terms argument.

param: array $terms List of Term IDs
param: string $taxonomy Term Context
since: 2.3
return: null Will break from function if conditions are not met.

is_object_in_term( $object_id, $taxonomy, $terms = null )   X-Ref
Determine if the given object is associated with any of the given terms.

The given terms are checked against the object's terms' term_ids, names and slugs.
Terms given as integers will only be checked against the object's terms' term_ids.
If no terms are given, determines if object is associated with any terms in the given taxonomy.

param: int $object_id.  ID of the object (post ID, link ID, ...)
param: string $taxonomy.  Single taxonomy name
param: int|string|array $terms Optional.  Term term_id, name, slug or array of said
since: 2.7.0
return: bool|WP_Error. WP_Error on input error.

get_children_cache( $taxonomy )   X-Ref
No description

set_children_cache( $taxonomy, $children )   X-Ref
No description

delete_children_cache( $taxonomy )   X-Ref
No description



Generated: Fri Oct 4 01:00:55 2024 Cross-referenced by PHPXref 0.7.1