-
Notifications
You must be signed in to change notification settings - Fork 134
/
class-llms-admin-post-table-forms.php
152 lines (122 loc) · 3.41 KB
/
class-llms-admin-post-table-forms.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
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
<?php
/**
* Add, Customize, and Manage LifterLMS Forms Post Table Columns
*
* @package LifterLMS/Admin/PostTypes/PostTables/Classes
*
* @since 5.0.0
* @version 5.0.0
*/
defined( 'ABSPATH' ) || exit;
/**
* LLMS_Admin_Post_Table_Forms
*
* @since 5.0.0
*/
class LLMS_Admin_Post_Table_Forms {
/**
* Constructor
*
* @since 5.0.0
*
* @return void
*/
public function __construct() {
add_filter( 'manage_llms_form_posts_columns', array( $this, 'add_columns' ), 10, 1 );
add_filter( 'bulk_actions-edit-llms_form', array( $this, 'manage_bulk_actions' ), 10, 1 );
add_filter( 'post_row_actions', array( $this, 'manage_post_row_actions' ), 10, 2 );
add_action( 'manage_llms_form_posts_custom_column', array( $this, 'manage_columns' ), 10, 2 );
add_action( 'pre_get_posts', array( 'LLMS_Admin_Post_Table_Forms', 'pre_get_posts' ) );
}
/**
* Add Custom Columns
*
* @since 5.0.0
*
* @param array $columns Array of default columns.
* @return array
*/
public function add_columns( $columns ) {
if ( apply_filters( 'llms_forms_disable_post_table_cb', true ) ) {
unset( $columns['cb'] );
}
return llms_assoc_array_insert( $columns, 'title', 'location', __( 'Location', 'lifterlms' ) );
}
/**
* Manage available bulk actions.
*
* @since 5.0.0
*
* @param array $actions Array of actions.
* @return array
*/
public function manage_bulk_actions( $actions ) {
unset( $actions['edit'] );
return $actions;
}
/**
* Manage content of custom columns
*
* @since 5.0.0
*
* @param string $column Table column name.
* @param int $post_id WP Post ID of the form for the current row.
* @return void
*/
public function manage_columns( $column, $post_id ) {
if ( 'location' === $column ) {
$locs = LLMS_Forms::instance()->get_locations();
$loc = get_post_meta( $post_id, '_llms_form_location', true );
if ( isset( $locs[ $loc ] ) ) {
printf( '<strong>%1$s</strong><br><em>%2$s</em>', $locs[ $loc ]['name'], $locs[ $loc ]['description'] );
} else {
echo $loc;
}
}
}
/**
* Manage available bulk actions.
*
* @since 5.0.0
* @since 6.4.0 Use `LLMS_Forms::is_a_core_form()` to determine whether a form is a core form and cannot be deleted.
*
* @param array $actions Array of actions.
* @return array
*/
public function manage_post_row_actions( $actions, $post ) {
if ( 'llms_form' !== $post->post_type ) {
return $actions;
}
// Core forms cannot be deleted.
if ( LLMS_Forms::instance()->is_a_core_form( $post ) ) {
unset( $actions['trash'] );
}
unset( $actions['inline hide-if-no-js'] );
$link = get_permalink( $post );
if ( $link ) {
$label = sprintf( esc_attr__( 'View "%s"', 'lifterlms' ), $post->post_title );
$actions['view'] = sprintf( '<a href="%1$s" rel="bookmark" aria-label="%2$s">%3$s</a>', $link, $label, __( 'View', 'lifterlms' ) );
}
return $actions;
}
/**
* Ensure only core forms are displayed in the forms list.
*
* @since 5.0.0
*
* @param WP_Query $query Query object.
* @return void
*/
public static function pre_get_posts( $query ) {
if ( ! function_exists( 'get_current_screen' ) ) {
return;
}
$screen = get_current_screen();
if ( ! $screen || 'edit-llms_form' !== $screen->id || ! $query->is_main_query() ) {
return;
}
$query->set( 'meta_key', '_llms_form_is_core' );
$query->set( 'meta_value', 'yes' );
}
}
return new LLMS_Admin_Post_Table_Forms();