File "class-acf-location-attachment.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/locations/class-acf-location-attachment.php
File size: 1.51 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

if (!defined('ABSPATH')) {
    exit;
}
if (!class_exists('ACF_Location_Attachment')) {
    class ACF_Location_Attachment extends ACF_Location
    {
        public function initialize()
        {
            $this->name = 'attachment';
            $this->label = __('Attachment', 'acf');
            $this->category = 'forms';
            $this->object_type = 'attachment';
        }
        public function match($rule, $screen, $field_group)
        {
            if (isset($screen['attachment'])) {
                $attachment = $screen['attachment'];
            } else {
                return false;
            }
            $mime_type = get_post_mime_type($attachment);
            if (!strpos($rule['value'], '/')) {
                $bits = explode('/', $mime_type);
                if ($bits[0] === $rule['value']) {
                    $mime_type = $rule['value'];
                }
            }
            return $this->compare_to_rule($mime_type, $rule);
        }
        public function get_values($rule)
        {
            $choices = array('all' => __('All', 'acf'));
            $mime_types = get_allowed_mime_types();
            foreach ($mime_types as $regex => $mime_type) {
                $type = current(explode('/', $mime_type));
                $choices[$type][$type] = sprintf(__('All %s formats', 'acf'), $type);
                $choices[$type][$mime_type] = "{$regex} ({$mime_type})";
            }
            return $choices;
        }
    }
    acf_register_location_type('ACF_Location_Attachment');
}