public function valid() { if (self::$layout_id !== null && self::$layout_id !== false) { return true; } $post = wpcf_admin_get_edited_post(); if (!empty($post)) { return $this->valid_per_post($post); } return $this->valid_per_post_type(); }
private function __construct() { $post = wpcf_admin_get_edited_post(); $post_type = wpcf_admin_get_edited_post_type($post); // if no post or no page if ($post_type != 'post' && $post_type != 'page') { $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); // abort if also no custom post type of types if (!array_key_exists($post_type, $custom_types)) { return false; } } $this->prepare(); }
/** * Adds items to view dropdown. * * @param type $items * @return type */ public static function editorDropdownFilter($items) { $post = wpcf_admin_get_edited_post(); if (empty($post)) { $post = (object) array('ID' => -1); } $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active'); $all_post_types = implode(' ', get_post_types(array('public' => true))); $add = array(); if (!empty($groups)) { // $group_id is blank therefore not equal to $group['id'] // use array for item key and CSS class $item_styles = array(); foreach ($groups as $group) { $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true); if (!empty($fields)) { // code from Types used here without breaking the flow // get post types list for every group or apply all $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true); if ($post_types == 'all') { $post_types = $all_post_types; } $post_types = trim(str_replace(',', ' ', $post_types)); $item_styles[$group['name']] = $post_types; foreach ($fields as $field) { $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')'; $add[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback); // TODO Remove - it's not post edit screen (meta box JS and CSS) WPCF_Fields::enqueueScript($field['type']); WPCF_Fields::enqueueStyle($field['type']); } } } } $search_key = ''; // Iterate all items to be displayed in the "V" menu foreach ($items as $key => $item) { if ($key == __('Basic', 'wpv-views')) { $search_key = 'found'; continue; } if ($search_key == 'found') { $search_key = $key; } if ($key == __('Field', 'wpv-views') && isset($item[trim(wpcf_types_get_meta_prefix(), '-')])) { unset($items[$key][trim(wpcf_types_get_meta_prefix(), '-')]); } } if (empty($search_key) || $search_key == 'found') { $search_key = count($items); } $insert_position = array_search($search_key, array_keys($items)); $part_one = array_slice($items, 0, $insert_position); $part_two = array_slice($items, $insert_position); $items = $part_one + $add + $part_two; // apply CSS styles to each item based on post types foreach ($items as $key => $value) { if (isset($item_styles[$key])) { $items[$key]['css'] = $item_styles[$key]; } else { $items[$key]['css'] = $all_post_types; } } return $items; }
/** * Get main post ID. * * @param type $context * @return type */ function wpcf_get_post_id($context = 'group') { if (!is_admin()) { /* * * TODO Check if frontend is fine (rendering children). * get_post() previously WP 3.5 requires $post_id */ $post_id = null; if (wpcf_compare_wp_version('3.5', '<')) { global $post; $post_id = !empty($post->ID) ? $post->ID : -1; } $_post = get_post($post_id); return !empty($_post->ID) ? $_post->ID : -1; } /* * TODO Explore possible usage for $context */ $post = wpcf_admin_get_edited_post(); return empty($post->ID) ? -1 : $post->ID; }
function wpcf_post_preview_warning() { $post = wpcf_admin_get_edited_post(); // Add preview warning if (isset($post->post_status) && !in_array($post->post_status, array('auto-draft', 'draft')) && !in_array($post->post_type, array('cred', 'view', 'view-template'))) { // require_once WPCF_EMBEDDED_ABSPATH . '/common/wp-pointer.php'; // // $pointer = new WPV_wp_pointer('types-post-preview-warning'); // $pointer->add_pointer(__('Preview warning'), // sprintf(__('Custom field changes cannot be previewed until %s is updated'), $post->post_type), // $jquery_id = '#types-preview-warning', // $position = 'left', // $pointer_name = 'types_preview_warning', // $activate_function = null, // $activate_selector = false // ); // $pointer->admin_enqueue_scripts(); wp_enqueue_style('wp-pointer'); wp_enqueue_script('wp-pointer'); ?> <script type="text/javascript">typesPostScreen.previewWarning('<?php _e('Preview warning', 'wpcf'); ?> ', '<?php printf(__('Custom field changes cannot be previewed until %s is updated', 'wpcf'), $post->post_type); ?> ');</script><?php } }
/** * Add User Fields to editor * * @author Gen gen.i@icanlocalize.com * @since Types 1.3 */ function wpcf_admin_post_add_usermeta_to_editor_js($menu, $views_callback = false) { global $wpcf; $post = wpcf_admin_get_edited_post(); if (empty($post)) { $post = (object) array('ID' => -1); } $groups = wpcf_admin_fields_get_groups('wp-types-user-group'); $user_id = wpcf_usermeta_get_user(); if (!empty($groups)) { $item_styles = array(); foreach ($groups as $group_id => $group) { if (empty($group['is_active'])) { continue; } $group_name = sprintf(__('%s (Usermeta fields)', 'wpcf'), $group['name']); $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true, 'wp-types-user-group', 'wpcf-usermeta'); if (!empty($fields)) { foreach ($fields as $field_id => $field) { // Use field class $wpcf->usermeta_field->set($user_id, $field); // Get field data $data = (array) $wpcf->usermeta_field->config; // Get inherited field if (isset($data['inherited_field_type'])) { $inherited_field_data = wpcf_fields_type_action($data['inherited_field_type']); } $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'usermeta\', ' . $post->ID . ')'; // Added for Views:users filter Vicon popup if ($views_callback) { $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'views-usermeta\', ' . $post->ID . ')'; } $menu[$group_name][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_usermeta_get_shortcode($field), '[]'), $group_name, $callback); } /* * Since Types 1.2 * We use field class to enqueue JS and CSS */ $wpcf->usermeta_field->enqueue_script(); $wpcf->usermeta_field->enqueue_style(); } } } return $menu; }
/** * Add styles to admin fields groups */ function wpcf_admin_fields_postfields_styles() { require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php'; require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php'; // $groups = wpcf_admin_fields_get_groups(); $groups = wpcf_admin_post_get_post_groups_fields(wpcf_admin_get_edited_post()); if (!empty($groups)) { echo '<style type="text/css">'; foreach ($groups as $group) { echo str_replace("}", "}\n", wpcf_admin_get_groups_admin_styles_by_group($group['id'])); } echo '</style>'; } }
function wpcf_wpml_have_original($post = null) { static $cache = array(); global $pagenow; $res = false; // WPML There is no lang on new post if ($pagenow == 'post-new.php') { return isset($_GET['trid']); } if (empty($post->ID)) { $post = wpcf_admin_get_edited_post(); } if (!empty($post->ID)) { $cache_key = $post->ID; if (isset($cache[$cache_key])) { return $cache[$cache_key]; } global $wpdb, $sitepress; $post_lang = $sitepress->get_element_language_details($post->ID, 'post_' . $post->post_type); if (isset($post_lang->language_code)) { $sql = $wpdb->prepare("SELECT trid FROM {$wpdb->prefix}icl_translations\n WHERE language_code = %s\n AND element_id = %d\n AND element_type = %s\n AND source_language_code IS NOT NULL", $post_lang->language_code, $post->ID, sprintf('post_%s', $post->post_type)); $res = (bool) $wpdb->get_var($sql); } $cache[$cache_key] = $res; } return $res; }
/** * Adds items to view dropdown. * * @param type $items * @return type */ public static function editorDropdownFilter($menu) { $post = wpcf_admin_get_edited_post(); if (empty($post)) { $post = (object) array('ID' => -1); } $groups = wpcf_admin_fields_get_groups('wp-types-group', 'group_active'); $all_post_types = implode(' ', get_post_types(array('public' => true))); $add = array(); if (!empty($groups)) { // $group_id is blank therefore not equal to $group['id'] // use array for item key and CSS class $item_styles = array(); foreach ($groups as $group) { $fields = wpcf_admin_fields_get_fields_by_group($group['id'], 'slug', true, false, true); if (!empty($fields)) { // code from Types used here without breaking the flow // get post types list for every group or apply all $post_types = get_post_meta($group['id'], '_wp_types_group_post_types', true); if ($post_types == 'all') { $post_types = $all_post_types; } $post_types = trim(str_replace(',', ' ', $post_types)); $item_styles[$group['name']] = $post_types; foreach ($fields as $field) { $callback = 'wpcfFieldsEditorCallback(\'' . $field['id'] . '\', \'postmeta\', ' . $post->ID . ')'; $menu[$group['name']][stripslashes($field['name'])] = array(stripslashes($field['name']), trim(wpcf_fields_get_shortcode($field), '[]'), $group['name'], $callback); // TODO Remove - it's not post edit screen (meta box JS and CSS) WPCF_Fields::enqueueScript($field['type']); WPCF_Fields::enqueueStyle($field['type']); } } } } return $menu; }
function wpcf_post_preview_warning() { $post = wpcf_admin_get_edited_post(); // Add preview warning if (isset($post->post_status) && !in_array($post->post_status, array('auto-draft', 'draft')) && !in_array($post->post_type, array('cred', 'view', 'view-template'))) { wp_enqueue_style('wp-pointer'); wp_enqueue_script('wp-pointer'); ?> <script type="text/javascript"> if ( "undefined" != typeof typesPostScreen ) { typesPostScreen.previewWarning( '<?php esc_attr_e(__('Preview warning', 'wpcf')); ?> ', '<?php esc_attr_e(sprintf(__('Custom field changes cannot be previewed until %s is updated', 'wpcf'), $post->post_type)); ?> '); } </script><?php } }
function wpcf_admin_get_current_edited_post($current_post = null) { $current_post = wpcf_admin_get_edited_post(); if (empty($current_post)) { return null; } return $current_post; }
/** * Get main post ID. * * @param type $context * @return type */ function wpcf_get_post_id($context = 'group') { if (!is_admin()) { $post = get_post(); return !empty($post->ID) ? $post->ID : -1; } /* * TODO Explore possible usage for $context */ $post = wpcf_admin_get_edited_post(); return empty($post->ID) ? -1 : $post->ID; }