/** * Renders Thickbox content. * * Field should provide callback function * that will be called automatically. * * Function should be named like: * 'wpcf_fields_' . $field_type . '_editor_callback' * e.g. 'wpcf_fields_checkbox__editor_callback' * * Function should return array with elements: * 'supports' - parameters or other feature supported, e.g. 'styling' will * enable 'Styling' options * * Tabs is array with elements: * 'menu_title' - used for menu title * 'title' - used for main title * 'content' - HTML content of tab * * @param type $field * @param type $meta_type * @param type $post_id * @param string $shortcode */ function frame($field, $meta_type = 'postmeta', $post_id = -1, $shortcode = null, $callback = false, $views_usermeta = false) { global $wp_version, $wpcf; // Queue rendering JS settings add_action('admin_print_footer_scripts', array($this, 'renderTedSettings'), 1); wp_enqueue_script('types'); wp_enqueue_script('types-knockout'); wp_enqueue_script('types-editor'); wp_enqueue_script('wp-pointer'); wp_enqueue_style('types-editor'); wp_enqueue_style('wp-pointer'); wp_enqueue_style('toolset-font-awesome'); // Load cloned WP Media Modal CSS if (version_compare($wp_version, '3.5', '<')) { wp_enqueue_style('types-editor-cloned'); } $this->field = $field; $this->_meta_type = $meta_type; $this->_post = get_post($post_id); $this->_settings = is_null($shortcode) ? array() : $this->shortcodeToParameters($shortcode); $this->callback = $callback; $this->_data = array('meta_type' => $meta_type, 'field' => $field, 'field_type_data' => WPCF_Fields::getFieldTypeData($field['type']), 'settings' => array(), 'tabs' => array(), 'supports' => array(), 'post' => $this->_post, 'post_types' => get_post_types(array('show_ui' => true)), 'style' => isset($this->_settings['style']) ? $this->_settings['style'] : '', 'class' => isset($this->_settings['class']) ? $this->_settings['class'] : '', 'output' => 'html', 'user_form' => ''); // Set title if updated if (!is_null($shortcode)) { $this->_data['title'] = sprintf(__('Update %s', 'wpcf'), $this->_data['field_type_data']['title']); $this->_data['submit_button_title'] = __('Update shortcode', 'wpcf'); } // Exclude post types foreach ($wpcf->excluded_post_types as $_post_type) { unset($this->_data['post_types'][$_post_type]); } /* * Callback */ $function = 'wpcf_fields_' . $field['type'] . '_editor_callback'; if (function_exists($function)) { // Main callback $callback = call_user_func($function, $field, $this->_settings, $this->_meta_type, $this->_post); // Add supports if (!empty($callback['supports']) && is_array($callback['supports'])) { $this->_data['supports'] = $callback['supports']; } // Add tabs if (!empty($callback['tabs']) && is_array($callback['tabs'])) { $this->_data['tabs'] = $callback['tabs']; } // Unify settings if (!empty($callback['settings']) && is_array($callback['settings'])) { $this->_settings = array_merge($this->_settings, self::sanitizeParams($callback['settings'], 'array')); } } // If no tabs if (empty($this->_data['tabs'])) { $this->_data['tabs']['display'] = array('menu_title' => __('Display', 'wpcf'), 'title' => __('Display', 'wpcf'), 'content' => sprintf(__('There are no additional display options for the %s field.', 'wpcf'), $this->_data['field_type_data']['title'])); } // Add User ID form if ($this->_meta_type == 'usermeta') { if (!$views_usermeta) { $this->_data['user_form'] = wpcf_form_simple(wpcf_get_usermeta_form_addon($this->_settings)); $this->_data['supports'][] = 'user_id'; } } else { // Add Post ID form $this->_data['supports'][] = 'post_id'; } // Get parents if (!empty($this->_post->ID)) { $this->_data['parents'] = WPCF_Relationship::get_parents($this->_post); } // Set icons $icons = array('audio' => 'icon-music', 'checkbox' => 'icon-check', 'checkboxes' => 'icon-checkboxes', 'colorpicker' => 'icon-tint', 'date' => 'icon-calendar', 'email' => 'icon-envelope-alt', 'embed' => 'icon-youtube-play', 'file' => 'icon-file-alt', 'image' => 'icon-picture', 'map' => 'icon-map-marker', 'numeric' => 'icon-numeric', 'phone' => 'icon-phone', 'radio' => 'icon-radio-button', 'select' => 'icon-select-box', 'skype' => 'icon-skype', 'textarea' => 'icon-text-area', 'textfield' => 'icon-text-field', 'url' => 'icon-link', 'video' => 'icon-film', 'wysiwyg' => 'icon-wysiwyg'); $this->_data['icon_class'] = isset($icons[$field['type']]) ? $icons[$field['type']] : 'icon-text-field'; // Is repetitive $this->_data['is_repetitive'] = (bool) types_is_repetitive($field); if ($this->_data['is_repetitive']) { $this->_data['supports'][] = 'separator'; } // Render header wpcf_admin_ajax_head(); // Check if submitted $this->_thickbox_check_submit(); // Render form echo '<form method="post" action="" id="types-editor-modal-form">'; echo WPCF_Loader::view('editor-modal-window', $this->_data); wp_nonce_field('types_editor_frame', '__types_editor_nonce'); echo '</form>'; // Render footer wpcf_admin_ajax_footer(); }