public static function wpcf_admin_post_add_postmeta_to_editor_on_demand($editor) { add_action('admin_footer', 'wpcf_admin_post_js_validation'); wpcf_enqueue_scripts(); wp_enqueue_script('toolset-colorbox'); wp_enqueue_style('toolset-colorbox'); $current_post = wpcf_admin_get_edited_post(); if (empty($current_post)) { $current_post = (object) array('ID' => -1); } $fields = wpcf_admin_post_add_to_editor('get'); $groups = wpcf_admin_post_get_post_groups_fields($current_post); if (!empty($fields) && !empty($groups)) { foreach ($groups as $group) { if (empty($group['fields'])) { continue; } foreach ($group['fields'] as $group_field_id => $group_field) { if (isset($fields[$group_field_id])) { $field = $fields[$group_field_id]; $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $current_post->ID . ')'; $editor->add_insert_shortcode_menu(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback); } } } } }
/** * Renders JS for editor menu. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @return type */ function wpcf_admin_post_add_to_editor_js() { // since 1.3 we do not use global $post $post = wpcf_admin_get_edited_post(); if (empty($post)) { $post = (object) array('ID' => -1); } $fields = wpcf_admin_post_add_to_editor('get'); $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($fields) || empty($groups)) { return false; } $editor_addon = new Editor_addon('types', __('Insert Types Shortcode', 'wpcf'), WPCF_EMBEDDED_RES_RELPATH . '/js/types_editor_plugin.js', '', true, 'icon-types-logo ont-icon-18 ont-color-gray'); foreach ($groups as $group) { if (empty($group['fields'])) { continue; } foreach ($group['fields'] as $group_field_id => $group_field) { if (!isset($fields[$group_field_id])) { continue; } $field = $fields[$group_field_id]; $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')'; $editor_addon->add_insert_shortcode_menu(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback); } } }
/** * Sets field meta box form. * * @return type */ function _get_meta_form($meta_value = null, $meta_id = null, $wrap = true) { /* * Note that field may be registered outside of Types. * In that case, it's on developer to make sure it's loaded. */ $this->_include_file_by_field_type($this->cf['type']); /* * Set value * * IMPORTANT * Here we set values for form elements */ $this->cf['value'] = is_null($meta_value) ? $this->meta : $meta_value; $form = array(); $form_meta_box = array(); $inherited = array(); $this->__multiple = false; // Open main wrapper if ($wrap) { $form['__meta_form_OPEN'] = array('#type' => 'markup', '#markup' => '' . '<div id="wpcf_wrapper_' . $this->unique_id . '" class="wpcf-wrap wpcf-meta-form">'); } /* * * * * * Since Types 1.2 * Avoid using parent (inherited) type * $this->config->inherited_field_type */ // See if inherited data and merge if (isset($this->config->inherited_field_type)) { if (!array_key_exists($this->cf['type'], $this->_deprecated_inherited_allowed())) { // _deprecated_argument( 'inherited_field_type', '1.2', // 'Since Types 1.2 we encourage developers to completely define fields' ); } $file = $this->_include_file_by_field_type($this->config->inherited_field_type); if (file_exists($file)) { if (function_exists('wpcf_fields_' . $this->config->inherited_field_type . '_meta_box_form')) { $inherited = call_user_func_array('wpcf_fields_' . $this->config->inherited_field_type . '_meta_box_form', array($this->cf, $this)); // If single form - convert to array of elements if (isset($inherited['#type'])) { $inherited = array('wpcf_field_' . $this->unique_id => $inherited); } // One value? if (count($inherited) > 1) { $this->__multiple = true; } $form = $form + $inherited; } } } $func = 'wpcf_fields_' . $this->cf['type'] . '_meta_box_form'; if (is_callable($func)) { /* * * From Types 1.2 use complete form setup */ $form_meta_box = call_user_func_array('wpcf_fields_' . $this->cf['type'] . '_meta_box_form', array($this->cf, $this)); // If single form - convert to array of elements if (isset($form_meta_box['#type'])) { $form_meta_box = array('wpcf_field_' . $this->unique_id => $form_meta_box); } // One value? if (count($form_meta_box) > 1) { $this->__multiple = true; } // Merge $form = array_merge($form, $form_meta_box); } if (!empty($form)) { // Process each field foreach ($form as $element_key => $element) { /* * * Start using __ in keys to skip element */ // Skip protected if (strpos($element_key, '__') === 0) { $form[$element_key] = $element; continue; } // Add title and description // TODO WPML if (empty($started)) { $_title = isset($element['#title']) ? $element['#title'] : $this->cf['name']; $element['#title'] = wpcf_translate('field ' . $this->cf['id'] . ' name', $_title); // Add asterisk for required fields if (isset($this->cf['data']['validate']['required'])) { $element['#title'] .= '*'; } $_description = isset($element['#description']) ? $element['#description'] : $this->cf['description']; $element['#description'] = wpautop(wpcf_translate('field ' . $this->cf['id'] . ' description', $_description)); $started = true; } // Set current element $this->__current_form_element = $element; // Process field $temp_processed = wpcf_admin_post_process_field($this); if (!empty($temp_processed['element'])) { $element = $temp_processed['element']; } // Set form element $form[$element_key] = apply_filters('wpcf_post_edit_field', $element, $this->cf, $this->post, $this->context); } // Add to editor if ($this->add_to_editor) { wpcf_admin_post_add_to_editor($this->cf); } $this->enqueue_script(); $this->enqueue_style(); } // Close main wrapper if ($wrap) { $form['meta_form_CLOSE'] = array('#type' => 'markup', '#markup' => '' . '</div>'); } // Add unique IDs foreach ($form as $k => $v) { $_form[$k . '_' . $this->unique_id] = $v; } return apply_filters('wpcf_meta_form', $_form); }
function __wpcf_usermeta_test() { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; $field['id'] = md5('date' . time()); $here = array(basename($_SERVER['REQUEST_URI']), basename($_SERVER['SCRIPT_FILENAME'])); global $post; // Get post_type if ($post) { $post_type = get_post_type($post); } else { if (!empty($_GET['post'])) { $post_type = get_post_type(sanitize_text_field($_GET['post'])); } else { if (!empty($_GET['post_type'])) { $post_type = esc_html(sanitize_text_field($_GET['post_type'])); } } } if ($here[0] == ('index.php' || 'wp-admin') && $here[1] != 'index.php') { /** This action is documented in embedded/bootstrap.php */ $post_types_without_meta_boxes = apply_filters('toolset_filter_exclude_own_post_types', array('view', 'view-template', 'cred-form', 'cred-user-form')); if (isset($post_type) && in_array($post_type, $post_types_without_meta_boxes)) { return; } wpcf_admin_post_add_to_editor($field); } }
function __wpcf_usermeta_test() { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; $field['id'] = md5('date' . time()); $here = array(basename($_SERVER['REQUEST_URI']), basename($_SERVER['SCRIPT_FILENAME'])); global $post; // Get post_type if ($post) { $post_type = get_post_type($post); } else { if (!empty($_GET['post'])) { $post_type = get_post_type(sanitize_text_field($_GET['post'])); } else { if (!empty($_GET['post_type'])) { $post_type = esc_html(sanitize_text_field($_GET['post_type'])); } } } if ($here[0] == ('index.php' || 'wp-admin') && $here[1] != 'index.php') { if (isset($post_type) && in_array($post_type, array('view', 'view-template', 'cred-form'))) { return; } wpcf_admin_post_add_to_editor($field); } }
/** * Renders JS for editor menu. * * Core function. Works and stable. Do not move or change. * If required, add hooks only. * * @return type */ function wpcf_admin_post_add_to_editor_js() { global $post; $fields = wpcf_admin_post_add_to_editor('get'); $groups = wpcf_admin_post_get_post_groups_fields($post); if (empty($fields) || empty($groups)) { return false; } $editor_addon = new Editor_addon('types', __('Insert Types Shortcode', 'wpcf'), WPCF_EMBEDDED_RES_RELPATH . '/js/types_editor_plugin.js', WPCF_EMBEDDED_RES_RELPATH . '/images/bw-logo-16.png'); foreach ($groups as $group) { if (empty($group['fields'])) { continue; } foreach ($group['fields'] as $group_field_id => $group_field) { if (!isset($fields[$group_field_id])) { continue; } $field = $fields[$group_field_id]; $data = wpcf_fields_type_action($field['type']); $callback = ''; if (isset($data['editor_callback'])) { $callback = sprintf($data['editor_callback'], $field['id']); } else { // Set callback if function exists $function = 'wpcf_fields_' . $field['type'] . '_editor_callback'; $callback = function_exists($function) ? 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\')' : ''; } $editor_addon->add_insert_shortcode_menu(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback); } } }