Example #1
0
 /**
  * Function that creates the add form with the default fields
  *
  * @since 1.0.0	
  *	 	 
  * @param array $fields array of default fields	
  * @param string $form_name the name of the form
  * @param int $post_id the post ID
  * @return string $output form container and js ajax call to load the actual form.
  */
 function create_add_form($fields, $form_name, $post_id, $action = '')
 {
     $nonce = wp_create_nonce('wck-fep-add-post');
     if ($action == 'edit') {
         $fep_form = get_post($post_id);
         if ($fep_form) {
             $author_id = $fep_form->post_author;
             $user_ID = get_current_user_id();
             if (!current_user_can('edit_others_posts')) {
                 if ($author_id != $user_ID) {
                     $error = '<div class="fep-error fep-access-denied">' . __("You are not allowed to edit this post.", "wck") . '</div>';
                     return $error;
                 }
             }
         }
     }
     $form = '<form id="' . $form_name . '" method="post" action="">';
     $element_id = 0;
     if (function_exists('wck_cfc_create_boxes_args')) {
         $all_box_args = wck_cfc_create_boxes_args();
     }
     if (!empty($fields)) {
         foreach ($fields as $details) {
             do_action("wck_fep_before_form_{$form_name}_element_{$element_id}");
             $form .= apply_filters("wck_fep_filter_before_form_{$form_name}_element_{$element_id}", '<div id="fep-' . Wordpress_Creation_Kit::wck_generate_slug($details['title']) . '"  class="fep-element-wrap">', $details);
             if (empty($details['cfc'])) {
                 if ($action == 'edit') {
                     /* build edit values depending on the field */
                     $value = self::wck_fep_get_edit_value($post_id, $details);
                 } else {
                     $value = apply_filters('wck_fep_default_value_' . $form_name . '_' . Wordpress_Creation_Kit::wck_generate_slug($details['title']), '');
                 }
                 $form .= parent::wck_output_form_field($form_name, $details, $value, 'fep', $post_id);
             } else {
                 /* add CFC boxes created with Custom Fields Creator */
                 if (!empty($all_box_args)) {
                     foreach ($all_box_args as $box_args) {
                         if ($box_args['post_type'] == $this->args['post_type'] && $box_args['metabox_title'] == $details['title']) {
                             /* treat single cfcs case */
                             if ($box_args['single']) {
                                 $form .= '<div id="' . $box_args['meta_name'] . '" class="single-cfc">';
                                 if (!empty($box_args['meta_array'])) {
                                     foreach ($box_args['meta_array'] as $details) {
                                         if ($action == 'edit') {
                                             /* build edit values depending on the field */
                                             $value = self::wck_fep_get_edit_value($post_id, $details, $box_args['meta_name']);
                                         } else {
                                             $value = '';
                                         }
                                         $form .= '<div class="fep-single-element-wrap">';
                                         $form .= parent::wck_output_form_field($box_args['meta_name'], $details, $value, 'fep', $post_id);
                                         $form .= '</div>';
                                     }
                                 }
                                 $form .= '</div>';
                             } else {
                                 ob_start();
                                 parent::create_add_form($box_args['meta_array'], $box_args['meta_name'], get_post($post_id), 'fep');
                                 $parent_form = ob_get_contents();
                                 ob_end_clean();
                                 $form .= $parent_form;
                                 $form .= parent::wck_output_meta_content($box_args['meta_name'], $post_id, $box_args['meta_array'], $box_args);
                             }
                         }
                     }
                 }
             }
             $form .= apply_filters("wck_fep_filter_after_form_{$form_name}_element_{$element_id}", '</div>');
             do_action("wck_after_form_{$form_name}_element_{$element_id}");
             $element_id++;
         }
     }
     if ($action == 'edit') {
         $submit_text = apply_filters('wck_fep_form_button_update', __('Update Post', 'wck'), $form_name);
     } else {
         $submit_text = apply_filters('wck_fep_form_button_add', __('Add Post', 'wck'), $form_name);
     }
     $form .= '<input type="submit" id="submit_' . $form_name . '" value="' . $submit_text . '" onclick="wckFepAddPost(\'' . $form_name . '\', ' . $post_id . ', \'' . $action . '\', \'' . $nonce . '\');return false;"/>';
     $form .= '</form>';
     return $form;
 }
Example #2
0
function wck_cfc_create_boxes()
{
    $all_box_args = wck_cfc_create_boxes_args();
    if (!empty($all_box_args)) {
        foreach ($all_box_args as $box_args) {
            new Wordpress_Creation_Kit($box_args);
        }
    }
}
/**
 * Funtion that retrieves all the CFC's for the selected post type in form args
 *
 * @since 1.0.0
 *
 * @param int $post_id Post ID of the form.	  
 * @return array $cfc_titles containing the Meta Boxes Titles created with CFC.
 */
function wck_fep_get_cfcs_for_post_type($post_id)
{
    $cfc_titles = array();
    if (function_exists('wck_cfc_create_boxes_args')) {
        $all_box_args = wck_cfc_create_boxes_args();
        if (!empty($all_box_args)) {
            foreach ($all_box_args as $box_args) {
                $form_args = get_post_meta($post_id, 'wck_fep_args', true);
                if (!empty($form_args)) {
                    if ($box_args['post_type'] == $form_args[0]['post-type']) {
                        $cfc_titles[] = 'CFC-' . $box_args['metabox_title'];
                    }
                }
            }
        }
    }
    return $cfc_titles;
}