/**
  * Construct function.
  */
 function __construct($parent_post, $child_post_type, $data)
 {
     WPCF_Loader::loadModel('relationship');
     $this->parent = $parent_post;
     $this->parent_post_type = $parent_post->post_type;
     $this->child_post_type = $child_post_type;
     $this->data = $data;
     // Clean data
     if (empty($this->data['fields_setting'])) {
         $this->data['fields_setting'] = 'all_cf';
     }
     $this->cf = new WPCF_Field();
     $this->cf->context = 'relationship';
     $this->children = WPCF_Relationship_Model::getChildrenByPostType($this->parent, $this->child_post_type, $this->data, $_GET);
     // If no children - use dummy post
     if (empty($this->children)) {
         $_dummy_post = get_default_post_to_edit($this->child_post_type, false);
         $this->children = array($_dummy_post);
         $this->_dummy_post = true;
     }
     $this->child_post_type_object = get_post_type_object($this->child_post_type);
     // Collect params from request
     foreach ($this->__params as $__param) {
         if (isset($_GET[$__param])) {
             $this->__urlParams[$__param] = $_GET[$__param];
         }
     }
     $post_types = get_option('wpcf-custom-types', array());
     if (array_key_exists($child_post_type, $post_types) && array_key_exists('supports', $post_types[$child_post_type])) {
         foreach ($post_types[$child_post_type]['supports'] as $key => $value) {
             $this->child_supports[$key] = (bool) $value;
         }
     }
     unset($post_types);
 }
Exemple #2
0
 /**
  * Construct function.
  */
 function __construct($parent_post, $child_post_type, $data)
 {
     WPCF_Loader::loadModel('relationship');
     $this->parent = $parent_post;
     $this->parent_post_type = $parent_post->post_type;
     $this->child_post_type = $child_post_type;
     $this->data = $data;
     // Clean data
     if (empty($this->data['fields_setting'])) {
         $this->data['fields_setting'] = 'all_cf';
     }
     $this->cf = new WPCF_Field();
     $this->cf->context = 'relationship';
     $this->children = WPCF_Relationship_Model::getChildrenByPostType($this->parent, $this->child_post_type, $this->data, $_GET);
     // If no children - use dummy post
     if (empty($this->children)) {
         $_dummy_post = get_default_post_to_edit($this->child_post_type, false);
         $this->children = array($_dummy_post);
         $this->_dummy_post = true;
     }
     $this->child_post_type_object = get_post_type_object($this->child_post_type);
     // Collect params from request
     foreach ($this->__params as $__param) {
         if (isset($_GET[$__param])) {
             $this->__urlParams[$__param] = $_GET[$__param];
         }
     }
 }
Exemple #3
0
 /**
  * Construct function.
  */
 function __construct($parent_post, $child_post_type, $data)
 {
     WPCF_Loader::loadModel('relationship');
     $this->parent = $parent_post;
     $this->parent_post_type = $parent_post->post_type;
     $this->child_post_type = $child_post_type;
     $this->data = $data;
     // Clean data
     if (empty($this->data['fields_setting'])) {
         $this->data['fields_setting'] = 'all_cf';
     }
     $this->cf = new WPCF_Field();
     $this->cf->context = 'relationship';
     $this->children = WPCF_Relationship_Model::getChildrenByPostType($this->parent, $this->child_post_type, $this->data, $_GET);
     // If no children - use dummy post
     if (empty($this->children)) {
         $_dummy_post = get_default_post_to_edit($this->child_post_type, false);
         $this->children = array($_dummy_post);
         $this->_dummy_post = true;
     }
     $this->child_post_type_object = get_post_type_object($this->child_post_type);
     if (!isset($this->child_post_type_object->slug) && isset($this->child_post_type_object->name)) {
         $this->child_post_type_object->slug = $this->child_post_type_object->name;
     }
     // Collect params from request
     foreach ($this->__params as $__param) {
         if (isset($_GET[$__param])) {
             $this->__urlParams[$__param] = $_GET[$__param];
         }
     }
     /**
      * build-in types
      */
     if (in_array($child_post_type, array('page', 'post', 'attachment', 'revision', 'nav_menu_item'))) {
         foreach (array_keys($this->child_supports) as $key) {
             $this->child_supports[$key] = post_type_supports($child_post_type, $key);
         }
         return;
     }
     /**
      * post types
      */
     $post_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array());
     if (array_key_exists($child_post_type, $post_types) && array_key_exists('supports', $post_types[$child_post_type])) {
         foreach ($post_types[$child_post_type]['supports'] as $key => $value) {
             $this->child_supports[$key] = (bool) $value;
         }
     }
     unset($post_types);
     /**
      * wp_enqueue_media allways
      */
     add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_media'), PHP_INT_MAX);
 }
Exemple #4
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;
}