Ejemplo n.º 1
0
/**
 * Meta boxes contents output.
 * 
 * @param type $post
 * @param type $args 
 */
function wpcf_pr_admin_post_meta_box_output($post, $args)
{
    $output = '';
    $relationships = $args;
    $post_id = !empty($post->ID) ? $post->ID : -1;
    $current_post_type = wpcf_admin_get_post_type($post);
    if (!empty($relationships['has'])) {
        foreach ($relationships['has'] as $post_type => $data) {
            $output_temp = wpcf_pr_admin_post_meta_box_has_form($post, $post_type, $data, $relationships['post_type']);
            if (!empty($output_temp)) {
                $post_type_object = get_post_type_object($post_type);
                $output .= '<div class="wpcf-pr-has-entries">' . '<div class="wpcf-pr-has-title">' . $post_type_object->label . '</div>' . '<a class="button-primary wpcf-pr-save-all-link" href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;wpcf_action=pr_save_all' . '&amp;post_id=' . $post->ID . '&amp;post_type=' . $post_type . '&amp;_wpnonce=' . wp_create_nonce('pr_save_all')) . '">' . __('Save All', 'wpcf') . '</a>' . '<a href="' . admin_url('admin-ajax.php?action=wpcf_ajax&amp;' . 'wpcf_action=pr_add_child_post&amp;post_type_parent=' . $relationships['post_type'] . '&amp;post_id=' . $post_id . '&amp;post_type_child=' . $post_type . '&_wpnonce=' . wp_create_nonce('pr_add_child_post')) . '" style="line-height:40px;" class="wpcf-pr-ajax-link button-secondary">' . $post_type_object->labels->add_new_item . '</a>' . '<div class="wpcf-pr-pagination-update">' . $output_temp . '</div>' . '</div>';
            }
        }
    }
    if (!empty($relationships['belongs'])) {
        $meta = get_post_custom($post_id);
        $belongs = array('belongs' => array(), 'posts' => array());
        foreach ($meta as $meta_key => $meta_value) {
            if (strpos($meta_key, '_wpcf_belongs_') === 0) {
                $temp_post = get_post($meta_value[0]);
                if (!empty($temp_post)) {
                    $belongs['posts'][$temp_post->ID] = $temp_post;
                    $belongs['belongs'][$temp_post->post_type] = $temp_post->ID;
                }
            }
        }
        $output_temp = '';
        foreach ($relationships['belongs'] as $post_type => $data) {
            $output_temp .= wpcf_form_simple(wpcf_pr_admin_post_meta_box_belongs_form($post, $post_type, $belongs));
        }
        if (!empty($output_temp)) {
            $output .= '<div style="margin: 20px 0 10px 0">' . sprintf(__('This %s belongs to:', 'wpcf'), $current_post_type) . '</div>' . $output_temp;
        }
    }
    return $output;
}
Ejemplo n.º 2
0
/**
 * Meta boxes contents output.
 * 
 * @param type $post
 * @param type $args 
 */
function wpcf_pr_admin_post_meta_box_output($post, $args)
{
    if (empty($post->ID)) {
        return false;
    }
    global $wpcf;
    $output = '';
    $relationships = $args;
    $post_id = !empty($post->ID) ? $post->ID : -1;
    $current_post_type = wpcf_admin_get_post_type($post);
    /*
     * 
     * 
     * 
     * Render has form (child form)
     */
    if (!empty($relationships['has'])) {
        foreach ($relationships['has'] as $post_type => $data) {
            $output .= $wpcf->relationship->child_meta_form($post, $post_type, $data);
        }
    }
    /*
     * 
     * 
     * 
     * Render belongs form (parent form)
     */
    if (!empty($relationships['belongs'])) {
        $meta = get_post_custom($post_id);
        $belongs = array('belongs' => array(), 'posts' => array());
        foreach ($meta as $meta_key => $meta_value) {
            if (strpos($meta_key, '_wpcf_belongs_') === 0) {
                $temp_post = get_post($meta_value[0]);
                if (!empty($temp_post)) {
                    $belongs['posts'][$temp_post->ID] = $temp_post;
                    $belongs['belongs'][$temp_post->post_type] = $temp_post->ID;
                }
            }
        }
        $output_temp = '';
        foreach ($relationships['belongs'] as $post_type => $data) {
            $output_temp .= wpcf_form_simple(wpcf_pr_admin_post_meta_box_belongs_form($post, $post_type, $belongs));
        }
        if (!empty($output_temp)) {
            $output .= '<div style="margin: 20px 0 10px 0">' . sprintf(__('This %s belongs to:', 'wpcf'), $current_post_type) . '</div>' . $output_temp;
        }
    }
    return $output;
}