Beispiel #1
0
 /**
  * Initialize by constructing metaboxes based on supported post formats
  *
  * @since 1.0
  */
 public function init()
 {
     if ($post_formats_support = get_theme_support('post-formats')) {
         /* Get supported post formats */
         if (!isset($post_formats_support[0]) || !is_array($post_formats_support[0])) {
             $post_formats_support = get_post_format_slugs();
         } else {
             $post_formats_support = $post_formats_support[0];
         }
         /* Prepare post format metaboxes */
         $this->metaboxes = array();
         foreach ($post_formats_support as $post_format) {
             if (is_callable("youxi_post_format_{$post_format}_metabox")) {
                 $metabox_id = youxi_post_format_id($post_format);
                 $metabox = call_user_func("youxi_post_format_{$post_format}_metabox");
                 $this->metaboxes[$post_format] = array_merge(array('id' => $metabox_id, 'html_classes' => array('youxi-metabox')), $metabox);
             }
         }
         /* Attach metabox on each supported post types */
         foreach ((array) youxi_post_format_post_types() as $post_type) {
             /* Make sure it's an existing post type */
             if (!post_type_exists($post_type)) {
                 continue;
             }
             /* Get the post type wrapper object */
             $post_type_object = Youxi_Post_Type::get($post_type);
             /* Add the metaboxes */
             foreach ($this->metaboxes as $metabox) {
                 $post_type_object->add_meta_box(new Youxi_Metabox($metabox['id'], $metabox));
             }
         }
         /* Prepare on the 'add_meta_boxes' hook */
         add_action('add_meta_boxes', array($this, 'prepare'));
     }
 }
Beispiel #2
0
 function helium_extract_post_format_meta($post = null)
 {
     $post = get_post($post);
     if (is_a($post, 'WP_Post') && function_exists('youxi_post_format_id')) {
         $post_format = get_post_format($post->ID);
         $meta_key = youxi_post_format_id($post_format);
         $post_meta = (array) $post->{$meta_key};
         switch ($post_format) {
             case 'video':
                 $post_meta = wp_parse_args($post_meta, array('type' => '', 'embed' => '', 'src' => '', 'poster' => ''));
                 if ('embed' == $post_meta['type'] && '' !== $post_meta['embed'] || 'hosted' == $post_meta['type'] && '' !== $post_meta['src']) {
                     return $post_meta;
                 }
                 break;
             case 'audio':
                 $post_meta = wp_parse_args($post_meta, array('type' => '', 'embed' => '', 'src' => ''));
                 if ('embed' == $post_meta['type'] && '' !== $post_meta['embed'] || 'hosted' == $post_meta['type'] && '' !== $post_meta['src']) {
                     return $post_meta;
                 }
                 break;
             case 'gallery':
                 $post_meta = wp_parse_args($post_meta, array('images' => array(), 'type' => 'slider'));
                 if (!empty($post_meta['images']) && is_array($post_meta['images'])) {
                     return $post_meta;
                 }
                 break;
             default:
                 break;
         }
     }
 }