Edit File by line
/home/barbar84/www/wp-inclu...
File: class-wp-term.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Taxonomy API: WP_Term class
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Taxonomy
[5] Fix | Delete
* @since 4.4.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/**
[9] Fix | Delete
* Core class used to implement the WP_Term object.
[10] Fix | Delete
*
[11] Fix | Delete
* @since 4.4.0
[12] Fix | Delete
*
[13] Fix | Delete
* @property-read object $data Sanitized term data.
[14] Fix | Delete
*/
[15] Fix | Delete
final class WP_Term {
[16] Fix | Delete
[17] Fix | Delete
/**
[18] Fix | Delete
* Term ID.
[19] Fix | Delete
*
[20] Fix | Delete
* @since 4.4.0
[21] Fix | Delete
* @var int
[22] Fix | Delete
*/
[23] Fix | Delete
public $term_id;
[24] Fix | Delete
[25] Fix | Delete
/**
[26] Fix | Delete
* The term's name.
[27] Fix | Delete
*
[28] Fix | Delete
* @since 4.4.0
[29] Fix | Delete
* @var string
[30] Fix | Delete
*/
[31] Fix | Delete
public $name = '';
[32] Fix | Delete
[33] Fix | Delete
/**
[34] Fix | Delete
* The term's slug.
[35] Fix | Delete
*
[36] Fix | Delete
* @since 4.4.0
[37] Fix | Delete
* @var string
[38] Fix | Delete
*/
[39] Fix | Delete
public $slug = '';
[40] Fix | Delete
[41] Fix | Delete
/**
[42] Fix | Delete
* The term's term_group.
[43] Fix | Delete
*
[44] Fix | Delete
* @since 4.4.0
[45] Fix | Delete
* @var int
[46] Fix | Delete
*/
[47] Fix | Delete
public $term_group = '';
[48] Fix | Delete
[49] Fix | Delete
/**
[50] Fix | Delete
* Term Taxonomy ID.
[51] Fix | Delete
*
[52] Fix | Delete
* @since 4.4.0
[53] Fix | Delete
* @var int
[54] Fix | Delete
*/
[55] Fix | Delete
public $term_taxonomy_id = 0;
[56] Fix | Delete
[57] Fix | Delete
/**
[58] Fix | Delete
* The term's taxonomy name.
[59] Fix | Delete
*
[60] Fix | Delete
* @since 4.4.0
[61] Fix | Delete
* @var string
[62] Fix | Delete
*/
[63] Fix | Delete
public $taxonomy = '';
[64] Fix | Delete
[65] Fix | Delete
/**
[66] Fix | Delete
* The term's description.
[67] Fix | Delete
*
[68] Fix | Delete
* @since 4.4.0
[69] Fix | Delete
* @var string
[70] Fix | Delete
*/
[71] Fix | Delete
public $description = '';
[72] Fix | Delete
[73] Fix | Delete
/**
[74] Fix | Delete
* ID of a term's parent term.
[75] Fix | Delete
*
[76] Fix | Delete
* @since 4.4.0
[77] Fix | Delete
* @var int
[78] Fix | Delete
*/
[79] Fix | Delete
public $parent = 0;
[80] Fix | Delete
[81] Fix | Delete
/**
[82] Fix | Delete
* Cached object count for this term.
[83] Fix | Delete
*
[84] Fix | Delete
* @since 4.4.0
[85] Fix | Delete
* @var int
[86] Fix | Delete
*/
[87] Fix | Delete
public $count = 0;
[88] Fix | Delete
[89] Fix | Delete
/**
[90] Fix | Delete
* Stores the term object's sanitization level.
[91] Fix | Delete
*
[92] Fix | Delete
* Does not correspond to a database field.
[93] Fix | Delete
*
[94] Fix | Delete
* @since 4.4.0
[95] Fix | Delete
* @var string
[96] Fix | Delete
*/
[97] Fix | Delete
public $filter = 'raw';
[98] Fix | Delete
[99] Fix | Delete
/**
[100] Fix | Delete
* Retrieve WP_Term instance.
[101] Fix | Delete
*
[102] Fix | Delete
* @since 4.4.0
[103] Fix | Delete
*
[104] Fix | Delete
* @global wpdb $wpdb WordPress database abstraction object.
[105] Fix | Delete
*
[106] Fix | Delete
* @param int $term_id Term ID.
[107] Fix | Delete
* @param string $taxonomy Optional. Limit matched terms to those matching `$taxonomy`. Only used for
[108] Fix | Delete
* disambiguating potentially shared terms.
[109] Fix | Delete
* @return WP_Term|WP_Error|false Term object, if found. WP_Error if `$term_id` is shared between taxonomies and
[110] Fix | Delete
* there's insufficient data to distinguish which term is intended.
[111] Fix | Delete
* False for other failures.
[112] Fix | Delete
*/
[113] Fix | Delete
public static function get_instance( $term_id, $taxonomy = null ) {
[114] Fix | Delete
global $wpdb;
[115] Fix | Delete
[116] Fix | Delete
$term_id = (int) $term_id;
[117] Fix | Delete
if ( ! $term_id ) {
[118] Fix | Delete
return false;
[119] Fix | Delete
}
[120] Fix | Delete
[121] Fix | Delete
$_term = wp_cache_get( $term_id, 'terms' );
[122] Fix | Delete
[123] Fix | Delete
// If there isn't a cached version, hit the database.
[124] Fix | Delete
if ( ! $_term || ( $taxonomy && $taxonomy !== $_term->taxonomy ) ) {
[125] Fix | Delete
// Any term found in the cache is not a match, so don't use it.
[126] Fix | Delete
$_term = false;
[127] Fix | Delete
[128] Fix | Delete
// Grab all matching terms, in case any are shared between taxonomies.
[129] Fix | Delete
$terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.*, tt.* FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE t.term_id = %d", $term_id ) );
[130] Fix | Delete
if ( ! $terms ) {
[131] Fix | Delete
return false;
[132] Fix | Delete
}
[133] Fix | Delete
[134] Fix | Delete
// If a taxonomy was specified, find a match.
[135] Fix | Delete
if ( $taxonomy ) {
[136] Fix | Delete
foreach ( $terms as $match ) {
[137] Fix | Delete
if ( $taxonomy === $match->taxonomy ) {
[138] Fix | Delete
$_term = $match;
[139] Fix | Delete
break;
[140] Fix | Delete
}
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
// If only one match was found, it's the one we want.
[144] Fix | Delete
} elseif ( 1 === count( $terms ) ) {
[145] Fix | Delete
$_term = reset( $terms );
[146] Fix | Delete
[147] Fix | Delete
// Otherwise, the term must be shared between taxonomies.
[148] Fix | Delete
} else {
[149] Fix | Delete
// If the term is shared only with invalid taxonomies, return the one valid term.
[150] Fix | Delete
foreach ( $terms as $t ) {
[151] Fix | Delete
if ( ! taxonomy_exists( $t->taxonomy ) ) {
[152] Fix | Delete
continue;
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
// Only hit if we've already identified a term in a valid taxonomy.
[156] Fix | Delete
if ( $_term ) {
[157] Fix | Delete
return new WP_Error( 'ambiguous_term_id', __( 'Term ID is shared between multiple taxonomies' ), $term_id );
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
$_term = $t;
[161] Fix | Delete
}
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
if ( ! $_term ) {
[165] Fix | Delete
return false;
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
// Don't return terms from invalid taxonomies.
[169] Fix | Delete
if ( ! taxonomy_exists( $_term->taxonomy ) ) {
[170] Fix | Delete
return new WP_Error( 'invalid_taxonomy', __( 'Invalid taxonomy.' ) );
[171] Fix | Delete
}
[172] Fix | Delete
[173] Fix | Delete
$_term = sanitize_term( $_term, $_term->taxonomy, 'raw' );
[174] Fix | Delete
[175] Fix | Delete
// Don't cache terms that are shared between taxonomies.
[176] Fix | Delete
if ( 1 === count( $terms ) ) {
[177] Fix | Delete
wp_cache_add( $term_id, $_term, 'terms' );
[178] Fix | Delete
}
[179] Fix | Delete
}
[180] Fix | Delete
[181] Fix | Delete
$term_obj = new WP_Term( $_term );
[182] Fix | Delete
$term_obj->filter( $term_obj->filter );
[183] Fix | Delete
[184] Fix | Delete
return $term_obj;
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
/**
[188] Fix | Delete
* Constructor.
[189] Fix | Delete
*
[190] Fix | Delete
* @since 4.4.0
[191] Fix | Delete
*
[192] Fix | Delete
* @param WP_Term|object $term Term object.
[193] Fix | Delete
*/
[194] Fix | Delete
public function __construct( $term ) {
[195] Fix | Delete
foreach ( get_object_vars( $term ) as $key => $value ) {
[196] Fix | Delete
$this->$key = $value;
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
/**
[201] Fix | Delete
* Sanitizes term fields, according to the filter type provided.
[202] Fix | Delete
*
[203] Fix | Delete
* @since 4.4.0
[204] Fix | Delete
*
[205] Fix | Delete
* @param string $filter Filter context. Accepts 'edit', 'db', 'display', 'attribute', 'js', 'rss', or 'raw'.
[206] Fix | Delete
*/
[207] Fix | Delete
public function filter( $filter ) {
[208] Fix | Delete
sanitize_term( $this, $this->taxonomy, $filter );
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* Converts an object to array.
[213] Fix | Delete
*
[214] Fix | Delete
* @since 4.4.0
[215] Fix | Delete
*
[216] Fix | Delete
* @return array Object as array.
[217] Fix | Delete
*/
[218] Fix | Delete
public function to_array() {
[219] Fix | Delete
return get_object_vars( $this );
[220] Fix | Delete
}
[221] Fix | Delete
[222] Fix | Delete
/**
[223] Fix | Delete
* Getter.
[224] Fix | Delete
*
[225] Fix | Delete
* @since 4.4.0
[226] Fix | Delete
*
[227] Fix | Delete
* @param string $key Property to get.
[228] Fix | Delete
* @return mixed Property value.
[229] Fix | Delete
*/
[230] Fix | Delete
public function __get( $key ) {
[231] Fix | Delete
switch ( $key ) {
[232] Fix | Delete
case 'data':
[233] Fix | Delete
$data = new stdClass();
[234] Fix | Delete
$columns = array( 'term_id', 'name', 'slug', 'term_group', 'term_taxonomy_id', 'taxonomy', 'description', 'parent', 'count' );
[235] Fix | Delete
foreach ( $columns as $column ) {
[236] Fix | Delete
$data->{$column} = isset( $this->{$column} ) ? $this->{$column} : null;
[237] Fix | Delete
}
[238] Fix | Delete
[239] Fix | Delete
return sanitize_term( $data, $data->taxonomy, 'raw' );
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function