abstract-acf-legacy-location.php
1 year ago
abstract-acf-location.php
1 year ago
class-acf-location-attachment.php
1 year ago
class-acf-location-block.php
1 year ago
class-acf-location-comment.php
1 year ago
class-acf-location-current-user-role.php
1 year ago
class-acf-location-current-user.php
1 year ago
class-acf-location-nav-menu-item.php
1 year ago
class-acf-location-nav-menu.php
1 year ago
class-acf-location-options-page.php
1 year ago
class-acf-location-page-parent.php
1 year ago
class-acf-location-page-template.php
1 year ago
class-acf-location-page-type.php
1 year ago
class-acf-location-page.php
1 year ago
class-acf-location-post-category.php
1 year ago
class-acf-location-post-format.php
1 year ago
class-acf-location-post-status.php
1 year ago
class-acf-location-post-taxonomy.php
1 year ago
class-acf-location-post-template.php
1 year ago
class-acf-location-post-type.php
1 year ago
class-acf-location-post.php
1 year ago
class-acf-location-taxonomy.php
1 year ago
class-acf-location-user-form.php
1 year ago
class-acf-location-user-role.php
1 year ago
class-acf-location-widget.php
1 year ago
index.php
1 year ago
class-acf-location-attachment.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; // Exit if accessed directly |
| 5 | } |
| 6 | |
| 7 | if ( ! class_exists( 'ACF_Location_Attachment' ) ) : |
| 8 | |
| 9 | class ACF_Location_Attachment extends ACF_Location { |
| 10 | |
| 11 | |
| 12 | /** |
| 13 | * Initializes props. |
| 14 | * |
| 15 | * @date 5/03/2014 |
| 16 | * @since ACF 5.0.0 |
| 17 | * |
| 18 | * @return void |
| 19 | */ |
| 20 | public function initialize() { |
| 21 | $this->name = 'attachment'; |
| 22 | $this->label = __( 'Attachment', 'secure-custom-fields' ); |
| 23 | $this->category = 'forms'; |
| 24 | $this->object_type = 'attachment'; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Matches the provided rule against the screen args returning a bool result. |
| 29 | * |
| 30 | * @date 9/4/20 |
| 31 | * @since ACF 5.9.0 |
| 32 | * |
| 33 | * @param array $rule The location rule. |
| 34 | * @param array $screen The screen args. |
| 35 | * @param array $field_group The field group settings. |
| 36 | * @return boolean |
| 37 | */ |
| 38 | public function match( $rule, $screen, $field_group ) { |
| 39 | |
| 40 | // Check screen args. |
| 41 | if ( isset( $screen['attachment'] ) ) { |
| 42 | $attachment = $screen['attachment']; |
| 43 | } else { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | // Get attachment mime type |
| 48 | $mime_type = get_post_mime_type( $attachment ); |
| 49 | |
| 50 | // Allow for unspecific mim_type matching such as "image" or "video". |
| 51 | if ( ! strpos( $rule['value'], '/' ) ) { |
| 52 | |
| 53 | // Explode mime_type into bits ([0] => type, [1] => subtype) and match type. |
| 54 | $bits = explode( '/', $mime_type ); |
| 55 | if ( $bits[0] === $rule['value'] ) { |
| 56 | $mime_type = $rule['value']; |
| 57 | } |
| 58 | } |
| 59 | return $this->compare_to_rule( $mime_type, $rule ); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Returns an array of possible values for this rule type. |
| 64 | * |
| 65 | * @date 9/4/20 |
| 66 | * @since ACF 5.9.0 |
| 67 | * |
| 68 | * @param array $rule A location rule. |
| 69 | * @return array |
| 70 | */ |
| 71 | public function get_values( $rule ) { |
| 72 | $choices = array( |
| 73 | 'all' => __( 'All', 'secure-custom-fields' ), |
| 74 | ); |
| 75 | |
| 76 | // Get mime types and append into optgroups. |
| 77 | $mime_types = get_allowed_mime_types(); |
| 78 | foreach ( $mime_types as $regex => $mime_type ) { |
| 79 | |
| 80 | // Get type "image" from mime_type "image/jpeg". |
| 81 | $type = current( explode( '/', $mime_type ) ); |
| 82 | |
| 83 | // Append group and mimetype. |
| 84 | /* translators: 1: image type */ |
| 85 | $choices[ $type ][ $type ] = sprintf( __( 'All %s formats', 'secure-custom-fields' ), $type ); |
| 86 | $choices[ $type ][ $mime_type ] = "$regex ($mime_type)"; |
| 87 | } |
| 88 | |
| 89 | // return |
| 90 | return $choices; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | // Register. |
| 95 | acf_register_location_type( 'ACF_Location_Attachment' ); |
| 96 | endif; // class_exists check |
| 97 |