Exemple #1
0
 /**
  * Loops through and displays fields
  * @since  1.0.0
  * @param  array  $meta_box    Metabox config array
  * @param  int    $object_id   Object ID
  * @param  string $object_type Type of object being saved. (e.g., post, user, or comment)
  */
 public static function show_form($meta_box, $object_id = 0, $object_type = '')
 {
     $meta_box = self::set_mb_defaults($meta_box);
     // Set/get type
     $object_type = self::set_object_type($object_type ? $object_type : self::set_mb_type($meta_box));
     // Set/get ID
     $object_id = self::set_object_id($object_id ? $object_id : self::get_object_id());
     // Add nonce only once per page.
     if (!self::$nonce_added) {
         wp_nonce_field(self::nonce(), 'wp_meta_box_nonce', false, true);
         self::$nonce_added = true;
     }
     // Use nonce for verification
     echo "\n<!-- Begin CMB Fields -->\n";
     do_action('cmb_before_table', $meta_box, $object_id, $object_type);
     echo '<table class="form-table cmb_metabox">';
     foreach ($meta_box['fields'] as $field_args) {
         $field_args['context'] = $meta_box['context'];
         if ('group' == $field_args['type']) {
             if (!isset($field_args['show_names'])) {
                 $field_args['show_names'] = $meta_box['show_names'];
             }
             self::render_group($field_args);
         } else {
             $field_args['show_names'] = $meta_box['show_names'];
             // Render default fields
             $field = new cmb_Meta_Box_field($field_args);
             $field->render_field();
         }
     }
     echo '</table>';
     do_action('cmb_after_table', $meta_box, $object_id, $object_type);
     echo "\n<!-- End CMB Fields -->\n";
 }
Exemple #2
0
 /**
  * Loops through and displays fields
  * @since  1.0.0
  * @param  array  $meta_box    Metabox config array
  * @param  int    $object_id   Object ID
  * @param  string $object_type Type of object being saved. (e.g., post, user, or comment)
  */
 public static function show_form($meta_box, $object_id = 0, $object_type = '')
 {
     $meta_box = self::set_mb_defaults($meta_box);
     // Set/get type
     $object_type = self::set_object_type($object_type ? $object_type : self::set_mb_type($meta_box));
     // Set/get ID
     $object_id = self::set_object_id($object_id ? $object_id : self::get_object_id());
     // Add nonce only once per page.
     if (!self::$nonce_added) {
         // Use nonce for verification
         wp_nonce_field(self::nonce(), 'wp_meta_box_nonce', false, true);
         self::$nonce_added = true;
     }
     echo "\n<!-- Begin CMB Fields -->\n";
     /**
      * Hook before form table begins
      *
      * @param array  $meta_box    Metabox config array
      * @param int    $object_id   The ID of the current object
      * @param string $object_type The type of object you are working with.
      *	                           Usually `post` (this applies to all post-types).
      *	                           Could also be `comment`, `user` or `options-page`.
      */
     do_action('cmb_before_table', $meta_box, $object_id, $object_type);
     echo '<table class="form-table cmb_metabox">';
     foreach ($meta_box['fields'] as $field_args) {
         $field_args['context'] = $meta_box['context'];
         if ('group' == $field_args['type']) {
             if (!isset($field_args['show_names'])) {
                 $field_args['show_names'] = $meta_box['show_names'];
             }
             self::render_group($field_args);
         } else {
             $field_args['show_names'] = $meta_box['show_names'];
             // Render default fields
             $field = new cmb_Meta_Box_field($field_args);
             $field->render_field();
         }
     }
     echo '</table>';
     /**
      * Hook after form table has been rendered
      *
      * @param array  $meta_box    Metabox config array
      * @param int    $object_id   The ID of the current object
      * @param string $object_type The type of object you are working with.
      *	                           Usually `post` (this applies to all post-types).
      *	                           Could also be `comment`, `user` or `options-page`.
      */
     do_action('cmb_after_table', $meta_box, $object_id, $object_type);
     echo "\n<!-- End CMB Fields -->\n";
 }