From 6e6282808628dbf7811b8e0fa57878a43bf226a9 Mon Sep 17 00:00:00 2001 From: jorge-vitrubio Date: Wed, 28 Dec 2022 17:41:40 +0100 Subject: [PATCH] added flush in custom pot type --- includes/custom-post-type-ajuts.php | 225 +++++++++++++++------------- 1 file changed, 117 insertions(+), 108 deletions(-) diff --git a/includes/custom-post-type-ajuts.php b/includes/custom-post-type-ajuts.php index 93f28a4..9b22888 100644 --- a/includes/custom-post-type-ajuts.php +++ b/includes/custom-post-type-ajuts.php @@ -22,7 +22,7 @@ // Register Custom Post Type - function ofisuport_wpplugin_init_custom_post_ajut() { + function ofisuport_wpplugin_custom_post_ajut_init() { $labels = array( 'name' => _x( 'Ajuts', 'Post Tipu General Name', 'text_domain' ), @@ -37,30 +37,33 @@ 'update_item' => __( 'Desa ajut', 'text_domain' ), 'search_items' => __( 'Cerca 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( - 'slug' => 'ajut', + 'slug' => 'ajut' ); // 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_ajut', - 'publish_posts' => 'publish_ajut', - 'edit_posts' => 'edit_ajut', - 'edit_published_posts' => 'edit_published_ajut', - 'edit_others_posts' => 'edit_others_ajut', - 'delete_posts' => 'delete_ajut', - 'delete_published_posts' => 'delete_published_ajut', - 'delete_others_posts' => 'delete_others_ajuts', - 'delete_private_posts' => 'delete_private_ajuts' - ); + //$capabilities = array( + // 'read' => 'read_ajut', + // 'publish_posts' => 'publish_ajut', + // 'edit_posts' => 'edit_ajut', + // 'edit_published_posts' => 'edit_published_ajut', + // 'edit_others_posts' => 'edit_others_ajut', + // 'delete_posts' => 'delete_ajut', + // 'delete_published_posts' => 'delete_published_ajut', + // 'delete_others_posts' => 'delete_others_ajuts', + // 'delete_private_posts' => 'delete_private_ajuts' + // ); $args = array( 'label' => __( 'ofisuport_ajut', 'text_domain' ), 'description' => __( 'Ajuts', 'text_domain' ), 'labels' => $labels, '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, 'public' => true, 'show_ui' => true, @@ -71,7 +74,7 @@ 'menu_position' => 5, 'menu_icon' => 'dashicons-book', 'can_export' => true, - 'has_ofisuport' => 'ajuts', + 'has_archive' => 'true', 'exclude_from_search' => false, 'publicly_queryable' => true, 'capability_type' => 'post', @@ -80,22 +83,28 @@ 'map_meta_cap' => true //neded to apply the new capabilities. ); register_post_type( 'ofisuport_ajut', $args ); - } - // 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 - function ofisuport_wpplugin_add_caps() { +// function ofisuport_wpplugin_add_caps() { // gets the XX role // $admins = get_role( '' ); // $admins->add_cap( ); // gets the administrator role -} +//} //add_action( 'admin_init', 'ofisuport_wpplugin_add_caps'); @@ -108,101 +117,101 @@ */ // Register Custom Taxonomy Category for Ajuts - function ofisuport_wpplugin_register_ajut_category() { + //function ofisuport_wpplugin_ajut_category_register() { - $labels = array( - 'name' => _x( 'Ajuts Tipus', 'Taxonomy General Name', 'text_domain' ), - 'singular_name' => _x( 'Tipu of ajut', 'Taxonomy Singular Name', 'text_domain' ), - 'menu_name' => __( 'Ajuts Tipus', 'text_domain' ), - 'all_items' => __( 'All type ajuts', 'text_domain' ), - 'parent_item' => __( 'Parent type ajut', 'text_domain' ), - 'parent_item_colon' => __( 'Parent type ajut:', 'text_domain' ), - 'new_item_name' => __( 'New type ajut', 'text_domain' ), - 'add_new_item' => __( 'Add New type ajut', 'text_domain' ), - 'edit_item' => __( 'Edit type ajut', 'text_domain' ), - 'update_item' => __( 'Update type of ajut', 'text_domain' ), - 'separate_items_with_commas' => __( 'Separate type ajut with commas', 'text_domain' ), - 'search_items' => __( 'Search 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' ), - 'not_ajut' => __( 'Tipu of ajut Not Ajut', 'text_domain' ), - ); - $rewrite = array( - 'slug' => 'ajut-tipus', - ); - $capabilities = array( - 'manage_terms' => 'OficinaSuport Manage ajuts Tipus', - 'edit_terms' => 'OficinaSuport Edit ajut Tipus', - 'delete_terms' => 'OficinaSuport Delete ajuts Tipus', - 'assign_terms' => 'OficinaSuport Assign ajuts Tipus', - ); - $args = array( - 'labels' => $labels, - 'hierarchical' => true, - 'public' => true, - 'show_ui' => true, - 'show_admin_column' => true, - 'show_in_nav_menus' => true, - 'show_tagcloud' => false, - 'rewrite' => $rewrite, - //'capabilities' => $capabilities, - 'map_meta_cap' => true //neded to apply the new capabilities. + // $labels = array( + // 'name' => _x( 'Ajuts Tipus', 'Taxonomy General Name', 'text_domain' ), + // 'singular_name' => _x( 'Tipus d`ajut', 'Taxonomy Singular Name', 'text_domain' ), + // 'menu_name' => __( 'Ajuts Tipus', 'text_domain' ), + // 'all_items' => __( 'All type ajuts', 'text_domain' ), + // 'parent_item' => __( 'Parent type ajut', 'text_domain' ), + // 'parent_item_colon' => __( 'Parent type ajut:', 'text_domain' ), + // 'new_item_name' => __( 'New type ajut', 'text_domain' ), + // 'add_new_item' => __( 'Add New type ajut', 'text_domain' ), + // 'edit_item' => __( 'Edit type ajut', 'text_domain' ), + // 'update_item' => __( 'Update type of ajut', 'text_domain' ), + // 'separate_items_with_commas' => __( 'Separate type ajut with commas', 'text_domain' ), + // 'search_items' => __( 'Search 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' ), + // 'not_ajut' => __( 'Tipus d`ajut Not Ajut', 'text_domain' ) + // ); + // $rewrite = array( + // 'slug' => 'ajut-tipus' + // ); + // //$capabilities = array( + // // 'manage_terms' => 'OficinaSuport Manage ajuts Tipus', + // // 'edit_terms' => 'OficinaSuport Edit ajut Tipus', + // // 'delete_terms' => 'OficinaSuport Delete ajuts Tipus', + // // 'assign_terms' => 'OficinaSuport Assign ajuts Tipus', + // // ); + // $args = array( + // 'labels' => $labels, + // 'hierarchical' => true, + // 'public' => true, + // 'show_ui' => true, + // 'show_admin_column' => true, + // 'show_in_nav_menus' => true, + // 'show_tagcloud' => false, + // 'rewrite' => $rewrite, + // //'capabilities' => $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 - add_action( 'init', 'ofisuport_wpplugin_register_ajut_category', 0 ); + //add_action( 'init', 'ofisuport_wpplugin_ajut_category_register', 0 ); // Register Custom Taxonomy Tag for Ajuts - function ofisuport_wpplugin_register_ajut_tag() { - - $labels = array( - 'name' => _x( 'Ajuts Tags', 'Taxonomy General Name', 'text_domain' ), - 'singular_name' => _x( 'Ajut Tag', 'Taxonomy Singular Name', 'text_domain' ), - 'menu_name' => __( 'Ajuts Tags', 'text_domain' ), - 'all_items' => __( 'All ajuts tags', 'text_domain' ), - 'parent_item' => __( 'Parent ajut tag', 'text_domain' ), - 'parent_item_colon' => __( 'Parent ajut tag:', 'text_domain' ), - 'new_item_name' => __( 'New ajut tag', 'text_domain' ), - 'add_new_item' => __( 'Add New ajut tag', 'text_domain' ), - 'edit_item' => __( 'Edit ajut tag', 'text_domain' ), - 'update_item' => __( 'Update ajut tag', 'text_domain' ), - 'separate_items_with_commas' => __( 'Separate ajut tag with commas', 'text_domain' ), - 'search_items' => __( 'Search ajut tags', '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' ), - 'not_ajut' => __( 'Ajut tag Not Ajut', 'text_domain' ), - ); - $rewrite = array( - 'slug' => 'ajut-tag', - // 'with_front' => false, - ); - $capabilities = array( - 'manage_terms' => 'OficinaSuport Manage ajuts Tag', - 'edit_terms' => 'OficinaSuport Edit ajut Tag', - 'delete_terms' => 'OficinaSuport Delete ajuts Tag', - 'assign_terms' => 'OficinaSuport Assign ajuts Tag', - ); - - $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, - //'capabilities' => $capabilities, - 'map_meta_cap' => true //neded to apply the new capabilities. - ); - register_taxonomy( 'ofisuport_ajut_tag', array( 'ofisuport_ajut' ) , $args ); - } +// function ofisuport_wpplugin_ajut_tag_register() { +// +// $labels = array( +// 'name' => _x( 'Ajuts Tags', 'Taxonomy General Name', 'text_domain' ), +// 'singular_name' => _x( 'Ajut Tag', 'Taxonomy Singular Name', 'text_domain' ), +// 'menu_name' => __( 'Ajuts Tags', 'text_domain' ), +// 'all_items' => __( 'All ajuts tags', 'text_domain' ), +// 'parent_item' => __( 'Parent ajut tag', 'text_domain' ), +// 'parent_item_colon' => __( 'Parent ajut tag:', 'text_domain' ), +// 'new_item_name' => __( 'New ajut tag', 'text_domain' ), +// 'add_new_item' => __( 'Add New ajut tag', 'text_domain' ), +// 'edit_item' => __( 'Edit ajut tag', 'text_domain' ), +// 'update_item' => __( 'Update ajut tag', 'text_domain' ), +// 'separate_items_with_commas' => __( 'Separate ajut tag with commas', 'text_domain' ), +// 'search_items' => __( 'Search ajut tags', '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' ), +// 'not_ajut' => __( 'Ajut tag Not Ajut', 'text_domain' ), +// ); +// $rewrite = array( +// 'slug' => 'ajut-tag', +// // 'with_front' => false, +// ); +// //$capabilities = array( +// // 'manage_terms' => 'OficinaSuport Manage ajuts Tag', +// // 'edit_terms' => 'OficinaSuport Edit ajut Tag', +// // 'delete_terms' => 'OficinaSuport Delete ajuts Tag', +// // 'assign_terms' => 'OficinaSuport Assign ajuts Tag', +// // ); +// +// $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, +// //'capabilities' => $capabilities, +// 'map_meta_cap' => true //neded to apply the new capabilities. +// ); +// register_taxonomy( 'ofisuport_ajut_tag', array( 'ofisuport_ajut' ) , $args ); +// } // 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 // https://wordpress.stackexchange.com/questions/108642/permalinks-custom-post-type-custom-taxonomy-post