class-learndash-admin-group-edit.php
6.74 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?php
/**
* LearnDash Admin Group Edit.
*
* @since 3.2.0
* @package LearnDash\Group\Edit
*/
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ( class_exists( 'Learndash_Admin_Post_Edit' ) ) && ( ! class_exists( 'Learndash_Admin_Group_Edit' ) ) ) {
/**
* Class LearnDash Admin Group Edit.
*
* @since 3.2.0
* @uses Learndash_Admin_Post_Edit
*/
class Learndash_Admin_Group_Edit extends Learndash_Admin_Post_Edit {
/**
* Public constructor for class.
*
* @since 3.2.0
*/
public function __construct() {
$this->post_type = learndash_get_post_type_slug( 'group' );
parent::__construct();
}
/**
* On Load handler function for this post type edit.
* This function is called by a WP action when the admin
* page 'post.php' or 'post-new.php' are loaded.
*
* @since 3.2.0
*/
public function on_load() {
if ( $this->post_type_check() ) {
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-display-content.php';
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-access-settings.php';
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-users.php';
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-leaders.php';
/** This filter is documented in includes/admin/class-learndash-admin-menus-tabs.php */
if ( true === apply_filters( 'learndash_show_metabox_group_courses', true ) ) {
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-courses.php';
require_once LEARNDASH_LMS_PLUGIN_DIR . 'includes/settings/settings-metaboxes/class-ld-settings-metabox-group-courses-enroll.php';
}
parent::on_load();
$this->_metaboxes = apply_filters( 'learndash_post_settings_metaboxes_init_' . $this->post_type, $this->_metaboxes );
}
}
/**
* Register Groups meta box for admin
* Managed enrolled groups, users and group leaders
*
* @since 3.2.0
*
* @param string $post_type Post Type being edited.
* @param object $post WP_Post Post being edited.
*/
public function add_metaboxes( $post_type = '', $post = null ) {
if ( $this->post_type_check( $post_type ) ) {
parent::add_metaboxes( $post_type, $post );
}
add_meta_box(
'learndash_group_attributes_metabox',
sprintf(
// translators: placeholder: Group.
esc_html_x( '%s Attributes', 'placeholder: Group', 'learndash' ),
learndash_get_custom_label( 'group' )
),
array( $this, 'group_attributes_metabox_content' ),
learndash_get_post_type_slug( 'group' ),
'side'
);
}
/**
* Show Metabox
*
* @since 3.2.0
*
* @param object $post WP_Post object.
*/
public function group_attributes_metabox_content( $post ) {
if ( is_post_type_hierarchical( $post->post_type ) ) {
$dropdown_args = array(
'post_type' => $post->post_type,
'exclude_tree' => $post->ID,
'selected' => $post->post_parent,
'name' => 'group_parent_id',
'show_option_none' => esc_html__( '(no parent)', 'learndash' ),
'sort_column' => 'menu_order, post_title',
'echo' => 0,
);
$groups = wp_dropdown_pages( $dropdown_args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- See list of args above
if ( ! empty( $groups ) ) {
wp_nonce_field( 'ld-group-attributes-metabox-nonce', 'ld-group-attributes-metabox-nonce', false );
?>
<p class="post-attributes-label-wrapper group-parent-id-label-wrapper"><label class="post-attributes-label" for="group_parent_id">
<?php
echo sprintf(
// translators: placeholder: Group.
esc_html_x( '%s Parent', 'placeholder: Group', 'learndash' ),
learndash_get_custom_label( 'group' ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Method escapes output
);
?>
</label></p>
<?php echo $groups; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php
}
}
?>
<p class="post-attributes-label-wrapper group-menu-order-label-wrapper"><label class="post-attributes-label" for="group_menu_order"><?php esc_html_e( 'Order', 'learndash' ); ?></label></p>
<input name="group_menu_order" type="text" size="4" id="group_menu_order" value="<?php echo esc_attr( $post->menu_order ); ?>" />
<?php
}
/**
* Save metabox handler function.
*
* @since 3.2.0
*
* @param integer $post_id Post ID Question being edited.
* @param object $post WP_Post Question being edited.
* @param boolean $update If update true, else false.
*/
public function save_post( $post_id = 0, $post = null, $update = false ) {
if ( ! $this->post_type_check( $post ) ) {
return false;
}
if ( ! parent::save_post( $post_id, $post, $update ) ) {
return false;
}
if ( ! empty( $this->_metaboxes ) ) {
foreach ( $this->_metaboxes as $_metaboxes_instance ) {
$settings_fields = array();
$settings_fields = $_metaboxes_instance->get_post_settings_field_updates( $post_id, $post, $update );
$_metaboxes_instance->save_post_meta_box( $post_id, $post, $update, $settings_fields );
}
}
$edit_post = array(
'ID' => $post->ID,
'post_parent' => $post->post_parent,
'menu_order' => $post->menu_order,
);
if ( ( isset( $_POST['ld-group-attributes-metabox-nonce'] ) ) && ( ! empty( $_POST['ld-group-attributes-metabox-nonce'] ) ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ld-group-attributes-metabox-nonce'] ) ), 'ld-group-attributes-metabox-nonce' ) ) {
$updated_post = false;
if ( isset( $_POST['group_parent_id'] ) ) {
$updated_post = true;
$edit_post['post_parent'] = absint( $_POST['group_parent_id'] );
}
if ( isset( $_POST['group_menu_order'] ) ) {
$updated_post = true;
$edit_post['menu_order'] = absint( $_POST['group_menu_order'] );
}
if ( true === $updated_post ) {
wp_update_post( $edit_post );
}
}
$group_leaders = array();
$group_users = array();
$group_courses = array();
/**
* Fires after the group post data is updated.
*
* @since 2.3.1
* @deprecated 3.1.7
*
* @param integer $post_id Post ID of the group
* @param array $group_leaders An array of group leaders.
* @param array $group_users An array of group users.
* @param array $group_courses An array of group courses.
*/
do_action_deprecated( 'ld_group_postdata_updated', array( $post_id, $group_leaders, $group_users, $group_courses ), '3.1.7' );
}
// End of functions.
}
}
new Learndash_Admin_Group_Edit();