_x('Shelves', 'post type general name', 'media-libraries'), 'singular_name' => _x('Shelf', 'post type singular name', 'media-libraries'), 'add_new_item' => __('Add New Shelf', 'media-libraries'), 'edit_item' => __('Edit Shelf', 'media-libraries'), 'new_item' => __('New Shelf', 'media-libraries'), 'view_item' => __('View Shelf', 'media-libraries'), 'search_items' => __('Search Shelves', 'media-libraries'), 'not_found' => __('No shelves found', 'media-libraries'), 'not_found_in_trash' => __('No shelves found in Trash', 'media-libraries'), ); $args = array( 'description' => __('Users can organise shelves to show which products they use (e.g. a DVD shelf, a book shelf, etc).'), 'rewrite' => array('slug' => "$slug_base/$slug_shelf", 'pages' => true, 'feeds' => true, 'with_front' => false), 'show_in_menu' => 'edit.php?post_type=ml_product', 'capability_type' => array('shelf', 'shelves'), 'register_meta_box_cb' => 'ml_shelf_boxes', 'supports' => array('title', 'author'), 'map_meta_cap' => true, 'hierarchical' => true, 'labels' => $labels, 'public' => true, ); register_post_type('ml_shelf', $args); add_filter('archive_template', 'ml_shelf_archive_template'); add_filter('single_template', 'ml_shelf_single_template'); } /** * Callback from ml_type_shelves() to generate meta boxes on an edit page */ function ml_shelf_boxes() { add_meta_box('ml_shelf_hide', __('Products on Shelf', 'media-libraries'), 'ml_shelf_mb_list', 'ml_shelf', 'normal', 'high'); add_meta_box('ml_shelf_add', __('Products in Library', 'media-libraries'), 'ml_shelf_mb_add', 'ml_shelf', 'side', 'high'); wp_enqueue_script('jquery'); wp_enqueue_script('utils'); wp_enqueue_script('hoverIntent'); wp_enqueue_script('common'); wp_enqueue_script('jquery-color'); wp_enqueue_script('jquery-ui-core'); wp_enqueue_script('jquery-ui-widget'); wp_enqueue_script('jquery-ui-mouse'); wp_enqueue_script('jquery-ui-sortable'); wp_enqueue_script('jquery-ui-draggable'); wp_enqueue_script('jquery-ui-droppable'); wp_enqueue_script( 'ml-shelf-script', plugins_url('/js/media.shelf.js', __FILE__) ); wp_enqueue_style( 'ml-fresh-style', plugins_url('/css/media.fresh.css', __FILE__) ); wp_enqueue_style( 'ml-shelf-style', plugins_url('/css/media.shelf.css', __FILE__) ); } /** * Meta Box for shelf display */ function ml_shelf_mb_list($post) { ml_shelf_page($post->ID, true); } /** * Meta Box for product list */ function ml_shelf_mb_add() { echo '
'; echo '
'; echo '
'; $args = array('numberposts' => -1, 'post_type' => 'ml_product'); $products = get_posts($args); if ($products) { foreach ($products as $product) { ml_product_thumbnail($product); } } echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; echo '
'; } /** * Register additional columns for manage products page */ function ml_shelf_register_columns($cols) { $cols['summary'] = 'Summary'; return $cols; } /** * Display additional columns for manage products page */ function ml_shelf_display_columns ($name, $post_id) { global $post; switch ($name) { case 'summary': // print total number of usages in shelf by status break; } } /** * Display shelves in the right now meta box */ function ml_shelf_right_now() { $num_posts = wp_count_posts('ml_shelf'); $num = number_format_i18n($num_posts->publish); $text = _n('Shelf', 'Shelves', intval($num_posts->publish), 'media-libraries'); if (current_user_can('edit_shelves')) { $num = '' . $num . ''; $text = '' . $text . ''; } echo ''; echo ''.$num.''; echo '' . $text . ''; echo ''; } /** * Register the actions for our product post_type */ function ml_init_shelf() { require_once dirname(__FILE__) . '/shelf-template.php'; ml_type_shelves(); add_action('manage_ml_shelf_posts_custom_column', 'ml_shelf_display_columns', 10, 2); add_action('manage_edit-ml_shelf_columns', 'ml_shelf_register_columns'); add_action('right_now_content_table_end', 'ml_shelf_right_now'); } ml_init_shelf();