| @@ -1,7 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace HTML_Forms\Admin; |
| 4 | + | |
| 4 | 5 | use HTML_Forms\Form; |
| 5 | 6 | use WP_List_Table, WP_Post; |
| 6 | 7 | |
| 7 | 8 | // Check if WP Core class exists so that we can keep testing rest of HTML Forms in isolation.. |
| @@ -14,10 +15,10 @@ | ||
| 14 | 15 | */ |
| 15 | 16 | public $is_trash = false; |
| 16 | 17 | |
| 17 | 18 | /** |
| 18 | - * @var array | |
| 19 | - */ | |
| 19 | + * @var array | |
| 20 | + */ | |
| 20 | 21 | private $settings = array(); |
| 21 | 22 | |
| 22 | 23 | /** |
| 23 | 24 | * Constructor |
| @@ -32,9 +33,12 @@ | ||
| 32 | 33 | ); |
| 33 | 34 | |
| 34 | 35 | $this->settings = $settings; |
| 35 | 36 | $this->process_bulk_action(); |
| 37 | + $this->prepare_items(); | |
| 38 | + } | |
| 36 | 39 | |
| 40 | + public function prepare_items() { | |
| 37 | 41 | $columns = $this->get_columns(); |
| 38 | 42 | $sortable = $this->get_sortable_columns(); |
| 39 | 43 | $hidden = array(); |
| 40 | 44 | $this->_column_headers = array( $columns, $hidden, $sortable ); |
| @@ -51,12 +55,12 @@ | ||
| 51 | 55 | /** |
| 52 | 56 | * Get an associative array ( id => link ) with the list |
| 53 | 57 | * of views available on this table. |
| 54 | 58 | * |
| 59 | + * @return array | |
| 55 | 60 | * @since 3.1.0 |
| 56 | 61 | * @access protected |
| 57 | 62 | * |
| 58 | - * @return array | |
| 59 | 63 | */ |
| 60 | 64 | public function get_views() { |
| 61 | 65 | $counts = wp_count_posts( 'html-form' ); |
| 62 | 66 | $current = isset( $_GET['post_status'] ) ? $_GET['post_status'] : ''; |
| @@ -77,13 +81,15 @@ | ||
| 77 | 81 | |
| 78 | 82 | if ( $this->is_trash ) { |
| 79 | 83 | $actions['untrash'] = __( 'Restore', 'html-forms' ); |
| 80 | 84 | $actions['delete'] = __( 'Delete Permanently', 'html-forms' ); |
| 85 | + | |
| 81 | 86 | return $actions; |
| 82 | 87 | } |
| 83 | 88 | |
| 84 | - $actions['trash'] = __( 'Move to Trash', 'html-forms' ); | |
| 89 | + $actions['trash'] = __( 'Delete Permanently', 'html-forms' ); | |
| 85 | 90 | $actions['duplicate'] = __( 'Duplicate', 'html-forms' ); |
| 91 | + | |
| 86 | 92 | return $actions; |
| 87 | 93 | } |
| 88 | 94 | |
| 89 | 95 | public function get_default_primary_column_name() { |
| @@ -110,10 +116,19 @@ | ||
| 110 | 116 | |
| 111 | 117 | /** |
| 112 | 118 | * @return array |
| 113 | 119 | */ |
| 120 | + public function get_hidden_columns() { | |
| 121 | + return array(); | |
| 122 | + } | |
| 123 | + | |
| 124 | + /** | |
| 125 | + * @return array | |
| 126 | + */ | |
| 114 | 127 | public function get_sortable_columns() { |
| 115 | - return array(); | |
| 128 | + return array( | |
| 129 | + 'form_name' => array( 'post_title', true ), | |
| 130 | + ); | |
| 116 | 131 | } |
| 117 | 132 | |
| 118 | 133 | /** |
| 119 | 134 | * @return array |
| @@ -118,9 +133,8 @@ | ||
| 118 | 133 | /** |
| 119 | 134 | * @return array |
| 120 | 135 | */ |
| 121 | 136 | public function get_items() { |
| 122 | - | |
| 123 | 137 | $args = array(); |
| 124 | 138 | |
| 125 | 139 | if ( ! empty( $_GET['s'] ) ) { |
| 126 | 140 | $args['s'] = sanitize_text_field( $_GET['s'] ); |
| @@ -129,14 +143,22 @@ | ||
| 129 | 143 | if ( ! empty( $_GET['post_status'] ) ) { |
| 130 | 144 | $args['post_status'] = sanitize_text_field( $_GET['post_status'] ); |
| 131 | 145 | } |
| 132 | 146 | |
| 133 | - $items = hf_get_forms( $args ); | |
| 134 | - return $items; | |
| 147 | + if ( ! empty( $_GET['order'] ) ) { | |
| 148 | + $args['order'] = $_GET['order']; | |
| 149 | + } | |
| 150 | + | |
| 151 | + if ( ! empty( $_GET['orderby'] ) ) { | |
| 152 | + $args['orderby'] = $_GET['orderby']; | |
| 153 | + } | |
| 154 | + | |
| 155 | + return hf_get_forms( $args ); | |
| 135 | 156 | } |
| 136 | 157 | |
| 137 | 158 | /** |
| 138 | 159 | * @param Form $form |
| 160 | + * | |
| 139 | 161 | * @return string |
| 140 | 162 | */ |
| 141 | 163 | public function column_cb( $form ) { |
| 142 | 164 | return sprintf( '<input type="checkbox" name="forms[]" value="%s" />', $form->ID ); |
| @@ -152,8 +174,9 @@ | ||
| 152 | 174 | } |
| 153 | 175 | |
| 154 | 176 | /** |
| 155 | 177 | * @param Form $form |
| 178 | + * | |
| 156 | 179 | * @return string |
| 157 | 180 | */ |
| 158 | 181 | public function column_form_name( Form $form ) { |
| 159 | 182 | if ( $this->is_trash ) { |
| @@ -163,19 +186,10 @@ | ||
| 163 | 186 | $edit_link = admin_url( 'admin.php?page=html-forms&view=edit&form_id=' . $form->ID ); |
| 164 | 187 | $title = '<strong><a class="row-title" href="' . $edit_link . '">' . esc_html( $form->title ) . '</a></strong>'; |
| 165 | 188 | |
| 166 | 189 | $actions = array(); |
| 167 | - $tabs = array( | |
| 168 | - 'fields' => __( 'Fields', 'html-forms' ), | |
| 169 | - 'messages' => __( 'Messages', 'html-forms' ), | |
| 170 | - 'settings' => __( 'Settings', 'html-forms' ), | |
| 171 | - 'actions' => __( 'Actions', 'html-forms' ), | |
| 172 | - ); | |
| 190 | + $tabs = hf_get_admin_tabs( $form ); | |
| 173 | 191 | |
| 174 | - if ( $form->settings['save_submissions'] ) { | |
| 175 | - $tabs['submissions'] = __( 'Submissions', 'html-forms' ); | |
| 176 | - } | |
| 177 | - | |
| 178 | 192 | foreach ( $tabs as $tab_slug => $tab_title ) { |
| 179 | 193 | $actions[ $tab_slug ] = '<a href="' . esc_attr( add_query_arg( array( 'tab' => $tab_slug ), $edit_link ) ) . '">' . $tab_title . '</a>'; |
| 180 | 194 | } |
| 181 | 195 | |
| @@ -183,8 +197,9 @@ | ||
| 183 | 197 | } |
| 184 | 198 | |
| 185 | 199 | /** |
| 186 | 200 | * @param Form $form |
| 201 | + * | |
| 187 | 202 | * @return string |
| 188 | 203 | */ |
| 189 | 204 | public function column_shortcode( Form $form ) { |
| 190 | 205 | if ( $this->is_trash ) { |
| @@ -239,25 +254,26 @@ | ||
| 239 | 254 | } |
| 240 | 255 | } |
| 241 | 256 | |
| 242 | 257 | public function process_bulk_action_trash( $forms ) { |
| 243 | - return array_map( 'wp_trash_post', $forms ); | |
| 258 | + array_map( 'wp_trash_post', $forms ); | |
| 244 | 259 | } |
| 245 | 260 | |
| 246 | 261 | public function process_bulk_action_delete( $forms ) { |
| 247 | - return array_map( 'wp_delete_post', $forms ); | |
| 262 | + array_map( 'wp_delete_post', $forms ); | |
| 248 | 263 | } |
| 249 | 264 | |
| 250 | 265 | public function process_bulk_action_untrash( $forms ) { |
| 251 | - return array_map( 'wp_untrash_post', $forms ); | |
| 266 | + array_map( 'wp_untrash_post', $forms ); | |
| 252 | 267 | } |
| 253 | 268 | |
| 254 | 269 | /** |
| 255 | 270 | * Generates content for a single row of the table |
| 256 | 271 | * |
| 272 | + * @param Form $form The current item | |
| 273 | + * | |
| 257 | 274 | * @since 3.1.0 |
| 258 | 275 | * |
| 259 | - * @param Form $form The current item | |
| 260 | 276 | */ |
| 261 | 277 | public function single_row( $form ) { |
| 262 | 278 | echo sprintf( '<tr id="hf-forms-item-%d">', $form->ID ); |
| 263 | 279 | $this->single_row_columns( $form ); |