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 +144 -121 3.2 → 4.9.12.2 View file →
@@ -1,132 +1,155 @@
1 1 <?php
2 -// Custom post types
3 -function kad_portfolio_post_init() {
4 - $portfoliolabels = array(
5 - 'name' => __('Portfolio', 'virtue-toolkit'),
6 - 'singular_name' => __('Portfolio Item', 'virtue-toolkit'),
7 - 'add_new' => __('Add New', 'virtue-toolkit'),
8 - 'add_new_item' => __('Add New Portfolio Item', 'virtue-toolkit'),
9 - 'edit_item' => __('Edit Portfolio Item', 'virtue-toolkit'),
10 - 'new_item' => __('New Portfolio Item', 'virtue-toolkit'),
11 - 'all_items' => __('All Portfolio', 'virtue-toolkit'),
12 - 'view_item' => __('View Portfolio Item', 'virtue-toolkit'),
13 - 'search_items' => __('Search Portfolio', 'virtue-toolkit'),
14 - 'not_found' => __('No Portfolio Item found', 'virtue-toolkit'),
15 - 'not_found_in_trash' => __('No Portfolio Items found in Trash', 'virtue-toolkit'),
16 - 'parent_item_colon' => '',
17 - 'menu_name' => __('Portfolio', 'virtue-toolkit')
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', 'virtue-toolkit' ),
38 - 'singular_name' => __( 'Type', 'virtue-toolkit' ),
39 - 'search_items' => __( 'Search Type', 'virtue-toolkit' ),
40 - 'all_items' => __( 'All Type', 'virtue-toolkit' ),
41 - 'parent_item' => __( 'Parent Type', 'virtue-toolkit' ),
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' ),
42 52 'parent_item_colon' => __( 'Parent Type:', 'virtue-toolkit' ),
43 - 'edit_item' => __( 'Edit Type', 'virtue-toolkit' ),
44 - 'update_item' => __( 'Update Type', 'virtue-toolkit' ),
45 - 'add_new_item' => __( 'Add New Type', 'virtue-toolkit' ),
46 - 'new_item_name' => __( 'New Type Name', '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 - $portfolio_type_slug = apply_filters('kadence_portfolio_type_slug', 'portfolio-type');
49 - // Register Custom Taxonomy
50 - register_taxonomy('portfolio-type',array('portfolio'), array(
51 - 'hierarchical' => true, // define whether to use a system like tags or categories
52 - 'labels' => $worklabels,
53 - 'show_ui' => true,
54 - 'query_var' => true,
55 - 'rewrite' => array( 'slug' => $portfolio_type_slug )
56 - ));
57 58
58 - 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 );
59 73 }
60 -add_action( 'init', 'kad_portfolio_post_init', 1 );
61 -function kad_portfolio_permalink_init(){
62 -global $wp_rewrite;
63 -$port_rewrite = apply_filters('kadence_portfolio_permalink_slug', 'portfolio');
64 -$portfolio_structure = '/'.$port_rewrite.'/%portfolio%';
65 -$wp_rewrite->add_rewrite_tag("%portfolio%", '([^/]+)', "portfolio=");
66 -$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 );
67 86 }
68 -add_action( 'init', 'kad_portfolio_permalink_init', 2 );
87 +add_action( 'init', 'kadence_toolkit_portfolio_permalink_init', 2 );
69 88
70 -// Add filter to plugin init function
71 -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 + );
72 111
73 -function kad_portfolio_permalink($permalink, $post_id, $leavename) {
74 - $post = get_post($post_id);
75 - $rewritecode = array(
76 - '%year%',
77 - '%monthnum%',
78 - '%day%',
79 - '%hour%',
80 - '%minute%',
81 - '%second%',
82 - $leavename? '' : '%postname%',
83 - '%post_id%',
84 - '%category%',
85 - '%author%',
86 - $leavename? '' : '%pagename%',
87 - );
88 -
89 - if ( '' != $permalink && !in_array($post->post_status, array('draft', 'pending', 'auto-draft')) ) {
90 - $unixtime = strtotime($post->post_date);
91 -
92 - $category = '';
93 - if ( strpos($permalink, '%category%') !== false ) {
94 - $cats = wp_get_post_terms($post->ID, 'portfolio-type', array( 'orderby' => 'parent', 'order' => 'DESC' ));
95 - if ( $cats ) {
96 - //usort($cats, '_usort_terms_by_ID'); // order by ID
97 - $category = $cats[0]->slug;
98 - }
99 - // show default category in permalinks, without
100 - // having to assign it explicitly
101 - if ( empty($category) ) {
102 - $category = 'portfolio-category';
103 - }
104 - }
105 -
106 - $author = '';
107 - if ( strpos($permalink, '%author%') !== false ) {
108 - $authordata = get_userdata($post->post_author);
109 - $author = $authordata->user_nicename;
110 - }
111 -
112 - $date = explode(" ",date('Y m d H i s', $unixtime));
113 - $rewritereplace =
114 - array(
115 - $date[0],
116 - $date[1],
117 - $date[2],
118 - $date[3],
119 - $date[4],
120 - $date[5],
121 - $post->post_name,
122 - $post->ID,
123 - $category,
124 - $author,
125 - $post->post_name,
126 - );
127 - $permalink = str_replace($rewritecode, $rewritereplace, $permalink);
128 - } else { // if they're not using the fancy permalink option
129 - }
130 - 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;
131 154 }
132 -
155 +add_filter( 'post_type_link', 'kadence_toolkit_portfolio_permalink', 10, 3 );