예제 #1
0
function ptn_setup_custom_fields()
{
    if (is_admin()) {
        include_once dirname(__FILE__) . '/enhanced-custom-fields/enhanced-custom-fields.php';
        $sections = array();
        $fields = array();
        $newsletter_panel =& new PECF_Panel('newsletter-data', 'Select posts for newsletter', PTN_NEWSLETTER_POST_TYPE, 'normal', 'high');
        if (get_option('ptn_highlights') != 'dont_show') {
            $fields[] = PECF_Field::factory('selectMulti', 'highlights');
            $sections[] = 'highlights';
        }
        if (get_option('ptn_featured_post') != 'dont_show') {
            $fields[] = PECF_Field::factory('select', 'featured_post');
            $sections[] = 'featured_post';
        }
        if (get_option('ptn_main_articles') != 'dont_show') {
            $fields[] = PECF_Field::factory('selectMulti', 'main_articles', 'Main section');
            $sections[] = 'main_articles';
        }
        if (get_option('ptn_side_articles') != 'dont_show') {
            $fields[] = PECF_Field::factory('selectMulti', 'side_articles', 'Side section');
            $sections[] = 'side_articles';
        }
        // add posts to sections
        $i = 0;
        foreach ($sections as $section) {
            // for multiselects, get selected posts and put them at the top in the correct order
            $featured_post_options = array();
            $all_posts = get_post_meta($_GET['post'], '_' . $section, true);
            $post_IDs = "";
            $j = 0;
            if (is_array($all_posts)) {
                foreach ($all_posts as $post_ID) {
                    $j++;
                    if ($j > 1) {
                        $post_IDs .= ",";
                    }
                    $post_IDs .= $post_ID;
                    $selected_post = get_post($post_ID);
                    $featured_post_options[$selected_post->ID] = $selected_post->post_title;
                }
            }
            // get the rest of the posts
            $post_type = get_option('ptn_' . $section);
            $latest_posts = get_posts('post_type=' . $post_type . '&numberposts=' . get_option('ptn_number_latest_posts') . '&exclude=' . $post_IDs);
            foreach ($latest_posts as $post) {
                $featured_post_options[$post->ID] = $post->post_title;
            }
            $fields[$i]->add_options($featured_post_options);
            $i++;
        }
        $fields[] = PECF_Field::factory('media', 'header_image', 'Header Image')->set_labels('Header Image')->set_post_type(PTN_NEWSLETTER_POST_TYPE)->help_text('<p style="color:red">Note: Make sure to click the button that says "Header Image", and NOT the "Insert into Post" button. <br />If you upload your own image, you\'ll have to click the "Save all changes" button first, then click the "Show" link next to your image, then click the "Header Image" button.</p>');
        $newsletter_panel->add_fields($fields);
    }
}
예제 #2
0
 function render_field()
 {
     $return = '';
     if ($this->is_multiply) {
         foreach ($this->values as $val) {
             // create new field object.
             $field = PECF_Field::factory($this->type, $this->name, $this->label);
             $field->post_id = $this->post_id;
             $field->value = $val;
             $field->is_subfield = true;
             $return .= $field->render();
         }
     }
     $return .= $this->render();
     return $return;
 }