wordpress important code

0
143

<?php
// This file creates the CCI Custom Content Types

// Create a Custom Content (Post) Type for Events
add_action( ‘init’, ‘create_post_type_event’, 1 );
function create_post_type_event() {
register_post_type( ‘cci_event’,
array(
‘labels’ => array(
‘name’ => __( ‘Events’ ),
‘singular_name’ => __( ‘Event’ ),
‘add_new’ => __( ‘Add Event’),
‘edit_item’ => __( ‘Edit Event’),
‘view_item’ => __( ‘View Event’)
),
‘description’ => ‘Use this content type to create events.’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘events’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
‘taxonomies’ => array(‘category’)
)
);
}

// Create a Custom Content (Post) Type for News
add_action( ‘init’, ‘create_post_type_news’, 1 );
function create_post_type_news() {
register_post_type( ‘cci_news’,
array(
‘labels’ => array(
‘name’ => __( ‘News’ ),
‘singular_name’ => __( ‘News’ ),
‘add_new’ => __( ‘Add News’),
‘edit_item’ => __( ‘Edit News’),
‘view_item’ => __( ‘View News’)
),
‘description’ => ‘Use this content type to create news.’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘news’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
‘taxonomies’ => array(‘category’)
)
);
}

// Create a Custom Content (Post) Type for Video
add_action( ‘init’, ‘create_post_type_video’, 1 );
function create_post_type_video() {
register_post_type( ‘cci_video’,
array(
‘labels’ => array(
‘name’ => __( ‘Video’ ),
‘singular_name’ => __( ‘Video’ ),
‘add_new’ => __( ‘Add Video’),
‘edit_item’ => __( ‘Edit Video’),
‘view_item’ => __( ‘View Video’)
),
‘description’ => ‘Use this content type to add new videos’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘video’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
//Remove ‘[custom xzy taxonomy]’ if not using custom taxonomies
‘taxonomies’ => array(‘category’)
)
);
}

// Create a Custom Content (Post) Type for Authors
add_action( ‘init’, ‘create_post_type_cauthors’, 1 );
function create_post_type_cauthors() {
register_post_type( ‘cci_cauthors’,
array(
‘labels’ => array(
‘name’ => __( ‘CCI Authors’ ),
‘singular_name’ => __( ‘CCI Author’ ),
‘add_new’ => __( ‘CCI Add Author’),
‘edit_item’ => __( ‘Edit CCI Author’),
‘view_item’ => __( ‘View CCI Author’)
),
‘description’ => ‘Use this content area to add new authors’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘cci-authors’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’, ‘category’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘taxonomies’ => array(‘category’,’companyname’)
)
);
}

// Create a Custom Content (Post) Type for Library
add_action( ‘init’, ‘create_post_type_library’, 1 );
function create_post_type_library() {
register_post_type( ‘cci_library’,
array(
‘labels’ => array(
‘name’ => __( ‘Leadership Library’ ),
‘singular_name’ => __( ‘Library Item’ ),
‘add_new’ => __( ‘Add Library Item’),
‘edit_item’ => __( ‘Edit Library Item’),
‘view_item’ => __( ‘View Library Item’)
),
‘description’ => ‘Use this content area to add items to the Leadership Library.’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘leadership-library’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘category’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
//Remove ‘[custom xzy taxonomy]’ if not using custom taxonomies
‘taxonomies’ => array(‘company’, ‘category’)
)
);
}

// Create a Custom Content (Post) Type for Jobs
add_action( ‘init’, ‘create_post_type_jobs’, 1 );
function create_post_type_jobs() {
register_post_type( ‘cci_jobs’,
array(
‘labels’ => array(
‘name’ => __( ‘Jobs’ ),
‘singular_name’ => __( ‘Job’ ),
‘add_new’ => __( ‘Add Job’),
‘edit_item’ => __( ‘Edit Job’),
‘view_item’ => __( ‘View Job’)
),
‘description’ => ‘Use this content type to add new Job listings.’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘jobs’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
//Remove ‘[custom xzy taxonomy]’ if not using custom taxonomies
‘taxonomies’ => array(‘category’)
)
);
}

// Create a Custom Content (Post) Type for Companies
add_action( ‘init’, ‘create_post_type_company’, 1 );
function create_post_type_company() {
register_post_type( ‘cci_companies’,
array(
‘labels’ => array(
‘name’ => __( ‘Company’ ),
‘singular_name’ => __( ‘Company’ ),
‘add_new’ => __( ‘Add Company’),
‘edit_item’ => __( ‘Edit Company’),
‘view_item’ => __( ‘View Company’)
),
‘description’ => ‘This is a custom post type to create a Company entry.’,
‘public’ => true,
‘has_archive’ => true,
‘rewrite’ => array(‘slug’ => ‘company’),
‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘thumbnail’, ‘excerpt’, ‘trackbacks’, ‘custom-fields’, ‘comments’, ‘revisions’, ‘page-attributes’, ‘post-formats’, ‘genesis-seo’),
‘menu_position’ => 6,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘show_in_menu’ => true,
‘query_var’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => true,
‘taxonomies’ => array(”)
)
);
}
?>

<?php

// Add Custom Post Types
add_action(‘init’, ‘papercutz_characters_init’);
function papercutz_characters_init()
{
$character_labels = array(
‘name’ => _x(‘Characters’, ‘post type general name’),
‘singular_name’ => _x(‘Character’, ‘post type singular name’),
‘all_items’ => __(‘All Characters’),
‘add_new’ => _x(‘Add new characters’, ‘characters’),
‘add_new_item’ => __(‘Add new characters’),
‘edit_item’ => __(‘Edit characters’),
‘new_item’ => __(‘New characters’),
‘view_item’ => __(‘View characters’),
‘search_items’ => __(‘Search in characters’),
‘not_found’ =>  __(‘No characters found’),
‘not_found_in_trash’ => __(‘No characters found in trash’),
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $character_labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’,’custom-fields’),
‘has_archive’ => ‘characters’
);
register_post_type(‘characters’,$args);
}
add_action(‘init’, ‘papercutz_authors_init’);
function papercutz_authors_init()
{
$author_labels = array(
‘name’ => _x(‘Authors & Artists’, ‘post type general name’),
‘singular_name’ => _x(‘Author & Artist’, ‘post type singular name’),
‘all_items’ => __(‘All Authors & Artists’),
‘add_new’ => _x(‘Add new Authors & Artists’, ‘authors’),
‘add_new_item’ => __(‘Add new authors & artists’),
‘edit_item’ => __(‘Edit authors & artists’),
‘new_item’ => __(‘New authors & artists’),
‘view_item’ => __(‘View authors & artists’),
‘search_items’ => __(‘Search in authors & artists’),
‘not_found’ =>  __(‘No authors & artists found’),
‘not_found_in_trash’ => __(‘No authors & artists found in trash’),
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $author_labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’,’custom-fields’),
‘has_archive’ => ‘authors’
);
register_post_type(‘authors’,$args);
}
add_action(‘init’, ‘papercutz_buzz_init’);
function papercutz_buzz_init()
{
$buzz_labels = array(
‘name’ => _x(‘Buzz’, ‘post type general name’),
‘singular_name’ => _x(‘Buzz’, ‘post type singular name’),
‘all_items’ => __(‘All Buzz’),
‘add_new’ => _x(‘Add new Buzz’, ‘buzz’),
‘add_new_item’ => __(‘Add new Buzz’),
‘edit_item’ => __(‘Edit Buzz’),
‘new_item’ => __(‘New Buzz’),
‘view_item’ => __(‘View Buzz’),
‘search_items’ => __(‘Search in Buzz’),
‘not_found’ =>  __(‘No Buzz found’),
‘not_found_in_trash’ => __(‘No Buzz found in trash’),
‘parent_item_colon’ => ”
);
$args = array(
‘labels’ => $buzz_labels,
‘public’ => true,
‘publicly_queryable’ => true,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => true,
‘capability_type’ => ‘post’,
‘hierarchical’ => false,
‘menu_position’ => 5,
‘supports’ => array(‘title’,’editor’,’author’,’thumbnail’,’excerpt’,’comments’,’custom-fields’),
‘has_archive’ => ‘buzz’
);
register_post_type(‘buzz’,$args);
}

// Add custom taxonomies
add_action( ‘init’, ‘papercutz_create_taxonomies’, 0 );

function papercutz_create_taxonomies()
{
// Comic Series
$series_labels = array(
‘name’ => _x( ‘Comic Series’, ‘taxonomy general name’ ),
‘singular_name’ => _x( ‘Comic Series’, ‘taxonomy singular name’ ),
‘search_items’ =>  __( ‘Search in comic series’ ),
‘all_items’ => __( ‘All comic series’ ),
‘most_used_items’ => null,
‘parent_item’ => null,
‘parent_item_colon’ => null,
‘edit_item’ => __( ‘Edit comic series’ ),
‘update_item’ => __( ‘Update comic series’ ),
‘add_new_item’ => __( ‘Add new comic series’ ),
‘new_item_name’ => __( ‘New comic series’ ),
‘menu_name’ => __( ‘Comic Series’ ),
);
register_taxonomy(‘comic-series’, array(‘characters’,’authors’,’buzz’), array(
‘hierarchical’ => true,
‘labels’ => $series_labels,
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’ => ‘comic-series’ )
));
}

?>

<?php
function remove_menus(){

remove_menu_page( ‘index.php’ );                  //Dashboard
remove_menu_page( ‘edit.php’ );                   //Posts
remove_menu_page( ‘upload.php’ );                 //Media
remove_menu_page( ‘edit.php?post_type=page’ );    //Pages
remove_menu_page( ‘edit-comments.php’ );          //Comments
remove_menu_page( ‘themes.php’ );                 //Appearance
remove_menu_page( ‘plugins.php’ );                //Plugins
remove_menu_page( ‘users.php’ );                  //Users
remove_menu_page( ‘tools.php’ );                  //Tools
remove_menu_page( ‘options-general.php’ );        //Settings

}
add_action( ‘admin_menu’, ‘remove_menus’ );
?>

<?php
function revcon_change_post_label() {
global $menu;
global $submenu;
$menu[5][0] = ‘News’;
$submenu[‘edit.php’][5][0] = ‘News’;
$submenu[‘edit.php’][10][0] = ‘Add News’;
$submenu[‘edit.php’][16][0] = ‘News Tags’;
echo ”;
}
function revcon_change_post_object() {
global $wp_post_types;
$labels = &$wp_post_types[‘post’]->labels;
$labels->name = ‘News’;
$labels->singular_name = ‘News’;
$labels->add_new = ‘Add News’;
$labels->add_new_item = ‘Add News’;
$labels->edit_item = ‘Edit News’;
$labels->new_item = ‘News’;
$labels->view_item = ‘View News’;
$labels->search_items = ‘Search News’;
$labels->not_found = ‘No News found’;
$labels->not_found_in_trash = ‘No News found in Trash’;
$labels->all_items = ‘All News’;
$labels->menu_name = ‘News’;
$labels->name_admin_bar = ‘News’;
}

add_action( ‘admin_menu’, ‘revcon_change_post_label’ );
add_action( ‘init’, ‘revcon_change_post_object’ );
?>

<?php
// Add custom Slider ID field to ‘Edit Page’
// Callback function to show fields in meta box

$prefix = ‘wp_’;
$meta_box = array(
‘id’ => ‘my-meta-box’,
‘title’ => ‘Custom meta box’,
‘page’ => ‘post’,
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘fields’ => array(
array(
‘name’ => ‘Text box’,
‘desc’ => ‘Enter something here’,
‘id’ => $prefix . ‘text’,
‘type’ => ‘text’,
‘std’ => ‘Default value 1’
),
array(
‘name’ => ‘Textarea’,
‘desc’ => ‘Enter big text here’,
‘id’ => $prefix . ‘textarea’,
‘type’ => ‘textarea’,
‘std’ => ‘Default value 2’
),
array(
‘name’ => ‘Select box’,
‘id’ => $prefix . ‘select’,
‘type’ => ‘select’,
‘options’ => array(‘Option 1’, ‘Option 2’, ‘Option 3’)
),
array(
‘name’ => ‘Radio’,
‘id’ => $prefix . ‘radio’,
‘type’ => ‘radio’,
‘options’ => array(
array(‘name’ => ‘Name 1’, ‘value’ => ‘Value 1’),
array(‘name’ => ‘Name 2’, ‘value’ => ‘Value 2’)
)
),
array(
‘name’ => ‘Checkbox’,
‘id’ => $prefix . ‘checkbox’,
‘type’ => ‘checkbox’
)
)
);

add_action(‘admin_menu’, ‘mytheme_add_box’);
// Add meta box
function mytheme_add_box() {
global $meta_box;
add_meta_box($meta_box[‘id’], $meta_box[‘title’], ‘mytheme_show_box’, $meta_box[‘page’], $meta_box[‘context’], $meta_box[‘priority’]);
}

function mytheme_show_box() {
global $meta_box, $post;
// Use nonce for verification
echo ‘<input type=”hidden” name=”mytheme_meta_box_nonce” value=”‘, wp_create_nonce(basename(__FILE__)), ‘” />’;
echo ‘<table class=”form-table”>’;
foreach ($meta_box[‘fields’] as $field) {
// get current post meta data
$meta = get_post_meta($post->ID, $field[‘id’], true);
echo ‘<tr>’,
‘<th style=”width:20%”><label for=”‘, $field[‘id’], ‘”>’, $field[‘name’], ‘</label></th>’,
‘<td>’;
switch ($field[‘type’]) {
case ‘text’:
echo ‘<input type=”text” name=”‘, $field[‘id’], ‘” id=”‘, $field[‘id’], ‘” value=”‘, $meta ? $meta : $field[‘std’], ‘” size=”30″ style=”width:97%” />’, ‘<br />’, $field[‘desc’];
break;
case ‘textarea’:
echo ‘<textarea name=”‘, $field[‘id’], ‘” id=”‘, $field[‘id’], ‘” cols=”60″ rows=”4″ style=”width:97%”>’, $meta ? $meta : $field[‘std’], ‘</textarea>’, ‘<br />’, $field[‘desc’];
break;
case ‘select’:
echo ‘<select name=”‘, $field[‘id’], ‘” id=”‘, $field[‘id’], ‘”>’;
foreach ($field[‘options’] as $option) {
echo ‘<option ‘, $meta == $option ? ‘ selected=”selected”‘ : ”, ‘>’, $option, ‘</option>’;
}
echo ‘</select>’;
break;
case ‘radio’:
foreach ($field[‘options’] as $option) {
echo ‘<input type=”radio” name=”‘, $field[‘id’], ‘” value=”‘, $option[‘value’], ‘”‘, $meta == $option[‘value’] ? ‘ checked=”checked”‘ : ”, ‘ />’, $option[‘name’];
}
break;
case ‘checkbox’:
echo ‘<input type=”checkbox” name=”‘, $field[‘id’], ‘” id=”‘, $field[‘id’], ‘”‘, $meta ? ‘ checked=”checked”‘ : ”, ‘ />’;
break;
}
echo ‘</td><td>’,
‘</td></tr>’;
}
echo ‘</table>’;
}

add_action(‘save_post’, ‘mytheme_save_data’);
// Save datafrom meta box
function mytheme_save_data($post_id) {
global $meta_box;
// verify nonce
if (!wp_verify_nonce($_POST[‘mytheme_meta_box_nonce’], basename(__FILE__))) {
return $post_id;
}
// check autosave
if (defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE) {
return $post_id;
}
// check permissions
if (‘page’ == $_POST[‘post_type’]) {
if (!current_user_can(‘edit_page’, $post_id)) {
return $post_id;
}
} elseif (!current_user_can(‘edit_post’, $post_id)) {
return $post_id;
}
foreach ($meta_box[‘fields’] as $field) {
$old = get_post_meta($post_id, $field[‘id’], true);
$new = $_POST[$field[‘id’]];
if ($new && $new != $old) {
update_post_meta($post_id, $field[‘id’], $new);

} elseif (” == $new && $old) {
delete_post_meta($post_id, $field[‘id’], $old);
}
}
}

?>

<?php
add_action( ‘admin_menu’, ‘adjust_the_wp_menu’, 999 );
function adjust_the_wp_menu() {
$page = remove_submenu_page( ‘themes.php’, ‘widgets.php’ );
// $page[0] is the menu title
// $page[1] is the minimum level or capability required
// $page[2] is the URL to the item’s file
}
?>

<?php
// unregister all widgets
function unregister_default_widgets() {
unregister_widget(‘WP_Widget_Pages’);
unregister_widget(‘WP_Widget_Calendar’);
unregister_widget(‘WP_Widget_Archives’);
unregister_widget(‘WP_Widget_Links’);
unregister_widget(‘WP_Widget_Meta’);
unregister_widget(‘WP_Widget_Search’);
unregister_widget(‘WP_Widget_Text’);
unregister_widget(‘WP_Widget_Categories’);
unregister_widget(‘WP_Widget_Recent_Posts’);
unregister_widget(‘WP_Widget_Recent_Comments’);
unregister_widget(‘WP_Widget_RSS’);
unregister_widget(‘WP_Widget_Tag_Cloud’);
unregister_widget(‘WP_Nav_Menu_Widget’);
unregister_widget(‘Twenty_Eleven_Ephemera_Widget’);
}
add_action(‘widgets_init’, ‘unregister_default_widgets’, 11);
?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here