WP_Term.php
1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace FakerPress\Provider;
use Faker\Provider\Base;
use FakerPress;
class WP_Term extends Base {
public function name( $qty = 4 ) {
$qty = FakerPress\Utils::instance()->get_qty_from_range( $qty );
$name = $this->generator->sentence( $qty );
// This removes the last dot on the end of the sentence
$name = rtrim( $name, '.' );
return $name;
}
public function taxonomy( $taxonomies = [ 'category', 'post_tag' ], $args = [] ) {
if ( empty( $taxonomies ) ){
// Merge the returned terms to those provided
$taxonomies = get_taxonomies( $args, 'names' );
}
return $this->generator->randomElement( (array) $taxonomies );
}
public function description( $min = 5, $max = 50 ) {
if ( is_array( $min ) ){
$description = $this->generator->randomElement( $min );
} else {
// Not sure if this is the best approach, but it will work no metter what...
if ( ! is_numeric( $min ) ){
$min = 5;
}
if ( ! is_numeric( $max ) ){
$max = 50;
}
$description = $this->generator->sentence( $this->generator->numberBetween( $min, $max ) );
// This removes the last dot on the end of the sentence
$description = substr( $description, 0, strlen( $description ) - 1 );
}
return $description;
}
public function parent_term( $terms = [], $taxonomies = [], $args = [] ) {
if ( ! empty( $taxonomies ) ){
// We only need the ids to be returned
$args['fields'] = 'ids';
// Merge the returned terms to the one provided
$terms = array_merge( (array) $terms, get_terms( $taxonomies, $args ) );
}
return $this->generator->randomElement( (array) $terms );
}
// For now I think we should omit the slug, since it's auto-gen, but we need to figure a way to do it later
/*
public function slug(){
return $slug;
}
*/
}