public function test_attributes()
 {
     $args = array('name' => 'test_media', 'attributes' => array('data-test' => rand_str()));
     $fm = new Fieldmanager_Media($args);
     ob_start();
     $fm->add_meta_box('Test Media', 'post')->render_meta_box($this->post, array());
     $html = ob_get_clean();
     $this->assertRegExp('/<input[^>]+type=[\'"]button[\'"][^>]+data-test=[\'"]' . $args['attributes']['data-test'] . '[\'"]/', $html);
 }
 public function init()
 {
     $fm = new Fieldmanager_Media(false, array('name' => 'basic_media'));
     $fm->add_meta_box('Basic Media Field', 'demo-media');
     $fm = new Fieldmanager_Media(false, array('name' => 'media_options', 'description' => 'This field has four customizations: the button text above, the modal title, modal button label, and the preview image size', 'preview_size' => 'medium', 'label' => 'Modified Media Popup', 'button_label' => 'Modified Button Label', 'modal_button_label' => 'Modified Modal Button', 'modal_title' => 'Modified Modal Title'));
     $fm->add_meta_box('Media field with options', 'demo-media');
     $fm = new Fieldmanager_Group(array('name' => 'repeatable_media', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('media_field' => new Fieldmanager_Media('Repeatable Field'))));
     $fm->add_meta_box('Repeatable Media Fields', 'demo-media');
     $fm = new Fieldmanager_Media(false, array('name' => 'sidebar_media'));
     $fm->add_meta_box('Sidebar Media Field', 'demo-media', 'side');
     $fm = new Fieldmanager_Group(array('name' => 'sidebar_repeatable_media', 'limit' => 0, 'add_more_label' => 'Add another field', 'sortable' => true, 'label' => 'Field', 'children' => array('media_field' => new Fieldmanager_Media('Repeatable Field'))));
     $fm->add_meta_box('Sidebar Repeatable Media Fields', 'demo-media', 'side');
 }
 public function setUp()
 {
     parent::setUp();
     // Spoof is_admin() for fm_add_script().
     $this->screen = get_current_screen();
     set_current_screen('dashboard-user');
     // Re-init scripts. @see Tests_Dependencies_Scripts.
     $this->old_wp_scripts = isset($GLOBALS['wp_scripts']) ? $GLOBALS['wp_scripts'] : null;
     remove_action('wp_default_scripts', 'wp_default_scripts');
     $GLOBALS['wp_scripts'] = new WP_Scripts();
     $GLOBALS['wp_scripts']->default_version = get_bloginfo('version');
     // Media will only try to register a script once, so hack around that.
     Fieldmanager_Media::$has_registered_media = false;
     // Instantiate field classes that register scripts.
     new Fieldmanager_Autocomplete('Test', array('datasource' => new Fieldmanager_Datasource_Post()));
     new Fieldmanager_Datepicker('Test');
     new Fieldmanager_DraggablePost('Test');
     new Fieldmanager_Grid('Test');
     new Fieldmanager_Group('Test', array('tabbed' => 'horizontal'));
     new Fieldmanager_Media('Test');
     new Fieldmanager_Select('Test');
     new Fieldmanager_RichTextArea('Test');
     do_action('wp_enqueue_scripts');
     do_action('admin_enqueue_scripts');
 }
 /**
  * Construct default attributes
  * @param string $label
  * @param array $options
  */
 public function __construct($label = '', $options = array())
 {
     $this->button_label = __('Attach a File', 'fieldmanager');
     $this->modal_button_label = __('Select Attachment', 'fieldmanager');
     $this->modal_title = __('Choose an Attachment', 'fieldmanager');
     add_action('admin_print_scripts', array($this, 'admin_print_scripts'));
     if (!self::$has_registered_media) {
         fm_add_script('fm_media', 'js/media/fieldmanager-media.js', array('jquery'), '1.0.4');
         self::$has_registered_media = true;
     }
     parent::__construct($label, $options);
 }
 /**
  * Construct default attributes
  * @param string $label
  * @param array $options
  */
 public function __construct($label, $options = array())
 {
     $this->button_label = __('Attach a File', 'fieldmanager');
     $this->modal_button_label = __('Select Attachment', 'fieldmanager');
     $this->modal_title = __('Choose an Attachment', 'fieldmanager');
     add_action('admin_print_scripts', function () {
         $post = get_post();
         $args = array();
         if (isset($post) && $post->ID) {
             $args['post'] = $post->ID;
         }
         wp_enqueue_media($args);
         // generally on post pages this will not have an impact.
     });
     if (!self::$has_registered_media) {
         fm_add_script('fm_media', 'js/media/fieldmanager-media.js', array('jquery'), '1.0.1');
         self::$has_registered_media = True;
     }
     parent::__construct($label, $options);
 }