Skip to content

Instantly share code, notes, and snippets.

<?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.
<?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',
<?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())
<?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();
<?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){
<?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']))
<?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']))
<?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))
<?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){