*/ /** * custom product post_type */ function aml_product_type() { $slug_base = aml_get_option('aml_slug_base'); $slug_product = aml_get_option('aml_slug_product'); $labels = array( 'name' => _x('Products', 'post type general name', 'amazon-library'), 'singular_name' => _x('Product', 'post type singular name', 'amazon-library'), 'add_new_item' => __('Add New Product', 'amazon-library'), 'edit_item' => __('Edit Product', 'amazon-library'), 'new_item' => __('New Product', 'amazon-library'), 'view_item' => __('View Product', 'amazon-library'), 'search_items' => __('Search Products', 'amazon-library'), 'not_found' => __('No products found', 'amazon-library'), 'not_found_in_trash' => __('No products found in Trash', 'amazon-library'), ); $args = array( 'description' => __('Product information and pictures fetched from Amazon. Similar to Amazon, an "official" review can be entered in the product page while individual users can also provide their own reviews in their shelves.'), 'rewrite' => array('slug' => "$slug_base/$slug_product", 'pages' => false, 'feeds' => false, 'with_front' => false), 'register_meta_box_cb' => 'aml_product_boxes', 'capability_type' => 'product', 'supports' => array('title'), 'has_archive' => $slug_base, 'map_meta_cap' => true, 'hierarchical' => true, 'menu_position' => 10, 'labels' => $labels, 'query_var' => true, 'public' => true, ); register_post_type('aml_product', $args); add_filter('archive_template', 'aml_product_archive_template'); add_filter('single_template', 'aml_product_single_template'); } /** * people taxonomy for products */ function aml_people_tax() { $slug_base = aml_get_option('aml_slug_base'); $slug_person = aml_get_option('aml_slug_person'); $labels = array( 'name' => _x('People', 'taxonomy general name', 'amazon-library'), 'singular_name' => _x('Person', 'taxonomy singular name', 'amazon-library'), 'search_items' => __('Search People', 'amazon-library'), 'popular_items' => __('Popular People', 'amazon-library'), 'all_items' => __('All People', 'amazon-library'), 'edit_item' => __('Edit Person', 'amazon-library'), 'update_item' => __('Update Person', 'amazon-library'), 'add_new_item' => __('Add New Person', 'amazon-library'), 'new_item_name' => __('New Person', 'amazon-library'), 'add_or_remove_items' => __('Add or remove people'), 'choose_from_most_used' => __('Choose from the most used people'), 'separate_items_with_commas' => __('Separate people\'s names with commas', 'amazon-library'), ); $capabilities = array( 'manage_terms' => 'edit_products', 'delete_terms' => 'delete_products', 'assign_terms' => 'edit_products', 'edit_terms' => 'edit_products', ); $args = array( 'rewrite' => array('slug' => "$slug_base/$slug_person", 'pages' => true, 'feeds' => true, 'with_front' => false), 'capabilities' => $capabilities, 'query_var' => 'aml_person', 'hierarchical' => false, 'labels' => $labels, ); register_taxonomy('aml_person','aml_product', $args); add_filter('taxonomy_template', 'aml_person_taxonomy_template'); } /** * callback from registering aml_product to generate meta boxes on an edit page */ function aml_product_boxes() { add_meta_box('aml_product_search', __('Search Amazon', 'amazon-library'), 'aml_mb_amazon_search', 'aml_product', 'normal', 'high'); add_meta_box('aml_product_meta', __('Additional Information', 'amazon-library'), 'aml_mb_product_meta', 'aml_product', 'side', 'high'); wp_enqueue_script( 'aml-product-script', plugins_url('/js/amazon.product.js', __FILE__) ); wp_enqueue_style( 'aml-product-style', plugins_url('/css/amazon.product.css', __FILE__) ); } /** * meta-box for Amazon search * @todo push html to template functions */ function aml_mb_amazon_search() { $aml_categories = aml_amazon::$categories; ?> ID, 'aml_type', true); $asin = get_post_meta($post->ID, 'aml_asin', true); $link = get_post_meta($post->ID, 'aml_link', true); $image = get_post_meta($post->ID, 'aml_image', true); $image_preview = (empty($image)) ? '' : 'preview'; $aml_categories = aml_amazon::$categories; ?>
'.$asin.''; if (empty($image)) { $img = $asin; $asin = ''; } else { $img = ''.$asin; } if (empty($img)) { $img = ''; } $img = (!empty($link)) ? ''.$img.'' : $img; echo '
'.$img.'
'; break; case 'people': $terms = get_the_term_list($post_id, 'aml_person', '', ', '); echo $terms; break; case 'tags': $terms = get_the_term_list($post_id, 'aml_tag', '', ', '); echo $terms; break; case 'connect': break; } } /** * display counts in the diashboard * @todo push html to template functions */ function aml_product_right_now() { $num_posts = wp_count_posts('aml_product'); $num = number_format_i18n($num_posts->publish); $text = _n('Product', 'Products', intval($num_posts->publish), 'amazon-library'); if (current_user_can('edit_products')) { $num = '' . $num . ''; $text = '' . $text . ''; } echo ''; echo ''.$num.''; echo '' . $text . ''; echo ''; } /** * initialise and register the actions for product post_type */ function aml_init_product() { aml_product_type(); aml_people_tax(); add_action('manage_aml_product_posts_custom_column', 'aml_product_display_columns', 10, 2); add_action('manage_edit-aml_product_columns', 'aml_product_register_columns'); add_action('right_now_content_table_end', 'aml_product_right_now'); add_action('save_post', 'aml_product_meta_postback'); } ?>