Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
<?php
/**
* Plugin Name: UC Purchasing
* Description: Purchasing Contracts
* Version: 1.0
* Plugin URI:
* Domain Path:
* Network:
* Author: John Calande UITS Web Development Lab
* Copyright: UCONN April 2016
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
//
// If this plugin script is called directly,
// notify the user and abort.
//
if ( ! defined( 'ABSPATH' ) || ! defined( 'WPINC' ) ){
die( 'Sorry, no direct access to plugin scripts!' );
}
/**********************************************************************************
NOTES:
Our custom post type: Contract (uc_contract)
Note that you must call register_post_type()
before the admin_menu and after the after_setup_theme action hooks.
A good hook to use is the 'init' hook.
Do pay close attention to not having your custom post type identifier
exceed 20 characters though, as the post_type column in the database
is currently a VARCHAR field of that length.
Read more about Custom Post types here: https://codex.wordpress.org/Post_Types
QUESTIONS:
1. do we need to register taxonomies ? (param of capabilities)
***********************************************************************************/
class UC_Purchasing{
/**
* Create our hook for our create_post_type() method
* and hook our function to the 'init' action
*/
public function __construct(){
add_action( $tag_action_hook = 'init',
$function_to_call = array( $this, 'create_post_type' )
);
}
/**
* Register our new custom post type
*/
public function create_post_type() {
$labels = array(
'name' => __( 'Purchasing' ), // show 'Purchasing' in the menu
'menu_name' => __( 'Purchasing' ),
'singular_name' => __( 'Contract' ), // same as 'name_admin_bar'
'add_new_item' => __( 'Add New Contract' ),
'add_new' => __( 'Add New Contract' ),
'new_item' => __( 'New Contract' ),
'view_item' => __( 'View Contract' ),
'search_items' => __( 'Search Contracts' ),
'edit_item' => __( 'Edit Contract' ),
'not_found' => __( 'No contracts were found.' ),
'not_found_in_trash' => __( 'No contracts found in trash' ),
'all_items' => __( 'All Contracts' ), // show 'All Contracts' in the menu
);
$capabilities = array(
'edit_post' => 'edit_contract',
'read_post' => 'read_contract',
'read' => 'read',
'delete_post' => 'delete_contract',
'edit_posts' => 'edit_contracts',
'edit_others_posts' => 'edit_others_contracts',
'publish_posts' => 'publish_contracts',
'read_private_posts' => 'read_private_contracts',
'create_posts' => 'create_contracts', /* or edit_contracts? - based on the example provided in the documentation ??? */
);
$args = array(
'labels' => $labels,
'description' => __( 'Purchasing Contract' ),
/* Publicly show the post type on the administration screens and
to make it show up in the site content itself, if it's queried for. */
'public' => true,
/* Whether there should be post type archives */
'has_archive' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'Contract' ),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 75, // 75 - below Tools
'capabilities' => $capabilities,
);
register_post_type( 'uc_contract', $args );
} // create_post_type
} // Class UC_Purchasing
$uc_purchasing = new UC_Purchasing();
?>