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
InstanceId.php
78 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Instance ID 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\Shortcode\Extension; |
| 17 | |
| 18 | /** |
| 19 | * Instance ID Query Part extension |
| 20 | */ |
| 21 | class InstanceId extends Extension { |
| 22 | /** |
| 23 | * The attribute for this Query Part. |
| 24 | * |
| 25 | * @since 4.0.0 |
| 26 | * @var string |
| 27 | */ |
| 28 | public $attribute_name = 'instance-id'; |
| 29 | |
| 30 | /** |
| 31 | * The instance ID. |
| 32 | * |
| 33 | * @var string |
| 34 | */ |
| 35 | public $instance_id = ''; |
| 36 | |
| 37 | /** |
| 38 | * Sanitize the shortcode attribute. |
| 39 | * |
| 40 | * The value ends up in an HTML `id` and in a URL fragment, so restrict it to |
| 41 | * characters valid in both. Spaces or a `#` would otherwise produce a broken id |
| 42 | * and a dead "back to top" anchor. |
| 43 | * |
| 44 | * @since 4.5.0 |
| 45 | * @param mixed $value The value of the shortcode attribute. |
| 46 | * @param array $attributes The complete set of shortcode attributes. |
| 47 | * @return string The sanitized instance ID. |
| 48 | */ |
| 49 | public function sanitize_attribute( $value, array $attributes ) { |
| 50 | return sanitize_html_class( (string) $value ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Update the query with this extension's additional configuration. |
| 55 | * |
| 56 | * @param \eslin87\AlphaListing\Query $query The query. |
| 57 | * @param string $display The display/query type. |
| 58 | * @param string $key The name of the attribute. |
| 59 | * @param mixed $value The shortcode attribute value. |
| 60 | * @param array $attributes The complete set of shortcode attributes. |
| 61 | * @return mixed The updated query. |
| 62 | */ |
| 63 | public function shortcode_query( $query, string $display, string $key, $value, array $attributes ) { |
| 64 | $this->instance_id = sanitize_html_class( (string) $value ); |
| 65 | $this->add_hook( 'filter', 'alphalisting_instance_id', array( $this, 'return_instance_id' ), 10, 1 ); |
| 66 | return $query; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Return the ID for this instance. |
| 71 | * |
| 72 | * @return string |
| 73 | */ |
| 74 | public function return_instance_id(): string { |
| 75 | return $this->instance_id; |
| 76 | } |
| 77 | } |
| 78 |