This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_filter('acf/settings/remove_wp_meta_box', '__return_false'); | |
| // Post Type Subpages: Settings | |
| function hwk_ptsp_settings(){ | |
| $settings = array( | |
| array( | |
| // Le Post Type cible. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * Dynamic Post Type Subpages | |
| * Exemple Simple | |
| */ | |
| add_filter('hwk/post_types/subpages', 'hwk_post_type_film_subpages_simple'); | |
| function hwk_post_type_film_subpages_simple($settings){ | |
| $settings[] = array( | |
| 'post_type' => 'film', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Settings | |
| function hwk_ptsp_settings(){ | |
| return apply_filters('hwk/post_types/subpages', array()); | |
| } | |
| // Post Type Subpages: Récupération des Post Types | |
| function hwk_ptsp_get_post_types(){ | |
| if(!$settings = hwk_ptsp_settings()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Création des Règles de Rewrite Rules | |
| add_action('generate_rewrite_rules', 'hwk_ptsp_rewrite_rules'); | |
| function hwk_ptsp_rewrite_rules($wp_rewrite){ | |
| if(!$post_types = hwk_ptsp_get_post_types()) | |
| return; | |
| $wp_rules = $wp_rewrite->rules; | |
| $new_rules = array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Ajout des Query Vars | |
| add_filter('query_vars', 'hwk_ptsp_query_vars'); | |
| function hwk_ptsp_query_vars($vars){ | |
| if(!$post_types = hwk_ptsp_get_post_types()) | |
| return $vars; | |
| foreach($post_types as $post_type){ | |
| foreach($post_type['pages'] as $page){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Création des redirections | |
| add_action('template_redirect', 'hwk_ptsp_redirect'); | |
| function hwk_ptsp_redirect(){ | |
| if( !($post_id = get_the_ID()) || !($post_types = hwk_ptsp_get_post_types()) ) | |
| return; | |
| foreach($post_types as $post_type){ | |
| if(!is_singular($post_type['post_type'])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Templates | |
| add_filter('template_include', 'hwk_ptsp_template'); | |
| function hwk_ptsp_template($template){ | |
| if( !($post_id = get_the_ID()) || !($post_types = hwk_ptsp_get_post_types()) ) | |
| return $template; | |
| foreach($post_types as $post_type){ | |
| if(!is_singular($post_type['post_type'])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Saubegarde d'un post | |
| add_action('save_post', 'hwk_ptsp_save_post', 10, 2); | |
| function hwk_ptsp_save_post($post_id, $post){ | |
| if(!$post_type = hwk_ptsp_get_post_type($post->post_type)) | |
| return; | |
| // Aucun Meta Parent: Création du meta par défaut | |
| if(!get_post_meta($post_id, $post_type['meta_prefix'] . 'parent', true)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Post Type Subpages: Hook get_permalink() | |
| add_filter('post_link', 'hwk_ptsp_get_permalink', 10, 3); | |
| add_filter('post_type_link', 'hwk_ptsp_get_permalink', 10, 3); | |
| function hwk_ptsp_get_permalink($permalink, $post){ | |
| if(!$post_types = hwk_ptsp_get_post_types()) | |
| return $permalink; | |
| foreach($post_types as $post_type){ |