Example #1
0
 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);
                 }
             }
         }
     }
 }
 public function valid()
 {
     $post_type = Types_Helper_Condition::get_post_type();
     // false if we have no post type
     if (!isset($post_type->name)) {
         return false;
     }
     // query a post
     $query = new WP_Query('post_type=' . $post_type->name . '&posts_per_page=1');
     if ($query->have_posts()) {
         $post = $query->posts[0];
         // for the case no post created yet (post fields group edit page / post type edit page)
     } else {
         $post = new stdClass();
         $post->ID = -1;
         $post->post_type = $post_type->name;
     }
     if (!function_exists('wpcf_admin_post_get_post_groups_fields')) {
         include_once WPCF_EMBEDDED_ABSPATH . '/includes/fields-post.php';
     }
     $fields = wpcf_admin_post_get_post_groups_fields($post);
     if (isset($fields) && is_array($fields) && !empty($fields)) {
         return true;
     }
     return false;
 }
 public function valid()
 {
     $post_type = Types_Helper_Condition::get_post_type();
     $query = new WP_Query('post_type=' . $post_type->name . '&posts_per_page=1');
     if ($query->have_posts()) {
         if (!function_exists('wpcf_admin_post_get_post_groups_fields')) {
             include_once WPCF_EMBEDDED_ABSPATH . '/includes/fields-post.php';
         }
         $fields = wpcf_admin_post_get_post_groups_fields($query->posts[0]);
     }
     if (isset($fields) && is_array($fields) && !empty($fields)) {
         return true;
     }
     return false;
 }
Example #4
0
 /**
  * Returns HTML formatted row
  *
  * While generating rows we collect headers too.
  *
  * @return type
  */
 function row()
 {
     /*
      * Start output.
      * Output is returned as array - each element is <td> content.
      */
     $row = array();
     /*
      * LOOP over fields
      * Custom settings (specific)
      */
     if ($this->data['fields_setting'] == 'specific' && !empty($this->data['fields'])) {
         // Set title
         if (isset($this->data['fields']['_wp_title']) && isset($this->child_post_type_object->slug) && post_type_supports($this->child_post_type_object->slug, 'title')) {
             $this->headers[] = '_wp_title';
             $row[] = $this->title();
         }
         // Set body
         if (isset($this->data['fields']['_wp_body']) && post_type_supports($this->child_post_type_object->slug, 'editor')) {
             $this->headers[] = '_wp_body';
             $row[] = $this->body();
         }
         // Set excerpt
         if (isset($this->data['fields']['_wp_excerpt']) && post_type_supports($this->child_post_type_object->slug, 'excerpt')) {
             $this->headers[] = '_wp_excerpt';
             $row[] = $this->excerpt();
         }
         // Set thumbnail
         if (isset($this->data['fields']['_wp_featured_image']) && post_type_supports($this->child_post_type_object->slug, 'thumbnail')) {
             $this->headers[] = '_wp_featured_image';
             $row[] = $this->thumbnail();
         }
         /**
          * get allowed fields for this post type
          */
         $allowed_fields = array();
         if (isset($this->child_post_type_object->slug)) {
             $allowed_fields = wpcf_admin_get_allowed_fields_by_post_type($this->child_post_type_object->slug);
         }
         // Loop over Types fields
         foreach ($this->data['fields'] as $field_key => $true) {
             // Skip parents
             if (in_array($field_key, array('_wp_title', '_wp_body', '_wp_excerpt', '_wpcf_pr_parents', '_wpcf_pr_taxonomies'))) {
                 continue;
             }
             /**
              * check field
              */
             if (!in_array($field_key, $allowed_fields)) {
                 continue;
             }
             /*
              * Set field
              */
             $this->cf->set($this->child, $field_key);
             $row[] = $this->field_form();
             $this->_field_triggers();
             // Add to header
             $this->headers[] = $field_key;
         }
         // Add parent forms
         if (!empty($this->data['fields']['_wpcf_pr_parents'])) {
             $_temp = (array) $this->data['fields']['_wpcf_pr_parents'];
             foreach ($_temp as $_parent => $_true) {
                 $row[] = $this->_parent_form($_parent);
                 // Add to header
                 $this->headers['__parents'][$_parent] = $_true;
             }
         }
         // Add taxonomies forms
         if (!empty($this->data['fields']['_wpcf_pr_taxonomies'])) {
             $_temp = (array) $this->data['fields']['_wpcf_pr_taxonomies'];
             foreach ($_temp as $taxonomy => $_true) {
                 $_taxonomy = get_taxonomy($taxonomy);
                 if (!empty($_taxonomy)) {
                     $row[] = $this->taxonomy_form($_taxonomy);
                     // Add to header
                     $this->headers['__taxonomies'][$taxonomy] = $_taxonomy->label;
                 }
             }
         }
         /*
          *
          *
          *
          *
          * DEFAULT SETTINGS
          */
     } else {
         // Set title
         $row[] = $this->title();
         $this->headers[] = '_wp_title';
         // Set body if needed
         if ($this->data['fields_setting'] == 'all_cf_standard') {
             $this->headers[] = '_wp_body';
             $row[] = $this->body();
             $this->headers[] = '_wp_excerpt';
             $row[] = $this->excerpt();
         }
         /*
          * Loop over groups and fields
          */
         // Get groups
         $groups = wpcf_admin_post_get_post_groups_fields($this->child, 'post_relationships');
         foreach ($groups as $group) {
             if (empty($group['fields'])) {
                 continue;
             }
             /*
              * Loop fields
              */
             foreach ($group['fields'] as $field_key => $field) {
                 /*
                  * Set field
                  */
                 $field_key = $this->cf->__get_slug_no_prefix($field_key);
                 $this->cf->set($this->child, $field_key);
                 $row[] = $this->field_form();
                 $this->_field_triggers();
                 // Add to header{
                 $this->headers[] = WPCF_META_PREFIX . $field_key;
             }
         }
         // Add parent forms
         if ($this->data['fields_setting'] == 'all_cf') {
             $this->data['fields']['_wpcf_pr_parents'] = wpcf_pr_admin_get_belongs($this->child_post_type);
             if (!empty($this->data['fields']['_wpcf_pr_parents'])) {
                 $_temp = (array) $this->data['fields']['_wpcf_pr_parents'];
                 foreach ($_temp as $_parent => $_true) {
                     if ($_parent == $this->parent_post_type) {
                         continue;
                     }
                     $row[] = $this->_parent_form($_parent);
                     // Add to header
                     $this->headers['__parents'][$_parent] = $_true;
                 }
             }
         }
     }
     return $row;
 }
Example #5
0
/**
 * 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);
        }
    }
}
Example #6
0
/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    static $cache = array();
    if (isset($args['post_id'])) {
        $post = $args['post_id'] != '0' ? get_post($args['post_id']) : null;
    } else {
        global $post;
    }
    if (empty($post->ID)) {
        return array();
    }
    $cache_key = md5($post->ID . serialize(func_get_args()));
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    global $wp_post_types;
    // WP allows querying inactive post types
    if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
        return array();
    }
    $defaults = array('post_status' => array('publish'));
    $args = wp_parse_args($args, $defaults);
    WPCF_Loader::loadModel('relationship');
    WPCF_Loader::loadInclude('fields-post');
    $child_posts = WPCF_Relationship_Model::getChildrenByPostType($post, $post_type, array(), array(), $args);
    foreach ($child_posts as $child_post_key => $child_post) {
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    $data = null;
                    if (types_is_repetitive($field)) {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false);
                        // get all field instances
                    } else {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                        // get single field instance
                        // handle checkboxes which are one value serialized
                        if ($field['type'] == 'checkboxes' && !empty($data)) {
                            $data = maybe_unserialize($data);
                        }
                    }
                    if (!is_null($data)) {
                        $child_posts[$child_post_key]->fields[$k] = $data;
                    }
                }
            }
        }
    }
    $cache[$cache_key] = $child_posts;
    return $child_posts;
}
Example #7
0
/**
 * wpcf_custom_fields_to_be_copied
 *
 * Hook the copy custom fields from WPML and remove any of the fields
 * that wpcf will copy.
 */
function wpcf_custom_fields_to_be_copied($copied_fields, $original_post_id)
{
    // see if this is one of our fields.
    $groups = wpcf_admin_post_get_post_groups_fields(get_post($original_post_id));
    foreach ($copied_fields as $id => $copied_field) {
        foreach ($groups as $group) {
            foreach ($group['fields'] as $field) {
                if ($copied_field == wpcf_types_get_meta_prefix($field) . $field['slug']) {
                    unset($copied_fields[$id]);
                }
            }
        }
    }
    return $copied_fields;
}
Example #8
0
 /**
  * Returns HTML formatted row
  *
  * While generating rows we collect headers too.
  *
  * @return type
  */
 function row()
 {
     /*
      * Start output.
      * Output is returned as array - each element is <td> content.
      */
     $row = array();
     /*
      * LOOP over fields
      * Custom settings (specific)
      */
     if ($this->data['fields_setting'] == 'specific' && !empty($this->data['fields'])) {
         // Set title
         if (isset($this->data['fields']['_wp_title'])) {
             $this->headers[] = '_wp_title';
             $row[] = $this->title();
         }
         // Set body
         if (isset($this->data['fields']['_wp_body'])) {
             $this->headers[] = '_wp_body';
             $row[] = $this->body();
         }
         // Loop over Types fields
         foreach ($this->data['fields'] as $field_key => $true) {
             // If field belongs only to disabled group - remove it.
             $groups = wpcf_admin_fields_get_groups_by_field($this->cf->__get_slug_no_prefix($field_key));
             if (empty($groups)) {
                 continue;
             }
             $_continue = false;
             // If at least one active - proceed
             foreach ($groups as $group) {
                 if ($group['is_active']) {
                     $_continue = true;
                 }
             }
             if (!$_continue) {
                 continue;
             }
             // Skip parents
             if (in_array($field_key, array('_wp_title', '_wp_body', '_wpcf_pr_parents', '_wpcf_pr_taxonomies'))) {
                 continue;
             } else {
                 /*
                  * Set field
                  */
                 //                    $field_key = $this->cf->__get_slug_no_prefix( $field_key );
                 $this->cf->set($this->child, $field_key);
                 $row[] = $this->field_form();
                 $this->_field_triggers();
                 // Add to header
                 //                    $this->headers[] = WPCF_META_PREFIX . $field_key;
                 $this->headers[] = $field_key;
             }
         }
         // Add parent forms
         if (!empty($this->data['fields']['_wpcf_pr_parents'])) {
             $_temp = (array) $this->data['fields']['_wpcf_pr_parents'];
             foreach ($_temp as $_parent => $_true) {
                 $row[] = $this->_parent_form($_parent);
                 // Add to header
                 $this->headers['__parents'][$_parent] = $_true;
             }
         }
         // Add taxonomies forms
         if (!empty($this->data['fields']['_wpcf_pr_taxonomies'])) {
             $_temp = (array) $this->data['fields']['_wpcf_pr_taxonomies'];
             foreach ($_temp as $taxonomy => $_true) {
                 $_taxonomy = get_taxonomy($taxonomy);
                 if (!empty($_taxonomy)) {
                     $row[] = $this->taxonomy_form($_taxonomy);
                     // Add to header
                     $this->headers['__taxonomies'][$taxonomy] = $_taxonomy->label;
                 }
             }
         }
         /*
          *
          *
          *
          *
          * DEFAULT SETTINGS
          */
     } else {
         // Set title
         $row[] = $this->title();
         $this->headers[] = '_wp_title';
         // Set body if needed
         if ($this->data['fields_setting'] == 'all_cf_standard') {
             $this->headers[] = '_wp_body';
             $row[] = $this->body();
         }
         /*
          * Loop over groups and fields
          */
         // Get groups
         $groups = wpcf_admin_post_get_post_groups_fields($this->child, 'post_relationships');
         foreach ($groups as $group) {
             if (empty($group['fields'])) {
                 continue;
             }
             /*
              * Loop fields
              */
             foreach ($group['fields'] as $field_key => $field) {
                 /*
                  * Set field
                  */
                 $field_key = $this->cf->__get_slug_no_prefix($field_key);
                 $this->cf->set($this->child, $field_key);
                 $row[] = $this->field_form();
                 $this->_field_triggers();
                 // Add to header{
                 $this->headers[] = WPCF_META_PREFIX . $field_key;
             }
         }
         // Add parent forms
         if ($this->data['fields_setting'] == 'all_cf') {
             $this->data['fields']['_wpcf_pr_parents'] = wpcf_pr_admin_get_belongs($this->child_post_type);
             if (!empty($this->data['fields']['_wpcf_pr_parents'])) {
                 $_temp = (array) $this->data['fields']['_wpcf_pr_parents'];
                 foreach ($_temp as $_parent => $_true) {
                     if ($_parent == $this->parent_post_type) {
                         continue;
                     }
                     $row[] = $this->_parent_form($_parent);
                     // Add to header
                     $this->headers['__parents'][$_parent] = $_true;
                 }
             }
         }
     }
     return $row;
 }
Example #9
0
/**
 * 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);
        }
    }
}
Example #10
0
/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
    global $post, $wp_post_types;
    // WP allows querying inactive post types
    if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
        return array();
    }
    $defaults = array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => null, 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID, 'suppress_filters' => false);
    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('types_child_posts_args', $args);
    $child_posts = get_posts($args);
    foreach ($child_posts as $child_post_key => $child_post) {
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    $child_posts[$child_post_key]->fields[$k] = get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                }
            }
        }
    }
    return $child_posts;
}
Example #11
0
/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
    global $post;
    $defaults = array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => null, 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID);
    $args = wp_parse_args($args, $defaults);
    $child_posts = get_posts($args);
    foreach ($child_posts as $child_post_key => $child_post) {
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    $child_posts[$child_post_key]->fields[$k] = get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                }
            }
        }
    }
    return $child_posts;
}
Example #12
0
/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields.php';
    require_once WPCF_EMBEDDED_INC_ABSPATH . '/fields-post.php';
    global $post, $wp_post_types;
    // WP allows querying inactive post types
    if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
        return array();
    }
    $defaults = array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => null, 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID, 'suppress_filters' => false);
    $args = wp_parse_args($args, $defaults);
    $args = apply_filters('types_child_posts_args', $args);
    $child_posts = get_posts($args);
    foreach ($child_posts as $child_post_key => $child_post) {
        if ($child_posts[$child_post_key]->post_status == 'trash') {
            unset($child_posts[$child_post_key]);
            continue;
        }
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    if (isset($field['data']['repetitive']) && $field['data']['repetitive']) {
                        $child_posts[$child_post_key]->fields[$k] = get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false);
                    } else {
                        $child_posts[$child_post_key]->fields[$k] = get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                    }
                    // get single field instance
                    // handle checkboxes which are one value serialized
                    if ($field['type'] == 'checkboxes' && isset($child_posts[$child_post_key]->fields[$k])) {
                        $child_posts[$child_post_key]->fields[$k] = maybe_unserialize($child_posts[$child_post_key]->fields[$k]);
                    }
                }
            }
        }
    }
    return $child_posts;
}
/**
 * Has form table row.
 * 
 * @param type $post
 * @param type $post_type
 * @param type $data
 * @param type $parent_post_type
 * @param stdClass $item
 * @return string 
 */
function wpcf_pr_admin_post_meta_box_has_row($post, $post_type, $data, $parent_post_type, $item)
{
    $new_item = false;
    $date_trigger = false;
    // Set item
    if (empty($item)) {
        $item = new stdClass();
        $item->ID = 'new_' . mt_rand();
        $item->post_title = '';
        $item->post_content = '';
        $item->post_type = $post_type;
        $new_item = true;
    }
    // Cleanup data
    if (empty($data['fields_setting'])) {
        $data['fields_setting'] = 'all_cf';
    }
    $item_parents = isset($data['fields']['_wpcf_pr_parents']) ? $data['fields']['_wpcf_pr_parents'] : array();
    unset($data['fields']['_wpcf_pr_parents']);
    $row_data = array();
    $wpcf_fields = wpcf_admin_fields_get_fields();
    $row_data[] = wpcf_form_simple(array('field' => array('#type' => 'textfield', '#id' => 'wpcf_post_relationship_' . $item->ID . '_wp_title', '#name' => 'wpcf_post_relationship[' . $item->ID . '][_wp_title]', '#value' => $item->post_title, '#inline' => true, '#attributes' => $new_item || $data['fields_setting'] == 'all_cf_standard' || isset($data['fields']['_wp_title']) ? array() : array('readonly' => 'readonly'))));
    if ($data['fields_setting'] == 'specific' && !empty($data['fields'])) {
        foreach ($data['fields'] as $field_key => $true) {
            if ($field_key == '_wp_title') {
                continue;
            } else {
                if ($field_key == '_wp_body') {
                    $value = wp_trim_words($item->post_content, 10, null);
                    $element = wpcf_form_simple(array('field' => array('#type' => 'textarea', '#id' => 'wpcf_post_relationship_' . $item->ID . '_' . $field_key, '#name' => 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']', '#value' => $item->post_content, '#attributes' => array('style' => 'width:300px;height:100px;'), '#inline' => true)));
                } else {
                    $wpcf_key = str_replace(WPCF_META_PREFIX, '', $field_key);
                    if (strpos($field_key, WPCF_META_PREFIX) === 0 && isset($wpcf_fields[$wpcf_key])) {
                        // Date trigger
                        if ($wpcf_fields[$wpcf_key]['type'] == 'date') {
                            $date_trigger = true;
                        }
                        // Get WPCF form
                        $element = wpcf_admin_post_process_fields($item, array('field' => $wpcf_fields[$wpcf_key]), false, false, 'post_relationship');
                        $element = array_shift($element);
                        // TODO There may still be problem with IDs
                        if (!in_array($wpcf_fields[$wpcf_key]['type'], array('image', 'file'))) {
                            $element['#id'] = 'wpcf_post_relationship_' . $item->ID . '_' . $wpcf_key;
                        }
                        $element['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']';
                        $element['#inline'] = true;
                        unset($element['#title'], $element['#description']);
                        if (in_array($wpcf_fields[$wpcf_key]['type'], array('wysiwyg'))) {
                            $element['#type'] = 'textarea';
                            $element['#attributes'] = array('style' => 'width:300px;height:100px;');
                        }
                        if (in_array($wpcf_fields[$wpcf_key]['type'], array('checkbox'))) {
                            $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkbox[' . $item->ID . '][' . $wpcf_key . ']" value="1" />';
                        }
                        $value = get_post_meta($item->ID, $field_key, true);
                        $element = wpcf_form_simple(array('field' => $element));
                    } else {
                        // Just render textfield
                        $value = get_post_meta($item->ID, $field_key, true);
                        $element = wpcf_form_simple(array('field' => array('#type' => 'textfield', '#id' => 'wpcf_post_relationship_' . $item->ID . '_' . $field_key, '#name' => 'wpcf_post_relationship[' . $item->ID . '][' . $field_key . ']', '#value' => $value, '#inline' => true)));
                    }
                }
            }
            $row_data[] = $element;
        }
        // Get other parents
        foreach ($item_parents as $parent => $temp_data) {
            if ($parent == $parent_post_type) {
                continue;
            }
            $meta = get_post_meta($item->ID, '_wpcf_belongs_' . $parent . '_id', true);
            $meta = empty($meta) ? 0 : $meta;
            $belongs_data = array('belongs' => array($parent => $meta));
            $temp_form = wpcf_pr_admin_post_meta_box_belongs_form($item, $parent, $belongs_data);
            unset($temp_form[$parent]['#suffix'], $temp_form[$parent]['#prefix'], $temp_form[$parent]['#title']);
            $temp_form[$parent]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][parents][' . $parent . ']';
            $row_data[] = wpcf_form_simple($temp_form);
        }
    } else {
        $groups = wpcf_admin_post_get_post_groups_fields($item, 'post_relationships');
        if ($data['fields_setting'] == 'all_cf_standard') {
            $element = wpcf_form_simple(array('field' => array('#type' => 'textarea', '#id' => 'wpcf_post_relationship_' . $item->ID . '_wp_body', '#name' => 'wpcf_post_relationship[' . $item->ID . '][_wp_body]', '#value' => $item->post_content, '#attributes' => array('style' => 'width:300px;height:100px;'), '#inline' => true)));
            $row_data[] = $element;
        }
        foreach ($groups as $group) {
            foreach ($group['fields'] as $field) {
                // Date trigger
                if ($field['type'] == 'date') {
                    $date_trigger = true;
                }
                // Get WPCF form
                $element_org = wpcf_admin_post_process_fields($item, array('field' => $field), false, false, 'post_relationship');
                $element = array_shift($element_org);
                // @todo Check if this is needed for skype only
                //                if ($field['type'] == 'skype') {
                //                    $temp_second_element = array_pop($element_org);
                //                    if (!empty($temp_second_element['#validate'])) {
                //                        $element['#validate'] = $temp_second_element['#validate'];
                //                    }
                //
                //                }
                // TODO Monitor if may still be problem with IDs
                if (!in_array($field['type'], array('image', 'file'))) {
                    $element['#id'] = 'wpcf_post_relationship_' . $item->ID . '_' . $field['id'];
                }
                $element['#name'] = 'wpcf_post_relationship[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . ']';
                $element['#inline'] = true;
                unset($element['#title'], $element['#description']);
                if (in_array($field['type'], array('wysiwyg'))) {
                    $element['#type'] = 'textarea';
                    $element['#attributes'] = array('style' => 'width:300px;height:100px;');
                }
                if (in_array($field['type'], array('checkbox'))) {
                    $element['#suffix'] = '<input type="hidden" name="wpcf_post_relationship_checkbox[' . $item->ID . '][' . wpcf_types_get_meta_prefix($field) . $field['slug'] . ']" value="1" />';
                }
                $value = get_post_meta($item->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                $element = array('field' => $element);
                $element = wpcf_form_simple($element);
                $row_data[] = $element;
            }
        }
        // Get all parents
        $item_parents = wpcf_pr_admin_get_belongs($post_type);
        if ($item_parents) {
            foreach ($item_parents as $parent => $temp_data) {
                if ($parent == $parent_post_type) {
                    continue;
                }
                $meta = get_post_meta($item->ID, '_wpcf_belongs_' . $parent . '_id', true);
                $meta = empty($meta) ? 0 : $meta;
                $belongs_data = array('belongs' => array($parent => $meta));
                $temp_form = wpcf_pr_admin_post_meta_box_belongs_form($item, $parent, $belongs_data);
                unset($temp_form[$parent]['#suffix'], $temp_form[$parent]['#prefix'], $temp_form[$parent]['#title']);
                $temp_form[$parent]['#name'] = 'wpcf_post_relationship[' . $item->ID . '][parents][' . $parent . ']';
                $row_data[] = wpcf_form_simple($temp_form);
            }
        }
    }
    if (!empty($row_data)) {
        $output = '';
        $output .= '<tr><td>' . implode('</td><td>', $row_data) . '<input type="hidden" name="wpcf_post_relationship[' . $item->ID . '][post_type]" value="' . $post_type . '" /></td><td class="actions">' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=pr_save_child_post&amp;post_type_parent=' . $parent_post_type . '&amp;post_id=' . $post->ID . '&amp;post_type_child=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_save_child_post')) . '" class="wpcf-pr-save-ajax button-secondary">' . __('Save') . '</a>';
        $output .= strpos($item->ID, 'new_') === false ? ' <a href="' . get_edit_post_link($item->ID) . '" class="button-secondary">' . __('Edit') . '</a>' : '';
        $output .= strpos($item->ID, 'new_') === false ? ' <a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=pr_delete_child_post' . '&amp;post_id=' . $item->ID . '&_wpnonce=' . wp_create_nonce('pr_delete_child_post')) . '" class="wpcf-pr-delete-ajax button-secondary">' . __('Delete') . '</a>' : '';
        if ($date_trigger) {
            $output .= '<script type="text/javascript">
        //<![CDATA[
        jQuery(document).ready(function(){
            wpcfFieldsDateInit("#wpcf-post-relationship");
        });
        //]]>
    </script>';
        }
        $output .= wpcf_form_render_js_validation('#post', false) . '</td></tr>';
        return $output;
    }
    return $output = '<tr><td><span style="color:Red;">' . __('Error occured', 'wpcf') . '</span></td></tr>';
}
Example #14
0
 /**
  * Returns HTML formatted row
  * 
  * While generating rows we collect headers too.
  * 
  * @return type
  */
 function row()
 {
     /*
      * Start output.
      * Output is returned as array - each element is <td> content.
      */
     $row = array();
     /*
      * LOOP over fields
      * Custom settings (specific)
      */
     if ($this->data['fields_setting'] == 'specific' && !empty($this->data['fields'])) {
         // Set title
         if (isset($this->data['fields']['_wp_title'])) {
             $this->headers[] = '_wp_title';
             $row[] = $this->title();
         }
         // Set body
         if (isset($this->data['fields']['_wp_body'])) {
             $this->headers[] = '_wp_body';
             $row[] = $this->body();
         }
         // Loop over Types fields
         foreach ($this->data['fields'] as $field_key => $true) {
             // Skip parents
             if (in_array($field_key, array('_wp_title', '_wp_body', '_wpcf_pr_parents'))) {
                 continue;
             } else {
                 /*
                  * Set field
                  */
                 $field_key = $this->cf->__get_slug_no_prefix($field_key);
                 $this->cf->set($this->child, $field_key);
                 $row[] = $this->field_form();
                 $this->_field_triggers();
                 // Add to header
                 $this->headers[] = $field_key;
             }
         }
         // Add parent forms
         if (!empty($this->data['fields']['_wpcf_pr_parents'])) {
             $_temp = (array) $this->data['fields']['_wpcf_pr_parents'];
             foreach ($_temp as $_parent => $_true) {
                 $row[] = $this->_parent_form($_parent);
                 // Add to header
                 $this->headers['__parents'][$_parent] = $_true;
             }
         }
         /*
          * 
          * 
          * 
          * 
          * DEFAULT SETTINGS
          */
     } else {
         // Set title
         $row[] = $this->title();
         $this->headers[] = '_wp_title';
         /*
          * Loop over groups and fields
          */
         // Get groups
         $groups = wpcf_admin_post_get_post_groups_fields($this->child, 'post_relationships');
         foreach ($groups as $group) {
             /*
              * Loop fields
              */
             foreach ($group['fields'] as $field_key => $field) {
                 /*
                  * Set field
                  */
                 $field_key = $this->cf->__get_slug_no_prefix($field_key);
                 $this->cf->set($this->child, $field_key);
                 $row[] = $this->field_form();
                 $this->_field_triggers();
                 // Add to header{
                 $this->headers[] = $field_key;
             }
         }
     }
     return $row;
 }
Example #15
0
 /**
  * Process AJAX conditional verify.
  * 
  * @global type $wpcf
  * @param type $data
  * @return boolean|string
  */
 public static function conditionalVerify($data)
 {
     WPCF_Loader::loadInclude('fields');
     WPCF_Loader::loadInclude('fields-post');
     WPCF_Loader::loadInclude('conditional-display');
     global $wpcf;
     $js_execute = '';
     $_flag_relationship = false;
     /*
      * 
      * Determine post.
      */
     if (empty($data['wpcf']) && !empty($data['wpcf_post_relationship'])) {
         /*
          * Relationship case
          */
         $_temp = $data['wpcf_post_relationship'];
         $parent_id = key($_temp);
         $_data = array_shift($_temp);
         $post_id = key($_data);
         $post = get_post($post_id);
         $posted_fields = $_data[$post_id];
         $_flag_relationship = true;
         /*
          * 
          * Regular submission
          */
     } else {
         if (isset($data['wpcf_main_post_id'])) {
             $post_id = intval($data['wpcf_main_post_id']);
             $post = get_post($post_id);
         }
     }
     // No post
     if (empty($post->ID)) {
         return false;
     }
     // Get Groups (Fields) for current post
     $groups = wpcf_admin_post_get_post_groups_fields($post);
     $_processed = array();
     foreach ($groups as $group) {
         if (!empty($group['fields'])) {
             foreach ($group['fields'] as $field_id => $field) {
                 // Check if already processed
                 if (isset($_processed[$field_id])) {
                     continue;
                 }
                 if ($wpcf->conditional->is_conditional($field_id)) {
                     if ($_flag_relationship) {
                         // Process only submitted fields
                         if (!isset($posted_fields[WPCF_META_PREFIX . $field_id])) {
                             continue;
                         }
                         $wpcf->conditional->set($post, $field_id);
                         $wpcf->conditional->context = 'relationship';
                         $_relationship_name = false;
                         // Set name and other values processed by hooks
                         $parent = get_post($parent_id);
                         if (!empty($parent->ID)) {
                             $wpcf->relationship->set($parent, $post);
                             $wpcf->relationship->cf->set($post, $field_id);
                             $_child = $wpcf->relationship->get_child();
                             $_child->form->cf->set($post, $field_id);
                             $_relationship_name = $_child->form->alter_form_name('wpcf[' . $wpcf->conditional->cf['id'] . ']');
                         }
                         if (!$_relationship_name) {
                             continue;
                         }
                         /*
                          * BREAKPOINT
                          * Adds filtering regular evaluation (not wpv_conditional)
                          */
                         add_filter('types_field_get_submitted_data', 'wpcf_relationship_ajax_data_filter', 10, 2);
                         $name = $_relationship_name;
                     } else {
                         $wpcf->conditional->set($post, $field_id);
                         $name = 'wpcf[' . $wpcf->conditional->cf['id'] . ']';
                     }
                     // Evaluate
                     $passed = $wpcf->conditional->evaluate();
                     if ($passed) {
                         $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.' . 'wpcf-conditional' . '\').show().removeClass(\'' . 'wpcf-conditional' . '-failed\').addClass(\'' . 'wpcf-conditional' . '-passed\');' . " ";
                         $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.wpcf-repetitive-wrapper\').show();';
                     } else {
                         $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.wpcf-repetitive-wrapper\').hide();';
                         $js_execute .= 'jQuery(\'[name^="' . $name . '"]\').parents(\'.' . 'wpcf-conditional' . '\').hide().addClass(\'' . 'wpcf-conditional' . '-failed\').removeClass(\'' . 'wpcf-conditional' . '-passed\');' . " ";
                     }
                 }
                 $_processed[$field_id] = true;
             }
         }
     }
     return $js_execute;
 }