PluginProbe
Virtue/Ascend/Pinnacle Toolkit / 4.9.12.2
Virtue/Ascend/Pinnacle Toolkit v4.9.12.2
4.9.12.2 trunk 1.3 1.4 1.5 1.6 1.7 1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3.0 3.1 3.2 3.3 3.4 3.7 All 48 releases
← All changes | post-types.php +145 -121 3.1 → 4.9.12.2 View file →
@@ -1,131 +1,155 @@
1 1 <?php
2 -// Custom post types
3 -function kad_portfolio_post_init() {
4 - $portfoliolabels = array(
5 - 'name' => __('Portfolio', 'kadencetoolkit'),
6 - 'singular_name' => __('Portfolio Item', 'kadencetoolkit'),
7 - 'add_new' => __('Add New', 'kadencetoolkit'),
8 - 'add_new_item' => __('Add New Portfolio Item', 'kadencetoolkit'),
9 - 'edit_item' => __('Edit Portfolio Item', 'kadencetoolkit'),
10 - 'new_item' => __('New Portfolio Item', 'kadencetoolkit'),
11 - 'all_items' => __('All Portfolio', 'kadencetoolkit'),
12 - 'view_item' => __('View Portfolio Item', 'kadencetoolkit'),
13 - 'search_items' => __('Search Portfolio', 'kadencetoolkit'),
14 - 'not_found' => __('No Portfolio Item found', 'kadencetoolkit'),
15 - 'not_found_in_trash' => __('No Portfolio Items found in Trash', 'kadencetoolkit'),
16 - 'parent_item_colon' => '',
17 - 'menu_name' => __('Portfolio', 'kadencetoolkit')
18 - );
2 +/**
3 + * Init Custom post types
4 + *
5 + * @package Kadence Toolkit
6 + */
19 7
20 - $portargs = array(
21 - 'labels' => $portfoliolabels,
22 - 'public' => true,
23 - 'publicly_queryable' => true,
24 - 'show_ui' => true,
25 - 'show_in_menu' => true,
26 - 'query_var' => true,
27 - //'rewrite' => array( 'slug' => 'portfolio', 'feeds' => true),
28 - 'has_archive' => false,
29 - 'capability_type' => 'post',
30 - 'hierarchical' => false,
31 - 'menu_position' => 8,
32 - 'menu_icon' => 'dashicons-format-gallery',
33 - 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'page-attributes', 'thumbnail', 'custom-fields', 'comments' )
34 - );
35 - // Initialize Taxonomy Labels
8 +/**
9 + * Init Portfolio posts type.
10 + */
11 +function kadence_toolkit_portfolio_post_init() {
12 + $portfoliolabels = array(
13 + 'name' => __( 'Portfolio', 'virtue-toolkit' ),
14 + 'singular_name' => __( 'Portfolio Item', 'virtue-toolkit' ),
15 + 'add_new' => __( 'Add New', 'virtue-toolkit' ),
16 + 'add_new_item' => __( 'Add New Portfolio Item', 'virtue-toolkit' ),
17 + 'edit_item' => __( 'Edit Portfolio Item', 'virtue-toolkit' ),
18 + 'new_item' => __( 'New Portfolio Item', 'virtue-toolkit' ),
19 + 'all_items' => __( 'All Portfolio', 'virtue-toolkit' ),
20 + 'view_item' => __( 'View Portfolio Item', 'virtue-toolkit' ),
21 + 'search_items' => __( 'Search Portfolio', 'virtue-toolkit' ),
22 + 'not_found' => __( 'No Portfolio Item found', 'virtue-toolkit' ),
23 + 'not_found_in_trash' => __( 'No Portfolio Items found in Trash', 'virtue-toolkit' ),
24 + 'parent_item_colon' => '',
25 + 'menu_name' => __( 'Portfolio', 'virtue-toolkit' ),
26 + );
27 +
28 + $portargs = array(
29 + 'labels' => $portfoliolabels,
30 + 'public' => true,
31 + 'publicly_queryable' => true,
32 + 'show_ui' => true,
33 + 'show_in_menu' => true,
34 + 'query_var' => true,
35 + // 'rewrite' => array( 'slug' => 'portfolio', 'feeds' => true),.
36 + 'has_archive' => false,
37 + 'capability_type' => 'post',
38 + 'hierarchical' => false,
39 + 'menu_position' => 8,
40 + 'show_in_rest' => true,
41 + 'menu_icon' => 'dashicons-format-gallery',
42 + 'supports' => array( 'title', 'editor', 'excerpt', 'author', 'page-attributes', 'thumbnail', 'custom-fields', 'comments' ),
43 + );
44 +
45 + // Initialize Taxonomy Labels.
36 46 $worklabels = array(
37 - 'name' => __( 'Portfolio Type', 'kadencetoolkit' ),
38 - 'singular_name' => __( 'Type', 'kadencetoolkit' ),
39 - 'search_items' => __( 'Search Type', 'kadencetoolkit' ),
40 - 'all_items' => __( 'All Type', 'kadencetoolkit' ),
41 - 'parent_item' => __( 'Parent Type', 'kadencetoolkit' ),
42 - 'parent_item_colon' => __( 'Parent Type:', 'kadencetoolkit' ),
43 - 'edit_item' => __( 'Edit Type', 'kadencetoolkit' ),
44 - 'update_item' => __( 'Update Type', 'kadencetoolkit' ),
45 - 'add_new_item' => __( 'Add New Type', 'kadencetoolkit' ),
46 - 'new_item_name' => __( 'New Type Name', 'kadencetoolkit' ),
47 + 'name' => __( 'Portfolio Type', 'virtue-toolkit' ),
48 + 'singular_name' => __( 'Type', 'virtue-toolkit' ),
49 + 'search_items' => __( 'Search Type', 'virtue-toolkit' ),
50 + 'all_items' => __( 'All Type', 'virtue-toolkit' ),
51 + 'parent_item' => __( 'Parent Type', 'virtue-toolkit' ),
52 + 'parent_item_colon' => __( 'Parent Type:', 'virtue-toolkit' ),
53 + 'edit_item' => __( 'Edit Type', 'virtue-toolkit' ),
54 + 'update_item' => __( 'Update Type', 'virtue-toolkit' ),
55 + 'add_new_item' => __( 'Add New Type', 'virtue-toolkit' ),
56 + 'new_item_name' => __( 'New Type Name', 'virtue-toolkit' ),
47 57 );
48 - // Register Custom Taxonomy
49 - register_taxonomy('portfolio-type',array('portfolio'), array(
50 - 'hierarchical' => true, // define whether to use a system like tags or categories
51 - 'labels' => $worklabels,
52 - 'show_ui' => true,
53 - 'query_var' => true,
54 - 'rewrite' => true,
55 - ));
56 58
57 - register_post_type( 'portfolio', $portargs );
59 + // Allow slug to be filterd.
60 + $portfolio_type_slug = apply_filters( 'kadence_portfolio_type_slug', 'portfolio-type' );
61 +
62 + // Register Custom Taxonomy.
63 + register_taxonomy( 'portfolio-type', array( 'portfolio' ), array(
64 + 'hierarchical' => true, // define whether to use a system like tags or categories.
65 + 'labels' => $worklabels,
66 + 'show_ui' => true,
67 + 'query_var' => true,
68 + 'show_in_rest' => true,
69 + 'rewrite' => array( 'slug' => $portfolio_type_slug ),
70 + ) );
71 +
72 + register_post_type( 'portfolio', $portargs );
58 73 }
59 -add_action( 'init', 'kad_portfolio_post_init', 1 );
60 -function kad_portfolio_permalink_init(){
61 -global $wp_rewrite;
62 -$port_rewrite = apply_filters('kadence_portfolio_permalink_slug', 'portfolio');
63 -$portfolio_structure = '/'.$port_rewrite.'/%portfolio%';
64 -$wp_rewrite->add_rewrite_tag("%portfolio%", '([^/]+)', "portfolio=");
65 -$wp_rewrite->add_permastruct('portfolio', $portfolio_structure, false);
74 +add_action( 'init', 'kadence_toolkit_portfolio_post_init', 1 );
75 +
76 +/**
77 + * Init Portfolio slug rewrite
78 + */
79 +function kadence_toolkit_portfolio_permalink_init() {
80 + global $wp_rewrite;
81 + $port_rewrite = apply_filters( 'kadence_portfolio_permalink_slug', 'portfolio' );
82 + $portfolio_structure = '/' . $port_rewrite . '/%portfolio%';
83 +
84 + $wp_rewrite->add_rewrite_tag( '%portfolio%', '([^/]+)', 'portfolio=' );
85 + $wp_rewrite->add_permastruct( 'portfolio', $portfolio_structure, false );
66 86 }
67 -add_action( 'init', 'kad_portfolio_permalink_init', 2 );
87 +add_action( 'init', 'kadence_toolkit_portfolio_permalink_init', 2 );
68 88
69 -// Add filter to plugin init function
70 -add_filter('post_type_link', 'kad_portfolio_permalink', 10, 3);
89 +/**
90 + * Run Portfolio slug rewrite
91 + *
92 + * @param string $permalink incoming permalink setting.
93 + * @param int $post_id incoming post ID.
94 + * @param string $leavename incoming name.
95 + */
96 +function kadence_toolkit_portfolio_permalink( $permalink, $post_id, $leavename ) {
97 + $post = get_post( $post_id );
98 + $rewritecode = array(
99 + '%year%',
100 + '%monthnum%',
101 + '%day%',
102 + '%hour%',
103 + '%minute%',
104 + '%second%',
105 + $leavename ? '' : '%postname%',
106 + '%post_id%',
107 + '%category%',
108 + '%author%',
109 + $leavename ? '' : '%pagename%',
110 + );
71 111
72 -function kad_portfolio_permalink($permalink, $post_id, $leavename) {
73 - $post = get_post($post_id);
74 - $rewritecode = array(
75 - '%year%',
76 - '%monthnum%',
77 - '%day%',
78 - '%hour%',
79 - '%minute%',
80 - '%second%',
81 - $leavename? '' : '%postname%',
82 - '%post_id%',
83 - '%category%',
84 - '%author%',
85 - $leavename? '' : '%pagename%',
86 - );
87 -
88 - if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
89 - $unixtime = strtotime($post->post_date);
90 -
91 - $category = '';
92 - if ( strpos($permalink, '%category%') !== false ) {
93 - $cats = wp_get_post_terms($post->ID, 'portfolio-type', array( 'orderby' => 'parent', 'order' => 'DESC' ));
94 - if ( $cats ) {
95 - //usort($cats, '_usort_terms_by_ID'); // order by ID
96 - $category = $cats[0]->slug;
97 - }
98 - // show default category in permalinks, without
99 - // having to assign it explicitly
100 - if ( empty($category) ) {
101 - $category = 'portfolio-category';
102 - }
103 - }
104 -
105 - $author = '';
106 - if ( strpos($permalink, '%author%') !== false ) {
107 - $authordata = get_userdata($post->post_author);
108 - $author = $authordata->user_nicename;
109 - }
110 -
111 - $date = explode(" ",date('Y m d H i s', $unixtime));
112 - $rewritereplace =
113 - array(
114 - $date[0],
115 - $date[1],
116 - $date[2],
117 - $date[3],
118 - $date[4],
119 - $date[5],
120 - $post->post_name,
121 - $post->ID,
122 - $category,
123 - $author,
124 - $post->post_name,
125 - );
126 - $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
127 - } else { // if they're not using the fancy permalink option
128 - }
129 - return $permalink;
112 + if ( ! empty( $permalink ) && ! in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
113 + $unixtime = strtotime( $post->post_date );
114 + $category = '';
115 + $author = '';
116 + if ( strpos( $permalink, '%category%' ) !== false ) {
117 + $cats = wp_get_post_terms( $post->ID, 'portfolio-type', array(
118 + 'orderby' => 'parent',
119 + 'order' => 'DESC',
120 + ) );
121 + if ( $cats ) {
122 + // usort($cats, '_usort_terms_by_ID'); // order by ID.
123 + $category = $cats[0]->slug;
124 + }
125 + // show default category in permalinks, without.
126 + // having to assign it explicitly.
127 + if ( empty( $category ) ) {
128 + $category = 'portfolio-category';
129 + }
130 + }
131 +
132 + if ( strpos( $permalink, '%author%' ) !== false ) {
133 + $authordata = get_userdata( $post->post_author );
134 + $author = $authordata->user_nicename;
135 + }
136 +
137 + $date = explode( ' ', date( 'Y m d H i s', $unixtime ) );
138 + $rewritereplace = array(
139 + $date[0],
140 + $date[1],
141 + $date[2],
142 + $date[3],
143 + $date[4],
144 + $date[5],
145 + $post->post_name,
146 + $post->ID,
147 + $category,
148 + $author,
149 + $post->post_name,
150 + );
151 + $permalink = str_replace( $rewritecode, $rewritereplace, $permalink );
152 + }
153 + return $permalink;
130 154 }
131 -
155 +add_filter( 'post_type_link', 'kadence_toolkit_portfolio_permalink', 10, 3 );