added custom post type for `ajuts`

This commit is contained in:
jorge-vitrubio 2022-12-24 18:41:07 +01:00
parent b787cda48f
commit b9868212cd
4 changed files with 1747 additions and 6 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,227 @@
<?php
/**
* Custom post type Ajuts.
*
*
* @link https://oficinasuport.xarxaprod.cat
* @since 1.0.0
* @package ofisuport-wp-plugin
* @subpackage ofisuport-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
function ofisuport_wpplugin_init_custom_post_ajut() {
$labels = array(
'name' => _x( 'Ajuts', 'Post Tipu General Name', 'text_domain' ),
'singular_name' => _x( 'Ajut', 'Post Tipu Singular Name', 'text_domain' ),
'menu_name' => __( 'Ajuts', 'text_domain' ),
'parent_item_colon' => __( 'Ajuts mare/pare:', 'text_domain' ),
'all_items' => __( 'Tots els ajuts', 'text_domain' ),
'view_item' => __( 'Mostra el ajut', 'text_domain' ),
'add_new_item' => __( 'Affegeix un ajut', 'text_domain' ),
'add_new' => __( 'Affegeix ajut', 'text_domain' ),
'edit_item' => __( 'Edita ajut', 'text_domain' ),
'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' ),
);
$rewrite = array(
'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'
);
$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'),
'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,
'menu_position' => 5,
'menu_icon' => 'dashicons-book',
'can_export' => true,
'has_ofisuport' => 'ajuts',
'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( 'ofisuport_ajut', $args );
}
// Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_init_custom_post_ajut', 0 );
// give capabilities once the custom post id activated
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');
/**
* Start custom taxonomies
* ----------------------------------------------------------------------------
* https://developer.wordpress.org/plugins/taxonomies/working-with-custom-taxonomies/
* https://developer.wordpress.org/reference/functions/register_taxonomy/
*/
// Register Custom Taxonomy Category for Ajuts
function ofisuport_wpplugin_register_ajut_category() {
$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.
);
register_taxonomy( 'ofisuport_ajut_category', array( 'ofisuport_ajut' ) , $args );
}
// Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_register_ajut_category', 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 );
}
// Hook into the 'init' action
add_action( 'init', 'ofisuport_wpplugin_register_ajut_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' => 'ajuts/%ofisuport_ajut_category%',
// 'with_front' => true,
// 'hierarchical' => true,
// );
// uncomment below
//
// function ofisuport_wpplugin_ajut_and_category_permalink( $post_link, $id = 0 ){
// $post = get_post($id);
// if ( is_object( $post ) && $post->post_type == 'ofisuport_ajut' ){
// $terms = wp_get_object_terms( $post->ID, 'ofisuport_ajut_category' );
// if( $terms ){
// return str_replace( '%ofisuport_ajut_category%' , $terms[0]->slug , $post_link );
// }
// }
// return $post_link;
// }
// add_filter( 'post_type_link', 'ofisuport_wpplugin_ajut_and_category_permalink', 1, 2 );

View File

@ -47,6 +47,28 @@ if( ! function_exists('ofisuport_wpplugin_settings_init') ){
// 'ofisuport_wpplugin_section_control_home'
// );
// register a new section in the "ofisuport_wpplugin" page
add_settings_section(
'ofisuport_wpplugin_section_reusableblocks',
__( 'Reusable blocks.', 'ofisuport-wpplugin-textdomain' ),
'ofisuport_wpplugin_section_reusableblocks_cb',
'ofisuport_wpplugin_reusableblocks'
);
// register a new field in the "ofisuport_wpplugin_section_reusableblocks" section, inside the "ofisuport_wpplugin" page
//
// uncoment below to activate
add_settings_field(
'ofisuport_wpplugin_field_reusableblocks', // as of WP 4.6 this value is used only internally
// use $args' label_for to populate the id inside the callback
__( 'Follow this link to edit the reusable blocks <a href="' . admin_url() . 'edit.php?post_type=wp_block" class="but.ton"> Reusable blocks</a>', 'ofisuport-wpplugin-textdomain' ),
'ofisuport_wpplugin_field_reusableblocks_cb',
'ofisuport_wpplugin_settings',
'ofisuport_wpplugin_section_reusableblocks',
// edit.php?post_type=wp_block
);
// register a new section in the "ofisuport_wpplugin" page
//
// uncoment below to activate

View File

@ -9,7 +9,7 @@
* Plugin Name: Oficina de Suport wp plugin
* Plugin URI: https://git.hangar.org/xarxaprod/oficinasuport-wp-plugin
* Description: Different needs for the Oficina de Suport de Xarxaprod.cat Wordpress theme needs. Adds support for: SVG.
* Date: 2022 10 28
* Date: 2022 12 29
* Version: 1.0.0
* Author: jorge - vitrubio.net
* Author URI: https://vitrubio.net/
@ -44,17 +44,26 @@ define( 'OFISUPORT_WPPLUGIN_VERSION', '1.0.0' );
* define Plugin path
* https://developer.wordpress.org/reference/functions/plugin_dir_path/#comment-1113
* * * * * * * * * * * * * * * * * * */
define( 'OFISUPORT_WPPLUGIN_FILE', __FILE__ );
define( 'OFISUPORT_WPPLUGIN_PATH', plugin_dir_path( __FILE__ ) ); //in server
define( 'OFISUPORT_WPPLUGIN_URL', plugin_dir_url( __FILE__ ) ); //public
//define( 'OFISUPORT_WPPLUGIN_BASENAME', plugin_basename( __FILE__ ) );
include( OFISUPORT_WPPLUGIN_PATH . 'includes/plugin-init-textdomain.php');
//include( OFISUPORT_WPPLUGIN_PATH . 'includes/plugin-settings-pannel.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/enable-svg.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-admin.php');
//if ( is_admin() ) {
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-admin.php');
//} else {
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-public.php');
//}
include( OFISUPORT_WPPLUGIN_PATH . 'includes/stylesheet-public.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/plugin-settings-pannel.php');
include( OFISUPORT_WPPLUGIN_PATH . 'includes/custom-post-type-ajuts.php');