Code Duplication    Length = 23-29 lines in 2 locations

src/includes/class-wordlift-entity-service.php 1 location

@@ 442-470 (lines=29) @@
439
	 *
440
	 * @return array The arguments for a `get_posts` call.
441
	 */
442
	public static function add_criterias( $args ) {
443
444
		// Build an optimal tax-query.
445
		$tax_query = array(
446
			'relation' => 'AND',
447
			array(
448
				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
449
				'operator' => 'EXISTS',
450
			),
451
			array(
452
				'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
453
				'field'    => 'slug',
454
				'terms'    => 'article',
455
				'operator' => 'NOT IN',
456
			),
457
		);
458
459
		return $args + array(
460
				'post_type' => Wordlift_Entity_Service::valid_entity_post_types(),
461
				// Since 3.17.0: should this be faster?
462
				'tax_query' => $tax_query,
463
				//				'tax_query' => array(
464
				//					array(
465
				//						'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
466
				//						'terms'    => self::get_entity_terms(),
467
				//					),
468
				//				),
469
			);
470
	}
471
472
//	/**
473
//	 * Get the entity terms IDs which represent an entity.

src/includes/class-wordlift-publisher-service.php 1 location

@@ 48-70 (lines=23) @@
45
	 *
46
	 * @return int The number of potential publishers.
47
	 */
48
	public function count() {
49
50
		// Search for entities which are either a Person
51
		// or Organization.
52
53
		// Get only the ids as all we need is the count.
54
		$entities = get_posts( array(
55
			'post_type'      => Wordlift_Entity_Service::valid_entity_post_types(),
56
			'post_status'    => 'publish',
57
			'posts_per_page' => - 1,
58
			'tax_query'      => array(
59
				array(
60
					'taxonomy' => Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME,
61
					'field'    => 'slug',
62
					'terms'    => array( 'organization', 'person' ),
63
				),
64
			),
65
			'fields'         => 'ids',
66
		) );
67
68
		// Finally return the count.
69
		return count( $entities );
70
	}
71
72
	/**
73
	 * Search SQL filter for matching against post title only.