added flush in custom pot type

This commit is contained in:
jorge 2022-12-28 17:41:40 +01:00
parent b9868212cd
commit 6e62828086
1 changed files with 117 additions and 108 deletions

View File

@ -22,7 +22,7 @@
// Register Custom Post Type // Register Custom Post Type
function ofisuport_wpplugin_init_custom_post_ajut() { function ofisuport_wpplugin_custom_post_ajut_init() {
$labels = array( $labels = array(
'name' => _x( 'Ajuts', 'Post Tipu General Name', 'text_domain' ), 'name' => _x( 'Ajuts', 'Post Tipu General Name', 'text_domain' ),
@ -37,30 +37,33 @@
'update_item' => __( 'Desa ajut', 'text_domain' ), 'update_item' => __( 'Desa ajut', 'text_domain' ),
'search_items' => __( 'Cerca ajut', 'text_domain' ), 'search_items' => __( 'Cerca ajut', 'text_domain' ),
'not_ajut' => __( 'No hem pogut trovar ningún ajut ajut ', 'text_domain' ), 'not_ajut' => __( 'No hem pogut trovar ningún ajut ajut ', 'text_domain' ),
'not_ajut_in_trash' => __( 'No hem trovat cap ajut a la brosa', 'text_domain' ), 'not_ajut_in_trash' => __( 'No hem trovat cap ajut a la brosa', 'text_domain' )
); );
$rewrite = array( $rewrite = array(
'slug' => 'ajut', 'slug' => 'ajut'
); );
// https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375 // https://wordpress.stackexchange.com/questions/108338/capabilities-and-custom-post-types#108375
// https://developer.wordpress.org/reference/functions/register_post_type/#capability_type // https://developer.wordpress.org/reference/functions/register_post_type/#capability_type
$capabilities = array( //$capabilities = array(
'read' => 'read_ajut', // 'read' => 'read_ajut',
'publish_posts' => 'publish_ajut', // 'publish_posts' => 'publish_ajut',
'edit_posts' => 'edit_ajut', // 'edit_posts' => 'edit_ajut',
'edit_published_posts' => 'edit_published_ajut', // 'edit_published_posts' => 'edit_published_ajut',
'edit_others_posts' => 'edit_others_ajut', // 'edit_others_posts' => 'edit_others_ajut',
'delete_posts' => 'delete_ajut', // 'delete_posts' => 'delete_ajut',
'delete_published_posts' => 'delete_published_ajut', // 'delete_published_posts' => 'delete_published_ajut',
'delete_others_posts' => 'delete_others_ajuts', // 'delete_others_posts' => 'delete_others_ajuts',
'delete_private_posts' => 'delete_private_ajuts' // 'delete_private_posts' => 'delete_private_ajuts'
); // );
$args = array( $args = array(
'label' => __( 'ofisuport_ajut', 'text_domain' ), 'label' => __( 'ofisuport_ajut', 'text_domain' ),
'description' => __( 'Ajuts', 'text_domain' ), 'description' => __( 'Ajuts', 'text_domain' ),
'labels' => $labels, 'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ), 'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
'taxonomies' => array('ofisuport_ajut_category','ofisuport_ajut_category'), 'taxonomies' => array(
'ofisuport_ajut_category',
'ofisuport_ajut_tag'
),
'hierarchical' => true, 'hierarchical' => true,
'public' => true, 'public' => true,
'show_ui' => true, 'show_ui' => true,
@ -71,7 +74,7 @@
'menu_position' => 5, 'menu_position' => 5,
'menu_icon' => 'dashicons-book', 'menu_icon' => 'dashicons-book',
'can_export' => true, 'can_export' => true,
'has_ofisuport' => 'ajuts', 'has_archive' => 'true',
'exclude_from_search' => false, 'exclude_from_search' => false,
'publicly_queryable' => true, 'publicly_queryable' => true,
'capability_type' => 'post', 'capability_type' => 'post',
@ -80,22 +83,28 @@
'map_meta_cap' => true //neded to apply the new capabilities. 'map_meta_cap' => true //neded to apply the new capabilities.
); );
register_post_type( 'ofisuport_ajut', $args ); register_post_type( 'ofisuport_ajut', $args );
} }
// Hook into the 'init' action // Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_init_custom_post_ajut', 0 ); add_action( 'init', 'ofisuport_wpplugin_custom_post_ajut_init', 0 );
// flush rewrite and when changing theme or plugin
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
function ofisuport_ajut_rewrite_flush() {
ofisuport_wpplugin_custom_post_ajut_init();
flush_rewrite_rules();
}
add_action( 'after_switch_theme', 'ofisuport_ajut_rewrite_flush' );
// give capabilities once the custom post id activated // give capabilities once the custom post id activated
function ofisuport_wpplugin_add_caps() { // function ofisuport_wpplugin_add_caps() {
// gets the XX role // gets the XX role
// $admins = get_role( '' ); // $admins = get_role( '' );
// $admins->add_cap( ); // $admins->add_cap( );
// gets the administrator role // gets the administrator role
} //}
//add_action( 'admin_init', 'ofisuport_wpplugin_add_caps'); //add_action( 'admin_init', 'ofisuport_wpplugin_add_caps');
@ -108,101 +117,101 @@
*/ */
// Register Custom Taxonomy Category for Ajuts // Register Custom Taxonomy Category for Ajuts
function ofisuport_wpplugin_register_ajut_category() { //function ofisuport_wpplugin_ajut_category_register() {
$labels = array( // $labels = array(
'name' => _x( 'Ajuts Tipus', 'Taxonomy General Name', 'text_domain' ), // 'name' => _x( 'Ajuts Tipus', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Tipu of ajut', 'Taxonomy Singular Name', 'text_domain' ), // 'singular_name' => _x( 'Tipus d`ajut', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Ajuts Tipus', 'text_domain' ), // 'menu_name' => __( 'Ajuts Tipus', 'text_domain' ),
'all_items' => __( 'All type ajuts', 'text_domain' ), // 'all_items' => __( 'All type ajuts', 'text_domain' ),
'parent_item' => __( 'Parent type ajut', 'text_domain' ), // 'parent_item' => __( 'Parent type ajut', 'text_domain' ),
'parent_item_colon' => __( 'Parent type ajut:', 'text_domain' ), // 'parent_item_colon' => __( 'Parent type ajut:', 'text_domain' ),
'new_item_name' => __( 'New type ajut', 'text_domain' ), // 'new_item_name' => __( 'New type ajut', 'text_domain' ),
'add_new_item' => __( 'Add New type ajut', 'text_domain' ), // 'add_new_item' => __( 'Add New type ajut', 'text_domain' ),
'edit_item' => __( 'Edit type ajut', 'text_domain' ), // 'edit_item' => __( 'Edit type ajut', 'text_domain' ),
'update_item' => __( 'Update type of ajut', 'text_domain' ), // 'update_item' => __( 'Update type of ajut', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate type ajut with commas', 'text_domain' ), // 'separate_items_with_commas' => __( 'Separate type ajut with commas', 'text_domain' ),
'search_items' => __( 'Search type of ajut', 'text_domain' ), // 'search_items' => __( 'Search type of ajut', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove type of ajut', 'text_domain' ), // 'add_or_remove_items' => __( 'Add or remove type of ajut', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used type of ajut', 'text_domain' ), // 'choose_from_most_used' => __( 'Choose from the most used type of ajut', 'text_domain' ),
'not_ajut' => __( 'Tipu of ajut Not Ajut', 'text_domain' ), // 'not_ajut' => __( 'Tipus d`ajut Not Ajut', 'text_domain' )
); // );
$rewrite = array( // $rewrite = array(
'slug' => 'ajut-tipus', // 'slug' => 'ajut-tipus'
); // );
$capabilities = array( // //$capabilities = array(
'manage_terms' => 'OficinaSuport Manage ajuts Tipus', // // 'manage_terms' => 'OficinaSuport Manage ajuts Tipus',
'edit_terms' => 'OficinaSuport Edit ajut Tipus', // // 'edit_terms' => 'OficinaSuport Edit ajut Tipus',
'delete_terms' => 'OficinaSuport Delete ajuts Tipus', // // 'delete_terms' => 'OficinaSuport Delete ajuts Tipus',
'assign_terms' => 'OficinaSuport Assign ajuts Tipus', // // 'assign_terms' => 'OficinaSuport Assign ajuts Tipus',
); // // );
$args = array( // $args = array(
'labels' => $labels, // 'labels' => $labels,
'hierarchical' => true, // 'hierarchical' => true,
'public' => true, // 'public' => true,
'show_ui' => true, // 'show_ui' => true,
'show_admin_column' => true, // 'show_admin_column' => true,
'show_in_nav_menus' => true, // 'show_in_nav_menus' => true,
'show_tagcloud' => false, // 'show_tagcloud' => false,
'rewrite' => $rewrite, // 'rewrite' => $rewrite,
//'capabilities' => $capabilities, // //'capabilities' => $capabilities,
'map_meta_cap' => true //neded to apply the new capabilities. // 'map_meta_cap' => true //neded to apply the new capabilities.
); // );
register_taxonomy( 'ofisuport_ajut_category', array( 'ofisuport_ajut' ) , $args ); // register_taxonomy( 'ofisuport_ajut_category', array( 'ofisuport_ajut' ) , $args );
} //}
// Hook into the 'init' action // Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_register_ajut_category', 0 ); //add_action( 'init', 'ofisuport_wpplugin_ajut_category_register', 0 );
// Register Custom Taxonomy Tag for Ajuts // Register Custom Taxonomy Tag for Ajuts
function ofisuport_wpplugin_register_ajut_tag() { // function ofisuport_wpplugin_ajut_tag_register() {
//
$labels = array( // $labels = array(
'name' => _x( 'Ajuts Tags', 'Taxonomy General Name', 'text_domain' ), // 'name' => _x( 'Ajuts Tags', 'Taxonomy General Name', 'text_domain' ),
'singular_name' => _x( 'Ajut Tag', 'Taxonomy Singular Name', 'text_domain' ), // 'singular_name' => _x( 'Ajut Tag', 'Taxonomy Singular Name', 'text_domain' ),
'menu_name' => __( 'Ajuts Tags', 'text_domain' ), // 'menu_name' => __( 'Ajuts Tags', 'text_domain' ),
'all_items' => __( 'All ajuts tags', 'text_domain' ), // 'all_items' => __( 'All ajuts tags', 'text_domain' ),
'parent_item' => __( 'Parent ajut tag', 'text_domain' ), // 'parent_item' => __( 'Parent ajut tag', 'text_domain' ),
'parent_item_colon' => __( 'Parent ajut tag:', 'text_domain' ), // 'parent_item_colon' => __( 'Parent ajut tag:', 'text_domain' ),
'new_item_name' => __( 'New ajut tag', 'text_domain' ), // 'new_item_name' => __( 'New ajut tag', 'text_domain' ),
'add_new_item' => __( 'Add New ajut tag', 'text_domain' ), // 'add_new_item' => __( 'Add New ajut tag', 'text_domain' ),
'edit_item' => __( 'Edit ajut tag', 'text_domain' ), // 'edit_item' => __( 'Edit ajut tag', 'text_domain' ),
'update_item' => __( 'Update ajut tag', 'text_domain' ), // 'update_item' => __( 'Update ajut tag', 'text_domain' ),
'separate_items_with_commas' => __( 'Separate ajut tag with commas', 'text_domain' ), // 'separate_items_with_commas' => __( 'Separate ajut tag with commas', 'text_domain' ),
'search_items' => __( 'Search ajut tags', 'text_domain' ), // 'search_items' => __( 'Search ajut tags', 'text_domain' ),
'add_or_remove_items' => __( 'Add or remove ajut tag', 'text_domain' ), // 'add_or_remove_items' => __( 'Add or remove ajut tag', 'text_domain' ),
'choose_from_most_used' => __( 'Choose from the most used ajut tags', 'text_domain' ), // 'choose_from_most_used' => __( 'Choose from the most used ajut tags', 'text_domain' ),
'not_ajut' => __( 'Ajut tag Not Ajut', 'text_domain' ), // 'not_ajut' => __( 'Ajut tag Not Ajut', 'text_domain' ),
); // );
$rewrite = array( // $rewrite = array(
'slug' => 'ajut-tag', // 'slug' => 'ajut-tag',
// 'with_front' => false, // // 'with_front' => false,
); // );
$capabilities = array( // //$capabilities = array(
'manage_terms' => 'OficinaSuport Manage ajuts Tag', // // 'manage_terms' => 'OficinaSuport Manage ajuts Tag',
'edit_terms' => 'OficinaSuport Edit ajut Tag', // // 'edit_terms' => 'OficinaSuport Edit ajut Tag',
'delete_terms' => 'OficinaSuport Delete ajuts Tag', // // 'delete_terms' => 'OficinaSuport Delete ajuts Tag',
'assign_terms' => 'OficinaSuport Assign ajuts Tag', // // 'assign_terms' => 'OficinaSuport Assign ajuts Tag',
); // // );
//
$args = array( // $args = array(
'labels' => $labels, // 'labels' => $labels,
'hierarchical' => false, // 'hierarchical' => false,
'public' => true, // 'public' => true,
'show_ui' => true, // 'show_ui' => true,
'show_admin_column' => true, // 'show_admin_column' => true,
'show_in_nav_menus' => true, // 'show_in_nav_menus' => true,
'show_tagcloud' => true, // 'show_tagcloud' => true,
'rewrite' => $rewrite, // 'rewrite' => $rewrite,
//'capabilities' => $capabilities, // //'capabilities' => $capabilities,
'map_meta_cap' => true //neded to apply the new capabilities. // 'map_meta_cap' => true //neded to apply the new capabilities.
); // );
register_taxonomy( 'ofisuport_ajut_tag', array( 'ofisuport_ajut' ) , $args ); // register_taxonomy( 'ofisuport_ajut_tag', array( 'ofisuport_ajut' ) , $args );
} // }
// Hook into the 'init' action // Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_register_ajut_tag', 0 ); //add_action( 'init', 'ofisuport_wpplugin_ajut_tag_register', 0 );
// changing the permalink // changing the permalink
// https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post // https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post