Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function brush_packs() {
- $labels = array(
- 'name' => _x( 'Brush Packs', 'post type general name' ),
- 'singular_name' => _x( 'Brush Pack', 'post type singular name' ),
- 'add_new' => _x( 'Add New', 'brushes' ),
- 'add_new_item' => __( 'Add New Brush Pack' ),
- 'edit_item' => __( 'Edit Brush Pack' ),
- 'new_item' => __( 'New Brush Pack' ),
- 'all_items' => __( 'All Brushes' ),
- 'view_item' => __( 'View Brushes' ),
- 'search_items' => __( 'Search Brushes' ),
- 'not_found' => __( 'No Brushes found' ),
- 'not_found_in_trash' => __( 'No Brushes found in the Trash' ),
- 'parent_item_colon' => '',
- 'menu_name' => 'Brushes'
- );
- $args = array(
- 'labels' => $labels,
- 'description' => 'text',
- 'public' => true,
- 'menu_position' => 5,
- 'menu_icon' => 'dashicons-admin-customizer',
- 'supports' => array( 'title', 'thumbnail'),
- 'has_archive' => true,
- );
- register_post_type( 'brushes', $args );
- }
- add_action( 'init', 'brush_packs' );
- function brushes_taxonomy() {
- register_taxonomy(
- 'brushes_categories', //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
- 'brushes', //post type name
- array(
- 'hierarchical' => true,
- 'label' => 'Brush Types', //Display name
- 'query_var' => true,
- 'rewrite' => array(
- 'slug' => 'brushes', // This controls the base slug that will display before each term
- 'with_front' => false // Don't display the category base before
- )
- )
- );
- }
- add_action( 'init', 'brushes_taxonomy');
- function add_custom_meta_boxes() {
- // Define the custom attachment for posts
- add_meta_box(
- 'brush_pack_attachment',
- 'Custom Attachment',
- 'brush_pack_attachment',
- 'brushes',
- 'normal'
- );
- } // end add_custom_meta_boxes
- add_action('add_meta_boxes', 'add_custom_meta_boxes');
- function brush_pack_attachment() {
- wp_nonce_field(plugin_basename(__FILE__), 'brush_pack_attachment_nonce');
- $html = '<p class="description">';
- $html .= 'Upload your PDF here.';
- $html .= '</p>';
- $html .= '<input type="file" id="brush_pack_attachment" name="brush_pack_attachment" value="" size="25" />';
- echo $html;
- } // end brush_pack_attachment
- function save_custom_meta_data($id) {
- /* --- security verification --- */
- if(!wp_verify_nonce($_POST['brush_pack_attachment_nonce'], plugin_basename(__FILE__))) {
- return $id;
- } // end if
- if(defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
- return $id;
- } // end if
- if('brushes' == $_POST['post_type']) {
- if(!current_user_can('edit_page', $id)) {
- return $id;
- } // end if
- } else {
- if(!current_user_can('edit_page', $id)) {
- return $id;
- } // end if
- } // end if
- /* - end security verification - */
- // Make sure the file array isn't empty
- if(!empty($_FILES['brush_pack_attachment']['name'])) {
- // Setup the array of supported file types. In this case, it's just PDF.
- $supported_types = array('application/pdf');
- // Get the file type of the upload
- $arr_file_type = wp_check_filetype(basename($_FILES['brush_pack_attachment']['name']));
- $uploaded_type = $arr_file_type['type'];
- // Check if the type is supported. If not, throw an error.
- if(in_array($uploaded_type, $supported_types)) {
- // Use the WordPress API to upload the file
- $upload = wp_upload_bits($_FILES['brush_pack_attachment']['name'], null, file_get_contents($_FILES['brush_pack_attachment']['tmp_name']));
- if(isset($upload['error']) && $upload['error'] != 0) {
- wp_die('There was an error uploading your file. The error is: ' . $upload['error']);
- } else {
- add_post_meta($id, 'brush_pack_attachment', $upload);
- update_post_meta($id, 'brush_pack_attachment', $upload);
- } // end if/else
- } else {
- wp_die("The file type that you've uploaded is not a PDF.");
- } // end if/else
- } // end if
- } // end save_custom_meta_data
- add_action('save_post', 'save_custom_meta_data');
- function update_edit_form() {
- echo ' enctype="multipart/form-data"';
- } // end update_edit_form
- add_action('post_edit_form_tag', 'update_edit_form');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement