-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwpum-profile-post-types.php
101 lines (81 loc) · 2.41 KB
/
wpum-profile-post-types.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/*
Plugin Name: WPUM Profile Post Types
Plugin URI: https://wpusermanager.com
Description: Addon for WP User Manager - add other custom post type entries to user profiles
Version: 1.0
Author: WP User Manager
Author URI: https://wpusermanager.com/
License: GPLv3+
*/
/**
* @param array $paths
*
* @return array
*/
function wpumpp_template_paths( $paths ) {
$paths[] = dirname( __FILE__ ) . '/templates';
return $paths;
}
add_filter( 'wpum_template_paths', 'wpumpp_template_paths' );
/**
* Register new settings for the addon.
*
* @param array $settings
*
* @return array
*/
function wpumpp_register_settings( $settings ) {
$settings['profiles_content'][] = array(
'id' => 'profile_cpts',
'name' => __( 'Display Custom Post Types' ),
'desc' => __( 'Display a tab for each Custom Post Type to display users submitted entries on their profile page.', 'wpum-woocommerce' ),
'type' => 'multiselect',
'options' => wpumpp_get_post_types(),
'multiple' => true,
);
return $settings;
}
add_action( 'wpum_registered_settings', 'wpumpp_register_settings' );
function wpumpp_get_post_types() {
$args = array(
'public' => true,
'_builtin' => false,
);
$all_post_types = get_post_types( apply_filters( 'wpumpp_post_type_args', $args ), 'objects' );
$post_types = array();
foreach ( $all_post_types as $post_type ) {
$post_types[] = array(
'value' => $post_type->name,
'label' => $post_type->label,
);
}
return $post_types;
}
function wpumpp_init() {
if ( ! function_exists( 'wpum_get_option' ) ) {
return;
}
$post_types = wpum_get_option( 'profile_cpts', array() );
if ( empty( $post_types ) ) {
return;
}
foreach ( $post_types as $key => $slug ) {
$post_type = get_post_type_object( $slug );
add_filter( 'wpum_get_registered_profile_tabs', function( $tabs ) use ( $slug, $key, $post_type ) {
$tabs[ $slug ] = [
'name' => esc_html( apply_filters( 'wpum_profile_tab_post_type_name', $post_type->label, $post_type ) ),
'priority' => $key + 10,
];
return $tabs;
} );
add_action( 'wpum_profile_page_content_' . $slug, function ( $data ) use ( $post_type ) {
WPUM()->templates->set_template_data( [
'post_type' => $post_type,
'user' => $data->user,
'current_user_id' => $data->current_user_id,
] )->get_template_part( 'profiles/custom-post-types' );
} );
}
}
add_action( 'init', 'wpumpp_init', 9999 );