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); }