class-acf-location-block.php
1 year ago
class-acf-location-options-page.php
1 year ago
index.php
1 year ago
class-acf-location-block.php
103 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_Block' ) ) : |
| 8 | |
| 9 | class ACF_Location_Block extends ACF_Location { |
| 10 | |
| 11 | /** |
| 12 | * Initializes props. |
| 13 | * |
| 14 | * @date 5/03/2014 |
| 15 | * @since 5.0.0 |
| 16 | * |
| 17 | * @param void |
| 18 | * @return void |
| 19 | */ |
| 20 | public function initialize() { |
| 21 | $this->name = 'block'; |
| 22 | $this->label = __( 'Block', 'acf' ); |
| 23 | $this->category = 'forms'; |
| 24 | $this->object_type = 'block'; |
| 25 | |
| 26 | add_filter( 'acf/field_group/list_table_classes', array( $this, 'field_group_list_table_classes' ), 10, 3 ); |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Matches the provided rule against the screen args returning a bool result. |
| 31 | * |
| 32 | * @date 9/4/20 |
| 33 | * @since 5.9.0 |
| 34 | * |
| 35 | * @param array $rule The location rule. |
| 36 | * @param array $screen The screen args. |
| 37 | * @param array $field_group The field group settings. |
| 38 | * @return boolean |
| 39 | */ |
| 40 | public function match( $rule, $screen, $field_group ) { |
| 41 | |
| 42 | // Check screen args. |
| 43 | if ( isset( $screen['block'] ) ) { |
| 44 | $block = $screen['block']; |
| 45 | } else { |
| 46 | return false; |
| 47 | } |
| 48 | |
| 49 | // Compare rule against $block. |
| 50 | return $this->compare_to_rule( $block, $rule ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Returns an array of possible values for this rule type. |
| 55 | * |
| 56 | * @date 9/4/20 |
| 57 | * @since 5.9.0 |
| 58 | * |
| 59 | * @param array $rule A location rule. |
| 60 | * @return array |
| 61 | */ |
| 62 | public function get_values( $rule ) { |
| 63 | $choices = array(); |
| 64 | |
| 65 | // Append block types. |
| 66 | $blocks = acf_get_block_types(); |
| 67 | if ( $blocks ) { |
| 68 | $choices['all'] = __( 'All', 'acf' ); |
| 69 | foreach ( $blocks as $block ) { |
| 70 | $choices[ $block['name'] ] = $block['title']; |
| 71 | } |
| 72 | } else { |
| 73 | $choices[''] = __( 'No block types exist', 'acf' ); |
| 74 | } |
| 75 | |
| 76 | // Return choices. |
| 77 | return $choices; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Adds block-specific classes to field groups in the Field Groups list table. |
| 82 | * |
| 83 | * @since 6.2.8 |
| 84 | * |
| 85 | * @param array $classes An array of the classes used by the field group. |
| 86 | * @param array $css_class An array of additional classes added to the field group. |
| 87 | * @param integer $post_id The ID of the field group. |
| 88 | * @return array |
| 89 | */ |
| 90 | public function field_group_list_table_classes( $classes, $css_class, $post_id ) { |
| 91 | // Add a CSS class if the field group has a block location. |
| 92 | if ( acf_field_group_has_location_type( $post_id, 'block' ) ) { |
| 93 | $classes[] = 'acf-has-block-location'; |
| 94 | } |
| 95 | |
| 96 | return $classes; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | // initialize |
| 101 | acf_register_location_type( 'ACF_Location_Block' ); |
| 102 | endif; // class_exists check |
| 103 |