상속: extends RWMB_Field
예제 #1
0
 /**
  * Add actions
  *
  * @return void
  */
 static function add_actions()
 {
     // Do same actions as file field
     parent::add_actions();
     // Reorder images via Ajax
     add_action('wp_ajax_rwmb_reorder_images', array(__CLASS__, 'wp_ajax_reorder_images'));
 }
예제 #2
0
 /**
  * Add actions
  *
  * @return void
  */
 static function add_actions()
 {
     parent::add_actions();
     // Attach images via Ajax
     add_action('wp_ajax_rwmb_attach_file', array(__CLASS__, 'wp_ajax_attach_file'));
     add_action('print_media_templates', array(__CLASS__, 'print_templates'));
 }
예제 #3
0
 /**
  * Get post meta
  *
  * @param string   $key     Meta key. Required.
  * @param int|null $post_id Post ID. null for current post. Optional
  * @param array    $args    Array of arguments. Optional.
  *
  * @return mixed
  */
 static function meta($key, $args = array(), $post_id = null)
 {
     $post_id = empty($post_id) ? get_the_ID() : $post_id;
     $args = wp_parse_args($args, array('type' => 'text', 'multiple' => false));
     // Always set 'multiple' true for following field types
     if (in_array($args['type'], array('checkbox_list', 'file', 'file_advanced', 'image', 'image_advanced', 'plupload_image', 'thickbox_image'))) {
         $args['multiple'] = true;
     }
     $meta = get_post_meta($post_id, $key, !$args['multiple']);
     // Get uploaded files info
     if (in_array($args['type'], array('file', 'file_advanced'))) {
         if (is_array($meta) && !empty($meta)) {
             $files = array();
             foreach ($meta as $id) {
                 // Get only info of existing attachments
                 if (get_attached_file($id)) {
                     $files[$id] = RWMB_File_Field::file_info($id);
                 }
             }
             $meta = $files;
         }
     } elseif (in_array($args['type'], array('image', 'plupload_image', 'thickbox_image', 'image_advanced'))) {
         if (is_array($meta) && !empty($meta)) {
             $images = array();
             foreach ($meta as $id) {
                 // Get only info of existing attachments
                 if (get_attached_file($id)) {
                     $images[$id] = RWMB_Image_Field::file_info($id, $args);
                 }
             }
             $meta = $images;
         }
     } elseif ('taxonomy_advanced' == $args['type']) {
         if (!empty($args['taxonomy'])) {
             $term_ids = array_map('intval', array_filter(explode(',', $meta . ',')));
             // Allow to pass more arguments to "get_terms"
             $func_args = wp_parse_args(array('include' => $term_ids, 'hide_empty' => false), $args);
             unset($func_args['type'], $func_args['taxonomy'], $func_args['multiple']);
             $meta = get_terms($args['taxonomy'], $func_args);
         } else {
             $meta = array();
         }
     } elseif ('taxonomy' == $args['type']) {
         $meta = empty($args['taxonomy']) ? array() : get_the_terms($post_id, $args['taxonomy']);
     } elseif ('map' == $args['type']) {
         $field = array('id' => $key, 'multiple' => false, 'clone' => false);
         $meta = RWMB_Map_Field::the_value($field, $args, $post_id);
     } elseif ('oembed' == $args['type']) {
         $field = array('id' => $key, 'clone' => isset($args['clone']) ? $args['clone'] : false, 'multiple' => isset($args['multiple']) ? $args['multiple'] : false);
         $meta = RWMB_OEmbed_Field::the_value($field, $args, $post_id);
     }
     return apply_filters('rwmb_meta', $meta, $key, $args, $post_id);
 }
예제 #4
0
파일: image.php 프로젝트: rilwis/meta-box
 /**
  * Enqueue scripts and styles.
  */
 public static function admin_enqueue_scripts()
 {
     parent::admin_enqueue_scripts();
     wp_enqueue_style('rwmb-image', RWMB_CSS_URL . 'image.css', array(), RWMB_VER);
 }
예제 #5
0
 /**
  * Get uploaded file information.
  *
  * @param int   $file_id Attachment image ID (post ID). Required.
  * @param array $args    Array of arguments (for size).
  * @return array|bool False if file not found. Array of image info on success
  */
 static function file_info($file_id, $args = array())
 {
     return RWMB_File_Field::file_info($file_id, $args);
 }
예제 #6
0
파일: media.php 프로젝트: rilwis/meta-box
 /**
  * Save meta value
  *
  * @param $new
  * @param $old
  * @param $post_id
  * @param $field
  */
 public static function save($new, $old, $post_id, $field)
 {
     delete_post_meta($post_id, $field['id']);
     parent::save($new, array(), $post_id, $field);
 }
예제 #7
0
 /**
  * Add actions
  *
  * @return void
  */
 static function add_actions()
 {
     parent::add_actions();
     // Attach images via Ajax
     add_action('wp_ajax_rwmb_attach_file', array(__CLASS__, 'wp_ajax_attach_file'));
 }