__( 'Form', 'ninja-forms' ), //singular name of the listed records 'plural' => __( 'Forms', 'ninja-forms' ), //plural name of the listed records 'ajax' => false //should this table support ajax? ) ); } public function no_items() { _e( 'No forms found.', 'ninja-forms' ); } /** * Prepare the items for the table to process * * @return Void */ public function prepare_items() { wp_enqueue_script( 'nf-all-forms', Ninja_Forms::$url . 'assets/js/all-forms.js' ); wp_localize_script( 'nf-all-forms', 'nfi18n', array( 'confirm_delete' => __( 'Really Delete This Form? This will remove all fields and submission data. Recovery is not possible.', 'ninja-forms' ), ) ); $columns = $this->get_columns(); $hidden = $this->get_hidden_columns(); $sortable = $this->get_sortable_columns(); $data = $this->table_data(); usort( $data, array( &$this, 'sort_data' ) ); $perPage = 20; $currentPage = $this->get_pagenum(); $totalItems = count($data); $this->set_pagination_args( array( 'total_items' => $totalItems, 'per_page' => $perPage ) ); $data = array_slice($data,(($currentPage-1)*$perPage),$perPage); $this->_column_headers = array($columns, $hidden, $sortable); $this->items = $data; } /** * Override the parent columns method. Defines the columns to use in your listing table * * @return Array */ public function get_columns() { $columns = array( 'cb' => '', 'title' => __( 'Form Title', 'ninja-forms' ), 'shortcode' => __( 'Shortcode', 'ninja-forms' ), 'date' => __( 'Created', 'ninja-forms' ) ); return $columns; } /** * Define which columns are hidden * * @return Array */ public function get_hidden_columns() { return array(); } /** * Define the sortable columns * * @return Array */ public function get_sortable_columns() { return array( 'title' => array( __( 'title', 'ninja-forms' ), TRUE ), 'date' => array( __( 'date', 'ninja-forms' ), TRUE ), ); } /** * Get the table data * * @return Array */ private function table_data() { $data = array(); $forms = Ninja_Forms()->form()->get_forms(); foreach( $forms as $form ){ $data[] = array( 'id' => $form->get_id(), 'title' => $form->get_setting( 'title' ), 'shortcode' => apply_filters ( 'ninja_forms_form_list_shortcode','[ninja_form id=' . $form->get_id() . ']', $form->get_id() ), 'date' => $form->get_setting( 'created_at' ) ); } return $data; } /** * Define what data to show on each column of the table * * @param Array $item Data * @param String $column_name - Current column name * * @return Mixed */ public function column_default( $item, $column_name ) { switch( $column_name ) { case 'title': case 'shortcode': case 'date': return $item[ $column_name ]; default: return print_r( $item, true ) ; } } /** * Allows you to sort the data by the variables set in the $_GET * * @return Mixed */ private function sort_data( $a, $b ) { // Set defaults $orderby = 'id'; $order = 'asc'; // If orderby is set, use this as the sort column if(!empty($_GET['orderby'])) { $orderby = $_GET['orderby']; } // If order is set use this as the order if(!empty($_GET['order'])) { $order = $_GET['order']; } $result = strnatcmp( $a[$orderby], $b[$orderby] ); if($order === 'asc') { return $result; } return -$result; } function column_cb( $item ) { return sprintf( '', $item['id'] ); } function column_title( $item ) { $title = $item[ 'title' ]; $edit_url = add_query_arg( 'form_id', $item[ 'id' ], admin_url( 'admin.php?page=ninja-forms') ); $delete_url = add_query_arg( array( 'action' => 'delete', 'id' => $item[ 'id' ], '_wpnonce' => wp_create_nonce( 'nf_delete_form' ))); $duplicate_url = add_query_arg( array( 'action' => 'duplicate', 'id' => $item[ 'id' ], '_wpnonce' => wp_create_nonce( 'nf_duplicate_form' ))); $preview_url = add_query_arg( 'nf_preview_form', $item[ 'id' ], site_url() ); $submissions_url = add_query_arg( 'form_id', $item[ 'id' ], admin_url( 'edit.php?post_status=all&post_type=nf_sub') ); $form = Ninja_Forms()->form( $item[ 'id' ] )->get(); $locked = $form->get_setting( 'lock' ); Ninja_Forms::template( 'admin-menu-all-forms-column-title.html.php', compact( 'title', 'edit_url', 'delete_url', 'duplicate_url', 'preview_url', 'submissions_url', 'locked' ) ); } public function single_row( $item ) { $form = Ninja_Forms()->form( $item[ 'id' ] )->get(); echo '