: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
<?php if ( ! defined( 'ABSPATH' ) ) exit;
if( ! class_exists( 'WP_List_Table' ) ){
if( file_exists( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' ) ) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
//TODO: Load local wp-list-table-class.php
class NF_Admin_AllFormsTable extends WP_List_Table
public function __construct() {
parent::__construct( array(
'singular' => esc_html__( 'Form', 'ninja-forms' ), //singular name of the listed records
'plural' => esc_html__( 'Forms', 'ninja-forms' ), //plural name of the listed records
'ajax' => false //should this table support ajax?
public function no_items() {
esc_html_e( 'No forms found.', 'ninja-forms' );
* Prepare the items for the table to process
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' => esc_html__( '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' ) );
$currentPage = $this->get_pagenum();
$totalItems = count($data);
$this->set_pagination_args( array(
'total_items' => $totalItems,
$data = array_slice($data,(($currentPage-1)*$perPage),$perPage);
$this->_column_headers = array($columns, $hidden, $sortable);
* Override the parent columns method. Defines the columns to use in your listing table
public function get_columns()
'cb' => '<input type="checkbox" />',
'title' => esc_html__( 'Form Title', 'ninja-forms' ),
'shortcode' => esc_html__( 'Shortcode', 'ninja-forms' ),
'date' => esc_html__( 'Created', 'ninja-forms' )
* Define which columns are hidden
public function get_hidden_columns()
* Define the sortable columns
public function get_sortable_columns()
'title' => array( esc_attr__( 'title', 'ninja-forms' ), TRUE ),
'date' => array( esc_attr__( 'date', 'ninja-forms' ), TRUE ),
private function table_data()
$forms = Ninja_Forms()->form()->get_forms();
foreach( $forms as $form ){
'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' )
* Define what data to show on each column of the table
* @param Array $item Data
* @param String $column_name - Current column name
public function column_default( $item, $column_name )
return $item[ $column_name ];
return print_r( $item, true ) ;
* Allows you to sort the data by the variables set in the $_GET
private function sort_data( $a, $b )
// If orderby is set, use this as the sort column
if(!empty($_GET['orderby']))
$orderby = WPN_Helper::sanitize_text_field($_GET['orderby']);
// If order is set use this as the order
if(!empty($_GET['order']))
$order = WPN_Helper::sanitize_text_field($_GET['order']);
$result = strnatcmp( $a[$orderby], $b[$orderby] );
function column_cb( $item )
'<input type="checkbox" name="bulk-delete[]" value="%s" />', $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();
$this->single_row_columns( $item );
* Returns an associative array containing the bulk action
public function get_bulk_actions()
'bulk-delete' => esc_html__( 'Delete', 'ninja-forms' )
public static function process_bulk_action()
if( ! isset( $_GET[ 'page' ] ) || 'ninja-forms' != $_GET[ 'page' ] ) return;
if ( isset( $_REQUEST[ 'action' ] ) && 'duplicate' === $_REQUEST[ 'action' ] ) {
// In our file that handles the request, verify the nonce.
$nonce = esc_attr( $_REQUEST['_wpnonce'] );
if ( ! wp_verify_nonce( $nonce, 'nf_duplicate_form' ) ) {
die( esc_html__( 'Go get a life, script kiddies', 'ninja-forms' ) );
NF_Database_Models_Form::duplicate( absint( $_GET['id'] ) );
wp_redirect( admin_url( 'admin.php?page=ninja-forms' ) );
if ( isset( $_REQUEST[ 'action' ] ) && 'delete' === $_REQUEST[ 'action' ] ) {
// In our file that handles the request, verify the nonce.
$nonce = esc_attr( $_REQUEST['_wpnonce'] );
if ( ! wp_verify_nonce( $nonce, 'nf_delete_form' ) ) {
die( esc_html__( 'Go get a life, script kiddies', 'ninja-forms' ) );
self::delete_item( absint( $_GET['id'] ) );
wp_redirect( admin_url( 'admin.php?page=ninja-forms' ) );
// If the delete bulk action is triggered
if ( ( isset( $_POST['action'] ) && $_POST['action'] == 'bulk-delete' )
|| ( isset( $_POST['action2'] ) && $_POST['action2'] == 'bulk-delete' )
// In our file that handles the request, verify the nonce.
$nonce = esc_attr( $_REQUEST['_wpnonce'] );
if ( ! wp_verify_nonce( $nonce, 'bulk-forms' ) ) {
die( esc_html__( 'Go get a life, script kiddies', 'ninja-forms' ) );
if( isset( $_POST[ 'bulk-delete' ] ) ) {
$delete_ids = esc_sql($_POST['bulk-delete']);
// loop over the array of record IDs and delete them
foreach ($delete_ids as $id) {
self::delete_item(absint($id));
wp_redirect( admin_url( 'admin.php?page=ninja-forms' ) );
public static function delete_item( $id )
$form = Ninja_Forms()->form( $id )->get();
} // END CLASS NF_Admin_AllFormsTable