PluginProbe ʕ •ᴥ•ʔ
AlphaListing / 4.5.0
AlphaListing v4.5.0
4.5.0 trunk 4.3.4 4.3.5 4.3.6 4.3.7 4.4.0
alphalisting / src / Shortcode / QueryParts / ParentTermSlugOrId.php
alphalisting / src / Shortcode / QueryParts Last commit date
Alphabet.php 2 weeks ago BackToTop.php 2 weeks ago ColumnGap.php 2 weeks ago ColumnWidth.php 2 weeks ago Columns.php 2 weeks ago CssLengthCommon.php 2 weeks ago ExcludePosts.php 2 weeks ago ExcludeTerms.php 2 weeks ago GroupBy.php 2 weeks ago HideEmptyTerms.php 2 weeks ago HideEmpty_Deprecated.php 2 weeks ago InstanceId.php 2 weeks ago ParentPost.php 2 weeks ago ParentTermCommon.php 2 weeks ago ParentTermId.php 2 weeks ago ParentTermSlugOrId.php 2 weeks ago PostType.php 2 weeks ago PostsTerms.php 2 weeks ago SymbolsFirst.php 2 weeks ago Taxonomy.php 2 weeks ago TermsCommon.php 2 weeks ago TermsTerms.php 2 weeks ago
ParentTermSlugOrId.php
65 lines
1 <?php
2 /**
3 * Parent Term Query Part.
4 *
5 * @package alphalisting
6 */
7
8 declare(strict_types=1);
9
10 namespace eslin87\AlphaListing\Shortcode\QueryParts;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 use \eslin87\AlphaListing\Strings;
17
18 /**
19 * Parent Term Slug Or ID implementation.
20 */
21 class ParentTermSlugOrId extends ParentTermCommon {
22 /**
23 * The attribute for this Query Part.
24 *
25 * @since 4.0.0
26 * @var string
27 */
28 public $attribute_name = 'parent-term';
29
30 /**
31 * Update the query with this extension's additional configuration.
32 *
33 * @param \eslin87\AlphaListing\Query $query The query.
34 * @param string $display The display/query type.
35 * @param string $key The name of the attribute.
36 * @param mixed $value The shortcode attribute value.
37 * @param array $attributes The complete set of shortcode attributes.
38 * @return mixed The updated query.
39 */
40 public function shortcode_query_for_display_and_attribute( $query, string $display, string $key, $value, array $attributes ) {
41 if ( is_numeric( $value ) ) {
42 $parent_id = intval( $value );
43 } else {
44 $parent_id = -1;
45 $taxonomies = array( 'category' );
46 if ( isset( $attributes['taxonomy'] ) ) {
47 $taxonomies = Strings::maybe_mb_split( ',', $attributes['taxonomy'] );
48 }
49
50 foreach ( $taxonomies as $taxonomy ) {
51 // get_term_by() returns \WP_Term|false|null -- null for an unregistered
52 // taxonomy, which slips past a `false !==` check and leaves $parent_id
53 // null, fatalling on the int parameter of shortcode_query_with_parent_id().
54 $parent_term = get_term_by( 'slug', $value, $taxonomy );
55 if ( $parent_term instanceof \WP_Term ) {
56 $parent_id = $parent_term->term_id;
57 break;
58 }
59 }
60 }
61
62 return $this->shortcode_query_with_parent_id( $query, $parent_id, $attributes );
63 }
64 }
65