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