2022-03-29 20:53:36 +02:00
|
|
|
<?php
|
2022-03-30 13:20:45 +02:00
|
|
|
/**
|
|
|
|
* Custom post type Resources.
|
|
|
|
*
|
|
|
|
* @link https://arc-hive.zone
|
|
|
|
* @since 1.1.0
|
|
|
|
*
|
|
|
|
* @package archive_wpplugin
|
|
|
|
* @subpackage archive_wpplugin/includes
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom post type Resources.
|
|
|
|
*
|
|
|
|
* This class defines all code necessary to run during the plugin's activation.
|
|
|
|
*
|
|
|
|
* @since 1.1.0
|
|
|
|
* @package archive_wpplugin
|
|
|
|
* @subpackage archive_wpplugin/includes
|
|
|
|
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
|
|
|
|
*/
|
|
|
|
|
2022-03-29 20:53:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Start custom post types
|
|
|
|
* ----------------------------------------------------------------------------
|
2022-03-30 13:20:45 +02:00
|
|
|
* https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
|
|
|
|
* https://developer.wordpress.org/reference/functions/register_post_type/
|
2022-03-29 20:53:36 +02:00
|
|
|
*/
|
2022-03-30 13:20:45 +02:00
|
|
|
|
2022-03-29 20:53:36 +02:00
|
|
|
// Register Custom Post Type
|
2022-03-30 13:49:50 +02:00
|
|
|
function archive_wpplugin_init_custom_post_resource() {
|
2022-03-29 20:53:36 +02:00
|
|
|
|
2022-03-30 13:49:50 +02:00
|
|
|
$labels = array(
|
2022-03-30 16:40:19 +02:00
|
|
|
'name' => _x( 'Resources', 'Post Type General Name', 'text_domain' ),
|
2022-03-30 13:49:50 +02:00
|
|
|
'singular_name' => _x( 'Resource', 'Post Type Singular Name', 'text_domain' ),
|
|
|
|
'menu_name' => __( 'Resources', 'text_domain' ),
|
|
|
|
'parent_item_colon' => __( 'Parent resources:', 'text_domain' ),
|
|
|
|
'all_items' => __( 'All the resources', 'text_domain' ),
|
|
|
|
'view_item' => __( 'Show the resource', 'text_domain' ),
|
|
|
|
'add_new_item' => __( 'Add a new resource', 'text_domain' ),
|
2022-03-30 16:40:19 +02:00
|
|
|
'add_new' => __( 'Add new resource', 'text_domain' ),
|
2022-03-30 13:49:50 +02:00
|
|
|
'edit_item' => __( 'Edit the resource', 'text_domain' ),
|
|
|
|
'update_item' => __( 'Save the resource', 'text_domain' ),
|
|
|
|
'search_items' => __( 'Search the resource', 'text_domain' ),
|
|
|
|
'not_found' => __( 'We couldn\'t find any resource ', 'text_domain' ),
|
|
|
|
'not_found_in_trash' => __( 'We couldn\'t find any resource in the bin', 'text_domain' ),
|
|
|
|
);
|
|
|
|
$rewrite = array(
|
2022-03-30 16:40:19 +02:00
|
|
|
'slug' => 'resource',
|
2022-03-30 13:49:50 +02:00
|
|
|
);
|
2022-03-30 16:40:19 +02:00
|
|
|
// https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375
|
|
|
|
// https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
|
|
|
|
$capabilities = array(
|
|
|
|
'read' => 'read_archive_resource',
|
|
|
|
'publish_posts' => 'publish_archive_resources',
|
|
|
|
'edit_posts' => 'edit_archive_resources',
|
|
|
|
'edit_published_posts' => 'edit_archive_published_resources',
|
|
|
|
'edit_others_posts' => 'edit_other_archive_resources',
|
|
|
|
'delete_posts' => 'delete_archive_resources',
|
|
|
|
'delete_published_posts' => 'delete_archive_published_resources',
|
|
|
|
'delete_others_posts' => 'delete_archive_others_resources',
|
|
|
|
'delete_private_posts' => 'delete_archive_private_resources',
|
|
|
|
'upload_files' => 'upload_media_files',
|
|
|
|
'manage_categories' => 'manage_archive_resources_types',
|
|
|
|
);
|
2022-03-30 13:49:50 +02:00
|
|
|
$args = array(
|
|
|
|
'label' => __( 'archive_resource', 'text_domain' ),
|
|
|
|
'description' => __( 'Resources', 'text_domain' ),
|
|
|
|
'labels' => $labels,
|
|
|
|
'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
|
2022-03-30 16:40:19 +02:00
|
|
|
'taxonomies' => array('archive_resource_category','archive_resource_category'),
|
2022-03-30 13:49:50 +02:00
|
|
|
'hierarchical' => true,
|
|
|
|
'public' => true,
|
|
|
|
'show_ui' => true,
|
|
|
|
'show_in_menu' => true,
|
|
|
|
'show_in_nav_menus' => true,
|
|
|
|
'show_in_admin_bar' => true,
|
2022-03-30 16:40:19 +02:00
|
|
|
'menu_position' => 5,
|
2022-03-30 13:49:50 +02:00
|
|
|
'menu_icon' => 'dashicons-book',
|
|
|
|
'can_export' => true,
|
|
|
|
'has_archive' => 'resources',
|
|
|
|
'exclude_from_search' => false,
|
|
|
|
'publicly_queryable' => true,
|
|
|
|
'capability_type' => 'post',
|
|
|
|
'rewrite' => $rewrite,
|
2022-03-30 16:40:19 +02:00
|
|
|
'capabilities' => $capabilities,
|
|
|
|
'map_meta_cap' => true //neded to apply the new capabilities.
|
2022-03-30 13:49:50 +02:00
|
|
|
);
|
|
|
|
register_post_type( 'archive_resource', $args );
|
2022-03-29 20:53:36 +02:00
|
|
|
|
2022-03-30 13:49:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hook into the 'init' action
|
|
|
|
add_action( 'init', 'archive_wpplugin_init_custom_post_resource', 0 );
|
2022-03-29 20:53:36 +02:00
|
|
|
|
|
|
|
|
2022-03-30 16:40:19 +02:00
|
|
|
// give capabilities once the custom post id activated
|
|
|
|
function archive_wpplugin_add_caps() {
|
|
|
|
// gets the XX role
|
|
|
|
// $admins = get_role( '' );
|
|
|
|
// $admins->add_cap( );
|
|
|
|
// gets the administrator role
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
add_action( 'admin_init', 'archive_wpplugin_add_caps');
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-03-29 20:53:36 +02:00
|
|
|
/**
|
|
|
|
* Start custom taxonomies
|
|
|
|
* ----------------------------------------------------------------------------
|
2022-03-30 13:20:45 +02:00
|
|
|
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
|
2022-03-29 20:53:36 +02:00
|
|
|
*/
|
2022-03-30 13:20:45 +02:00
|
|
|
|
2022-03-30 16:40:19 +02:00
|
|
|
// Register Custom Taxonomy Category for Resources
|
|
|
|
function archive_wpplugin_register_resource_category() {
|
2022-03-29 20:53:36 +02:00
|
|
|
|
2022-03-30 13:49:50 +02:00
|
|
|
$labels = array(
|
2022-03-30 16:40:19 +02:00
|
|
|
'name' => _x( 'Resources Types', 'Taxonomy General Name', 'text_domain' ),
|
2022-03-30 13:49:50 +02:00
|
|
|
'singular_name' => _x( 'Type of resource', 'Taxonomy Singular Name', 'text_domain' ),
|
2022-03-30 16:40:19 +02:00
|
|
|
'menu_name' => __( 'Resources Types', 'text_domain' ),
|
2022-03-30 13:49:50 +02:00
|
|
|
'all_items' => __( 'All type resources', 'text_domain' ),
|
|
|
|
'parent_item' => __( 'Parent type resource', 'text_domain' ),
|
|
|
|
'parent_item_colon' => __( 'Parent type resource:', 'text_domain' ),
|
|
|
|
'new_item_name' => __( 'New type resource', 'text_domain' ),
|
|
|
|
'add_new_item' => __( 'Add New type resource', 'text_domain' ),
|
|
|
|
'edit_item' => __( 'Edit type resource', 'text_domain' ),
|
|
|
|
'update_item' => __( 'Update type of resource', 'text_domain' ),
|
|
|
|
'separate_items_with_commas' => __( 'Separate type resource with commas', 'text_domain' ),
|
|
|
|
'search_items' => __( 'Search type of resource', 'text_domain' ),
|
|
|
|
'add_or_remove_items' => __( 'Add or remove type of resource', 'text_domain' ),
|
|
|
|
'choose_from_most_used' => __( 'Choose from the most used type of resource', 'text_domain' ),
|
|
|
|
'not_found' => __( 'Type of resource Not Found', 'text_domain' ),
|
|
|
|
);
|
|
|
|
$rewrite = array(
|
2022-03-30 16:40:19 +02:00
|
|
|
'slug' => 'resource-type',
|
2022-03-30 13:49:50 +02:00
|
|
|
);
|
|
|
|
$args = array(
|
|
|
|
'labels' => $labels,
|
|
|
|
'hierarchical' => true,
|
|
|
|
'public' => true,
|
|
|
|
'show_ui' => true,
|
|
|
|
'show_admin_column' => true,
|
|
|
|
'show_in_nav_menus' => true,
|
2022-03-30 16:40:19 +02:00
|
|
|
'show_tagcloud' => false,
|
2022-03-30 13:20:45 +02:00
|
|
|
'rewrite' => $rewrite,
|
2022-03-30 13:49:50 +02:00
|
|
|
);
|
2022-03-30 16:40:19 +02:00
|
|
|
register_taxonomy( 'archive_resource_category', array( 'archive_resource' ) , $args );
|
2022-03-30 13:49:50 +02:00
|
|
|
}
|
2022-03-29 20:53:36 +02:00
|
|
|
|
2022-03-30 13:49:50 +02:00
|
|
|
// Hook into the 'init' action
|
2022-03-30 16:40:19 +02:00
|
|
|
add_action( 'init', 'archive_wpplugin_register_resource_category', 0 );
|
2022-03-29 20:53:36 +02:00
|
|
|
|
2022-03-30 16:40:19 +02:00
|
|
|
// Register Custom Taxonomy Tag for Resources
|
|
|
|
function archive_wpplugin_register_resource_tag() {
|
|
|
|
|
|
|
|
$labels = array(
|
|
|
|
'name' => _x( 'Resources Tags', 'Taxonomy General Name', 'text_domain' ),
|
|
|
|
'singular_name' => _x( 'Resource Tag', 'Taxonomy Singular Name', 'text_domain' ),
|
|
|
|
'menu_name' => __( 'Resources Tags', 'text_domain' ),
|
|
|
|
'all_items' => __( 'All resources tags', 'text_domain' ),
|
|
|
|
'parent_item' => __( 'Parent resource tag', 'text_domain' ),
|
|
|
|
'parent_item_colon' => __( 'Parent resource tag:', 'text_domain' ),
|
|
|
|
'new_item_name' => __( 'New resource tag', 'text_domain' ),
|
|
|
|
'add_new_item' => __( 'Add New resource tag', 'text_domain' ),
|
|
|
|
'edit_item' => __( 'Edit resource tag', 'text_domain' ),
|
|
|
|
'update_item' => __( 'Update resource tag', 'text_domain' ),
|
|
|
|
'separate_items_with_commas' => __( 'Separate resource tag with commas', 'text_domain' ),
|
|
|
|
'search_items' => __( 'Search resource tags', 'text_domain' ),
|
|
|
|
'add_or_remove_items' => __( 'Add or remove resource tag', 'text_domain' ),
|
|
|
|
'choose_from_most_used' => __( 'Choose from the most used resource tags', 'text_domain' ),
|
|
|
|
'not_found' => __( 'Resource tag Not Found', 'text_domain' ),
|
|
|
|
);
|
|
|
|
$rewrite = array(
|
|
|
|
'slug' => 'resource-tag',
|
|
|
|
// 'with_front' => false,
|
|
|
|
);
|
|
|
|
$args = array(
|
|
|
|
'labels' => $labels,
|
|
|
|
'hierarchical' => false,
|
|
|
|
'public' => true,
|
|
|
|
'show_ui' => true,
|
|
|
|
'show_admin_column' => true,
|
|
|
|
'show_in_nav_menus' => true,
|
|
|
|
'show_tagcloud' => true,
|
|
|
|
'rewrite' => $rewrite,
|
|
|
|
);
|
|
|
|
register_taxonomy( 'archive_resource_tag', array( 'archive_resource' ) , $args );
|
2022-03-30 13:49:50 +02:00
|
|
|
}
|
2022-03-30 16:40:19 +02:00
|
|
|
|
|
|
|
// Hook into the 'init' action
|
|
|
|
add_action( 'init', 'archive_wpplugin_register_resource_tag', 0 );
|
|
|
|
|
|
|
|
// changing the permalink
|
|
|
|
// https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post
|
|
|
|
// change in register_post_type the slug 'rewrite' to this
|
|
|
|
// $rewrite = array(
|
|
|
|
// 'slug' => 'resources/%archive_resource_category%',
|
|
|
|
// 'with_front' => true,
|
|
|
|
// 'hierarchical' => true,
|
|
|
|
// );
|
|
|
|
// uncomment below
|
|
|
|
//
|
|
|
|
// function archive_wpplugin_resource_and_category_permalink( $post_link, $id = 0 ){
|
|
|
|
// $post = get_post($id);
|
|
|
|
// if ( is_object( $post ) && $post->post_type == 'archive_resource' ){
|
|
|
|
// $terms = wp_get_object_terms( $post->ID, 'archive_resource_category' );
|
|
|
|
// if( $terms ){
|
|
|
|
// return str_replace( '%archive_resource_category%' , $terms[0]->slug , $post_link );
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// return $post_link;
|
|
|
|
// }
|
|
|
|
// add_filter( 'post_type_link', 'archive_wpplugin_resource_and_category_permalink', 1, 2 );
|