'method_name', 'admin_init' => 'admin_init', ]; } /** * Array with default value * * @var array */ private $fields_old = []; private ?int $randID = null; /** * Default option * * @var array */ private $carousel_options = []; private array $indicators = ['before-inner', 'after-inner', 'after-control', 'false']; private array $instance_old = []; function __construct(FieldsInterface $fields_type, ItalyStrap\Image\Size $image_size) { $this->image_size_media = $image_size; $this->fields_type = $fields_type; /** * Define data by given attributes. */ $this->fields_old = require(ITALYSTRAP_PLUGIN_PATH . 'config/carousel.php'); $this->fields = require(ITALYSTRAP_PLUGIN_PATH . 'config/media-carousel.php'); $this->carousel_options = ['orderby' => ['menu_order' => __('Menu order (Default)', 'italystrap'), 'title' => __('Order by the image\'s title', 'italystrap'), 'post_date' => __('Sort by date/time', 'italystrap'), 'rand' => __('Order randomly', 'italystrap'), 'ID' => __('Order by the image\'s ID', 'italystrap')], 'indicators' => ['before-inner' => __('before-inner', 'italystrap'), 'after-inner' => __('after-inner', 'italystrap'), 'after-control' => __('after-control', 'italystrap'), 'false' => __('false', 'italystrap')], 'control' => true, 'pause' => ['false' => __('none', 'italystrap'), 'hover' => __('hover', 'italystrap')], 'image_title' => true, 'text' => true, 'wpautop' => true, 'responsive' => false]; $this->randID = random_int(2, 5); // add_action( 'admin_init', array( $this, 'admin_init' ) ); } /** * @todo applicare filtro in ItalyStrapCarousel e togliere il 2° valore dell'array qui sotto */ function admin_init() { $this->gallery_types = apply_filters( 'italystrap_gallery_types', ['default' => __('Standard gallery', 'italystrap'), 'carousel' => __('Bootstrap Carousel', 'italystrap')] ); // Enqueue the media UI only if needed. // if ( count( $this->gallery_types ) > 0 ) { add_action('wp_enqueue_media', [$this, 'wp_enqueue_media']); add_action('print_media_templates', [$this, 'print_media_templates_old']); // add_action( 'print_media_templates', array( $this, 'print_media_templates' ) ); // } } /** * Registers/enqueues the gallery settings admin js. */ function wp_enqueue_media() { if (! wp_script_is('italystrap-gallery-settings', 'registered')) { /** * This only happens if we're not in ItalyStrap, but on WPCOM instead. * This is the correct path for WPCOM. */ wp_register_script('italystrap-gallery-settings', plugins_url('admin/js/src/gallery-settings.js', ITALYSTRAP_FILE), ['media-views'], '20121225666'); } $translation_array = wp_json_encode(require(ITALYSTRAP_PLUGIN_PATH . 'config/carousel.php')); // var_dump( $translation_array ); die(); wp_localize_script('italystrap-gallery-settings', 'gallery_fields', $translation_array); wp_enqueue_script('italystrap-gallery-settings'); } /** * Outputs a view template which can be used with wp.media.template */ function print_media_templates_old() { $default_gallery_type = apply_filters('italystrap_default_gallery_type', 'default'); echo ''; } /** * Outputs a view template which can be used with wp.media.template */ function print_media_templates() { $output = ''; $default_gallery_type = apply_filters('italystrap_default_gallery_type', 'default'); $instance = []; $key = [ 'name' => __('Type', 'italystrap'), 'desc' => __('Enter the widget class name.', 'italystrap'), 'id' => 'type', '_id' => 'type', '_name' => 'type', 'type' => 'select', 'class' => 'widefat', 'data-setting' => 'type', // 'class-p' => 'setting', 'default' => $default_gallery_type, 'options' => $this->gallery_types, ]; $output = sprintf( '', $this->fields_type->get_field_type($key, $instance), $this->get_field_types($this->fields) ); printf( '' ); echo $output; // XSS ok. } /** * Create Fields * * Creates each field defined. * * @access protected * @param array $fields The fields array. * @param string $out The HTML form output. * @return string Return the HTML Fields */ protected function get_field_types(array $fields, $out = '') { foreach ($fields as $key) { $out .= $this->get_field_type($key); } return $out; } /** * Create the Fields * * @access protected * @param array $key The key of field's array to create the HTML field. * * @return string Return the HTML Fields */ protected function get_field_type(array $key) { /** * Set field id and name */ $key['_id'] = $key['_name'] = $key['attributes']['data-setting'] = $key['id']; return $this->fields_type->get_field_type($key, []); } }