xarxaprod-wp-plugin/includes/custom-post-type-convos.php

242 lines
11 KiB
PHP
Raw Normal View History

2024-01-18 12:15:33 +01:00
<?php
/**
2024-01-27 18:31:59 +01:00
* Custom post type Convos.
2024-01-18 12:15:33 +01:00
*
*
* @link https://xarxaprod.cat
* @since 1.0.0
* @package xarxaprod-wp-plugin
* @subpackage xarxaprod-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*
* @internal never define functions inside callbacks.
* these functions could be run multiple times; this would result in a fatal error.
*/
/**
* Start custom post types
* ----------------------------------------------------------------------------
* https://developer.wordpress.org/plugins/post-types/registering-custom-post-types/
* https://developer.wordpress.org/reference/functions/register_post_type/
*/
// Register Custom Post Type
2024-01-27 18:31:59 +01:00
if ( ! function_exists('xarxaprod_wpplugin_custom_post_convo_init') ){
function xarxaprod_wpplugin_custom_post_convo_init() {
2024-01-18 12:15:33 +01:00
$labels = array(
2024-01-27 18:31:59 +01:00
'name' => _x( 'Convos', 'Post Tipu General Name', 'text_domain' ),
'singular_name' => _x( 'Convo', 'Post Tipu Singular Name', 'text_domain' ),
'menu_name' => __( 'Convos', 'text_domain' ),
'parent_item_colon' => __( 'Convos mare/pare:', 'text_domain' ),
'all_items' => __( 'Totas las convos', 'text_domain' ),
'view_item' => __( 'Mostra la convo', 'text_domain' ),
'add_new_item' => __( 'Affegeix un convo', 'text_domain' ),
'add_new' => __( 'Affegeix convo', 'text_domain' ),
'edit_item' => __( 'Edita convo', 'text_domain' ),
'update_item' => __( 'Desa convo', 'text_domain' ),
'search_items' => __( 'Cerca convo', 'text_domain' ),
'not_convo' => __( 'No hem pogut trovar ningúna convo', 'text_domain' ),
'not_convo_in_trash' => __( 'No hem trovat cap convo a la brosa', 'text_domain' )
2024-01-18 12:15:33 +01:00
);
$rewrite = array(
2024-01-27 18:31:59 +01:00
'slug' => 'convos'
2024-01-18 12:15:33 +01: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(
2024-01-27 18:31:59 +01:00
// 'read' => 'read_convo',
// 'publish_posts' => 'publish_convo',
// 'edit_posts' => 'edit_convo',
// 'edit_published_posts' => 'edit_published_convo',
// 'edit_others_posts' => 'edit_others_convo',
// 'delete_posts' => 'delete_convo',
// 'delete_published_posts' => 'delete_published_convo',
// 'delete_others_posts' => 'delete_others_convos',
// 'delete_private_posts' => 'delete_private_convos'
2024-01-18 12:15:33 +01:00
// );
$args = array(
'label' => __( 'xarxaprod-convo', 'text_domain' ),
2024-01-27 18:31:59 +01:00
'description' => __( 'Convos', 'text_domain' ),
2024-01-18 12:15:33 +01:00
'labels' => $labels,
//'supports' => array( 'title', 'editor', 'thumbnail', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
'supports' => array( 'title', 'editor', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes' ),
// 'taxonomies' => array(
// 'xarxaprod-convo-category',
// 'xarxaprod-convo-tag'
// ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'show_in_rest' => true,
2024-01-27 18:31:59 +01:00
'menu_position' => 5,
'menu_icon' => 'dashicons-calendar',
2024-01-18 12:15:33 +01:00
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'rewrite' => $rewrite,
//'capabilities' => $capabilities,
//'map_meta_cap' => true //neded to apply the new capabilities.
);
register_post_type( 'xarxaprod-convo', $args );
2024-01-27 18:31:59 +01:00
}
}// end function_exists xarxaprod_wpplugin_custom_post_convo_init
2024-01-18 12:15:33 +01:00
// Hook into the 'init' action
2024-01-27 18:31:59 +01:00
add_action( 'init', 'xarxaprod_wpplugin_custom_post_convo_init', 0 );
2024-01-18 12:15:33 +01:00
// flush rewrite and when changing theme or plugin
2024-01-27 18:31:59 +01:00
// https://developer.wordpress.org/reference/functions/register_post_type/#flushing-rewrite-on-activation
if ( ! function_exists( 'xarxaprod_convo_rewrite_flush') ){
function xarxaprod_convo_rewrite_flush() {
xarxaprod_wpplugin_custom_post_convo_init();
2024-01-18 12:15:33 +01:00
flush_rewrite_rules();
}
2024-01-27 18:31:59 +01:00
}// end function_exists xarxaprod_convo_rewrite_flush
add_action( 'after_switch_theme', 'xarxaprod_convo_rewrite_flush' );
2024-01-18 12:15:33 +01:00
// give capabilities once the custom post id activated
// function xarxaprod_wpplugin_add_caps() {
// gets the XX role
// $admins = get_role( '' );
// $admins->add_cap( );
// gets the administrator role
//}
//add_action( 'admin_init', 'xarxaprod_wpplugin_add_caps');
/**
* Start custom taxonomies
* ----------------------------------------------------------------------------
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
* https://developer.wordpress.org/reference/functions/register_taxonomy/
*/
2024-01-27 18:31:59 +01:00
// Register Custom Taxonomy Category for Convos
//function xarxaprod_wpplugin_convo_category_register() {
2024-01-18 12:15:33 +01:00
// $labels = array(
2024-01-27 18:31:59 +01:00
// 'name' => _x( 'Convos Tipus', 'Taxonomy General Name', 'text_domain' ),
// 'singular_name' => _x( 'Tipus d`convo', 'Taxonomy Singular Name', 'text_domain' ),
// 'menu_name' => __( 'Convos Tipus', 'text_domain' ),
// 'all_items' => __( 'All type convos', 'text_domain' ),
// 'parent_item' => __( 'Parent type convo', 'text_domain' ),
// 'parent_item_colon' => __( 'Parent type convo:', 'text_domain' ),
// 'new_item_name' => __( 'New type convo', 'text_domain' ),
// 'add_new_item' => __( 'Add New type convo', 'text_domain' ),
// 'edit_item' => __( 'Edit type convo', 'text_domain' ),
// 'update_item' => __( 'Update type of convo', 'text_domain' ),
// 'separate_items_with_commas' => __( 'Separate type convo with commas', 'text_domain' ),
// 'search_items' => __( 'Search type of convo', 'text_domain' ),
// 'add_or_remove_items' => __( 'Add or remove type of convo', 'text_domain' ),
// 'choose_from_most_used' => __( 'Choose from the most used type of convo', 'text_domain' ),
// 'not_convo' => __( 'Tipus d`convo Not Convo', 'text_domain' )
2024-01-18 12:15:33 +01:00
// );
// $rewrite = array(
2024-01-27 18:31:59 +01:00
// 'slug' => 'convo-tipus'
2024-01-18 12:15:33 +01:00
// );
// //$capabilities = array(
2024-01-27 18:31:59 +01:00
// // 'manage_terms' => 'Xarxaprod Manage convos Tipus',
// // 'edit_terms' => 'Xarxaprod Edit convo Tipus',
// // 'delete_terms' => 'Xarxaprod Delete convos Tipus',
// // 'assign_terms' => 'Xarxaprod Assign convos Tipus',
2024-01-18 12:15:33 +01:00
// // );
// $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( 'xarxaprod-convo-category', array( 'xarxaprod-convo' ) , $args );
//}
// Hook into the 'init' action
2024-01-27 18:31:59 +01:00
//add_action( 'init', 'xarxaprod_wpplugin_convo_category_register', 0 );
2024-01-18 12:15:33 +01:00
2024-01-27 18:31:59 +01:00
// Register Custom Taxonomy Tag for Convos
// function xarxaprod_wpplugin_convo_tag_register() {
2024-01-18 12:15:33 +01:00
//
// $labels = array(
2024-01-27 18:31:59 +01:00
// 'name' => _x( 'Convos Tags', 'Taxonomy General Name', 'text_domain' ),
// 'singular_name' => _x( 'Convo Tag', 'Taxonomy Singular Name', 'text_domain' ),
// 'menu_name' => __( 'Convos Tags', 'text_domain' ),
// 'all_items' => __( 'All convos tags', 'text_domain' ),
// 'parent_item' => __( 'Parent convo tag', 'text_domain' ),
// 'parent_item_colon' => __( 'Parent convo tag:', 'text_domain' ),
// 'new_item_name' => __( 'New convo tag', 'text_domain' ),
// 'add_new_item' => __( 'Add New convo tag', 'text_domain' ),
// 'edit_item' => __( 'Edit convo tag', 'text_domain' ),
// 'update_item' => __( 'Update convo tag', 'text_domain' ),
// 'separate_items_with_commas' => __( 'Separate convo tag with commas', 'text_domain' ),
// 'search_items' => __( 'Search convo tags', 'text_domain' ),
// 'add_or_remove_items' => __( 'Add or remove convo tag', 'text_domain' ),
// 'choose_from_most_used' => __( 'Choose from the most used convo tags', 'text_domain' ),
// 'not_convo' => __( 'Convo tag Not Convo', 'text_domain' ),
2024-01-18 12:15:33 +01:00
// );
// $rewrite = array(
2024-01-27 18:31:59 +01:00
// 'slug' => 'convo-tag',
2024-01-18 12:15:33 +01:00
// // 'with_front' => false,
// );
// //$capabilities = array(
2024-01-27 18:31:59 +01:00
// // 'manage_terms' => 'Xarxaprod Manage convos Tag',
// // 'edit_terms' => 'Xarxaprod Edit convo Tag',
// // 'delete_terms' => 'Xarxaprod Delete convos Tag',
// // 'assign_terms' => 'Xarxaprod Assign convos Tag',
2024-01-18 12:15:33 +01:00
// // );
//
// $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( 'xarxaprod-convo-tag', array( 'xarxaprod-convo' ) , $args );
// }
// Hook into the 'init' action
2024-01-27 18:31:59 +01:00
//add_action( 'init', 'xarxaprod_wpplugin_convo_tag_register', 0 );
2024-01-18 12:15:33 +01:00
// 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(
2024-01-27 18:31:59 +01:00
// 'slug' => 'convos/%xarxaprod-convo-category%',
2024-01-18 12:15:33 +01:00
// 'with_front' => true,
// 'hierarchical' => true,
// );
// uncomment below
//
2024-01-27 18:31:59 +01:00
// function xarxaprod_wpplugin_convo_and_category_permalink( $post_link, $id = 0 ){
2024-01-18 12:15:33 +01:00
// $post = get_post($id);
// if ( is_object( $post ) && $post->post_type == 'xarxaprod-convo' ){
// $terms = wp_get_object_terms( $post->ID, 'xarxaprod-convo-category' );
// if( $terms ){
// return str_replace( '%xarxaprod-convo-category%' , $terms[0]->slug , $post_link );
// }
// }
// return $post_link;
// }
2024-01-27 18:31:59 +01:00
// add_filter( 'post_type_link', 'xarxaprod_wpplugin_convo_and_category_permalink', 1, 2 );