(string) Database table name
*
* 'wpda_list_columns' => (object) Reference to a WPDA_List_Columns object
*
* 'singular' => (string) Singular object label
*
* 'plural' => (string) plural object label
*
* 'ajax' => (string) TRUE = list table support Ajax
*
* 'column_headers' => (array|string) Column headers
*
* 'title' => (string) Page title
*
* 'subtitle' => (string) Page subtitle
*
* 'bulk_export_enabled' => (boolean)
*
* 'search_box_enabled' => (boolean)
*
* 'bulk_actions_enabled' => (boolean)
*
* 'show_view_link' => (string) on|off
*
* 'allow_insert' => (string) on|off
*
* 'allow_update' => (string) on|off
*
* 'allow_delete' => (string) on|off
*
* 'allow_import' => (string) on|off
*
* 'hide_navigation' => (boolean)
*
* 'default_where' => (string)
*
* ]
* @since 1.0.0
*/
public function __construct( $args = array() ) {
global $wpdb;
if ( !isset( $args['table_name'] ) ) {
// Calling WPDA_List_Table without a table_name doesn't make sense.
wp_die( esc_attr__( 'ERROR: Wrong arguments [no table argument]', 'wp-data-access' ) );
}
if ( !isset( $args['wpda_list_columns'] ) ) {
// Calling WPDA_List_Table without a column list is not allowed.
wp_die( esc_attr__( 'ERROR: Wrong arguments [no columns argument]', 'wp-data-access' ) );
}
parent::__construct( array(
'singular' => ( isset( $args['singular'] ) ? $args['singular'] : __( 'Row', 'wp-data-access' ) ),
'plural' => ( isset( $args['plural'] ) ? $args['plural'] : __( 'Rows', 'wp-data-access' ) ),
'ajax' => ( isset( $args['ajax'] ) ? $args['ajax'] : false ),
) );
// Set schema name is available.
if ( isset( $args['wpdaschema_name'] ) ) {
$this->schema_name = $args['wpdaschema_name'];
}
// Set table name (availability already checked).
$this->table_name = $args['table_name'];
if ( self::LIST_BASE_TABLE !== $this->table_name ) {
// Whenever a table name is provided through a URL we are risking an SQL injection attack. Our
// defence mechanism here is to check whether the table name provided exists in our database.
// If it does not we'll terminate the process with an error.
// Although this check is only needed when a table name is provided through the URL we will perform
// it in all situations. It is a fast query which makes our application much more safe and reliable.
$this->wpda_data_dictionary = new WPDA_Dictionary_Exist($this->schema_name, $this->table_name);
if ( !$this->wpda_data_dictionary->table_exists() ) {
wp_die( esc_attr__( 'ERROR: Invalid table name or not authorized', 'wp-data-access' ) );
}
}
$this->pid = ( isset( $args['pid'] ) ? $args['pid'] : '' );
// Get menu slag of current page.
if ( isset( $_REQUEST['page'] ) ) {
$this->page = sanitize_text_field( wp_unslash( $_REQUEST['page'] ) );
} else {
// In order to show a list table we need a page.
wp_die( esc_attr__( 'ERROR: Wrong arguments [no page argument]', 'wp-data-access' ) );
}
// Use column list: argument wpda_list_columns (availability already checked).
$this->wpda_list_columns =& $args['wpda_list_columns'];
// Set pagination.
if ( is_admin() ) {
$this->items_per_page = WPDA::get_option( WPDA::OPTION_BE_PAGINATION );
} else {
$this->items_per_page = WPDA::get_option( WPDA::OPTION_FE_PAGINATION );
}
// Overwrite column header text if column headers were provided.
$this->column_headers = ( isset( $args['column_headers'] ) ? $args['column_headers'] : '' );
// Set title.
if ( isset( $args['title'] ) ) {
$this->title = $args['title'];
} else {
$this->title = __( 'Table', 'wp-data-access' ) . ' ' . strtoupper( $this->table_name );
}
// Set subtitle.
if ( isset( $args['subtitle'] ) ) {
$this->subtitle = $args['subtitle'];
} else {
$wp_tables = $wpdb->tables( 'all', true );
if ( isset( $wp_tables[substr( $this->table_name, strlen( $wpdb->prefix ) )] ) ) {
$this->subtitle = ' ' . WPDA::get_table_type_text( WPDA::TABLE_TYPE_WP );
} elseif ( WPDA::is_wpda_table( $this->table_name ) ) {
$this->subtitle = ' ' . WPDA::get_table_type_text( WPDA::TABLE_TYPE_WPDA );
}
}
if ( !(isset( $args['allow_import'] ) && 'off' === $args['allow_import']) ) {
try {
// Instantiate WPDA_Import.
$this->wpda_import = new WPDA_Import(( is_admin() ? "?page={$this->page}" : '' ), $this->schema_name, $this->table_name);
} catch ( \Exception $e ) {
// If import is turned off instantiation will fail. Handle is set to null (check in future calls).
$this->wpda_import = null;
}
}
if ( isset( $args['bulk_export_enabled'] ) ) {
$this->bulk_export_enabled = $args['bulk_export_enabled'];
}
if ( isset( $args['search_box_enabled'] ) ) {
$this->search_box_enabled = $args['search_box_enabled'];
}
if ( isset( $args['bulk_actions_enabled'] ) ) {
$this->bulk_actions_enabled = $args['bulk_actions_enabled'];
}
if ( 'on' !== WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK ) ) {
$this->show_view_link = WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK );
} else {
if ( isset( $args['show_view_link'] ) ) {
$this->show_view_link = $args['show_view_link'];
} else {
$this->show_view_link = WPDA::get_option( WPDA::OPTION_BE_VIEW_LINK );
}
}
if ( 'on' !== WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT ) ) {
$this->allow_insert = WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT );
} else {
if ( isset( $args['allow_insert'] ) ) {
$this->allow_insert = $args['allow_insert'];
} else {
$this->allow_insert = WPDA::get_option( WPDA::OPTION_BE_ALLOW_INSERT );
}
}
if ( 'on' !== WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE ) ) {
$this->allow_update = WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE );
} else {
if ( isset( $args['allow_update'] ) ) {
$this->allow_update = $args['allow_update'];
} else {
$this->allow_update = WPDA::get_option( WPDA::OPTION_BE_ALLOW_UPDATE );
}
}
if ( 'on' !== WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE ) ) {
$this->allow_delete = WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE );
} else {
if ( isset( $args['allow_delete'] ) ) {
$this->allow_delete = $args['allow_delete'];
} else {
$this->allow_delete = WPDA::get_option( WPDA::OPTION_BE_ALLOW_DELETE );
}
}
if ( isset( $args['hide_navigation'] ) ) {
$this->hide_navigation = $args['hide_navigation'];
}
$this->search_value = ( is_scalar( $this->get_search_value() ) ? str_replace( "\\'", '', (string) $this->get_search_value() ) : '' );
if ( isset( $_REQUEST["{$this->search_item_name}_old_value"] ) ) {
$this->search_value_old = sanitize_text_field( wp_unslash( $_REQUEST["{$this->search_item_name}_old_value"] ) );
} else {
$this->search_value_old = $this->search_value;
}
// Get page number(s).
if ( 'page_number' !== $this->page_number_item_name ) {
if ( isset( $_REQUEST['page_number'] ) ) {
$requested_page_number = sanitize_text_field( wp_unslash( $_REQUEST['page_number'] ) );
$this->page_number_link = '&page_number=' . esc_attr( $requested_page_number );
$this->page_number_item = "";
}
}
$this->page_number_link .= '&paged=' . esc_attr( $this->get_pagenum() );
$this->page_number_item .= "";
// Add search arguments to link to return to same page.
foreach ( $_REQUEST as $key => $value ) {
if ( substr( $key, 0, 19 ) === 'wpda_search_column_' && count( array_filter( $this->wpda_list_columns->get_table_columns(), function ( $column ) use($key) {
return $column['column_name'] === substr( $key, 19 );
} ) ) > 0 ) {
if ( is_array( $value ) ) {
foreach ( $value as $elem_key => $elem_value ) {
$this->page_number_link .= '&' . esc_attr( $elem_key ) . '=' . esc_attr( $elem_value );
$this->page_number_item .= "";
}
} else {
$this->page_number_link .= '&' . esc_attr( $key ) . '=' . esc_attr( $value );
$this->page_number_item .= "";
}
}
}
// Check if a WHERE clause (filter) was defined.
if ( isset( $args['default_where'] ) ) {
$this->where = $args['default_where'];
}
// Get table settings.
$wpda_table_settings = WPDA_Table_Settings_Model::query( $this->table_name, $this->schema_name );
if ( isset( $wpda_table_settings[0]['wpda_table_settings'] ) ) {
$this->wpda_table_settings = json_decode( $wpda_table_settings[0]['wpda_table_settings'] );
}
// Get estimated row count.
$this->row_count_estimate = WPDA::get_row_count_estimate( $this->schema_name, $this->table_name, $this->wpda_table_settings );
$this->table_rows = $this->row_count_estimate['row_count'];
// Get project table settings.
global $wpda_project_mode;
if ( is_array( $wpda_project_mode ) ) {
$setname = $wpda_project_mode['setname'];
$wpda_project_table_settings = null;
$wpda_project_table_settings_db = WPDP_Project_Design_Table_Model::static_query( $this->schema_name, $this->table_name, $setname );
if ( isset( $wpda_project_table_settings_db->tableinfo ) ) {
$this->wpda_project_table_settings = $wpda_project_table_settings_db->tableinfo;
}
}
if ( isset( $args['show_page_title'] ) && false === $args['show_page_title'] ) {
$this->show_page_title = $args['show_page_title'];
}
if ( isset( $args['help_url'] ) ) {
$this->help_url = $args['help_url'];
}
foreach ( $this->wpda_list_columns->get_table_columns() as $table_columns ) {
$this->columns_indexed[$table_columns['column_name']] = $table_columns;
}
}
/**
* Overwrite method
*
* @return int|void
*/
public function get_pagenum() {
if ( isset( $_REQUEST[$this->page_number_item_name] ) ) {
$pagenum = ( isset( $_REQUEST[$this->page_number_item_name] ) ? absint( $_REQUEST[$this->page_number_item_name] ) : 0 );
if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] ) {
$pagenum = $this->_pagination_args['total_pages'];
}
return max( 1, $pagenum );
} else {
return parent::get_pagenum();
}
}
/**
* Set columns to be queries
*
* Set columns to be queried and shown in the list table.
* By default all columns in the table will be displayed.
*
* @param mixed $columns_queried Column list.
*
* @since 1.0.0
*/
public function set_columns_queried( $columns_queried ) {
$this->columns_queried = $columns_queried;
}
/**
* Enable or disable bulk actions
*
* @param boolean $bulk_actions_enabled TRUE = allowed, FALSE = not allowed.
*
* @since 1.0.0
*/
public function set_bulk_actions_enabled( $bulk_actions_enabled ) {
$this->bulk_actions_enabled = $bulk_actions_enabled;
}
/**
* Enable or disable bulk export options
*
* @param boolean $bulk_export_enabled TRUE = allowed, FALSE = not allowed.
*
* @since 1.0.0
*/
public function set_bulk_export_enabled( $bulk_export_enabled ) {
$this->bulk_export_enabled = $bulk_export_enabled;
}
/**
* Show or hide search box
*
* @param boolean $search_box_enabled TRUE = show search box, FALSE = do not show search bow.
*
* @since 1.0.0
*/
public function set_search_box_enabled( $search_box_enabled ) {
$this->search_box_enabled = $search_box_enabled;
}
/**
* Set page title
*
* @param string $title Page title.
*
* @since 1.0.0
*/
public function set_title( $title ) {
$this->title = $title;
}
/**
* Set page subtitle
*
* @param string $subtitle Page subtitle.
*
* @since 1.0.0
*/
public function set_subtitle( $subtitle ) {
$this->subtitle = $subtitle;
}
/**
* I18n text displayed when no data found
*
* @since 1.0.0
*/
public function no_items() {
echo esc_attr__( 'No data found', 'wp-data-access' );
}
/**
* Use this method to build parent child relationships.
*
* Overwrite this function if you want to use the list table as a child list table related to some parent
* form. You can add parent arguments to calls to make sure you get back to the right parent.
*
* @param array $item Column info.
* @return string String contains parent arguments.
* @since 1.5.0
*/
protected function add_parent_args_as_string( $item ) {
return '';
}
/**
* Render columns
*
* Three links are provided for every list table row:
* + 'View' => Link to view form (readonly data entry form)
* + 'Edit' => Link to data entry form (updatable)
* + 'Delete' => Link to delete record from database table
*
* Links to view, edit and delete records are only available if a primary key for the table is found. Without
* a primary key unique identification of records is not possible.
*
* Links to action are offered through hidden forms to prevent long URL's and problem when refreshing pages
* manually. More information about how and why is provided in source code at place where I thought the
* information could be helpful.
*
* @param array $item Column info.
* @param string $column_name Column name.
*
* @return mixed Value display in list table column
* @since 1.0.0
*/
public function column_default( $item, $column_name ) {
if ( $this->wpda_list_columns->get_table_columns()[0]['column_name'] === $column_name || $column_name === $this->first_display_column ) {
// First column: add row actions.
$count = count( $this->wpda_list_columns->get_table_primary_key() );
// phpcs:ignore -- 8.1 proof
if ( 0 === $count ) {
// No actions without a primary key!
// This automatically covers view processing correctly.
return $this->render_column_content( $item, $column_name ) . $this->row_actions( array(
'wpda_hide_column' => '',
) );
} else {
// Check rights.
if ( 'off' === $this->show_view_link && 'off' === $this->allow_update && 'off' === $this->allow_delete ) {
// No rights!
$actions = array();
$this->column_default_add_action( $item, $column_name, $actions );
if ( is_array( $actions ) && count( $actions ) > 0 ) {
// phpcs:ignore -- 8.1 proof
return sprintf( '%1$s %2$s', $this->render_column_content( $item, $column_name ), $this->row_actions( $actions ) );
} else {
return sprintf( '%1$s', $this->render_column_content( $item, $column_name ) );
}
}
// Check if row security is enabled.
$row_security = isset( $this->wpda_table_settings->table_settings->row_level_security ) && 'true' === $this->wpda_table_settings->table_settings->row_level_security;
// To prevent our URLs containing many arguments, we'll use post to submit row actions. Since our
// list table is build within a form and we cannot use nested forms we'll use a container (id =
// wpda_invisible_container) defined outside the list table, and add our forms to that container.
// We'll use jQuery to add our forms to the container. From the links in our rows we can then just
// submit any form in that container with jQuery as well.
$form_id = '_' . self::$list_number++;
$wp_nonce_keys = '';
$row_security_keys = '';
// We need to add keys and values for multi-column primary keys.
foreach ( $this->wpda_list_columns->get_table_primary_key() as $key ) {
$wp_nonce_keys .= "-{$item[$key]}";
if ( $row_security ) {
$row_security_keys .= "-{$key}-{$item[$key]}";
}
}
if ( $row_security ) {
$row_security_nonce = wp_create_nonce( "wpda-row-level-security-{$this->table_name}{$row_security_keys}" );
$row_security_nonce_field = "";
} else {
$row_security_nonce_field = '';
}
// Prepare url.
if ( is_admin() ) {
$url = "?page={$this->page}";
} else {
$url = '';
}
if ( 'on' === $this->show_view_link ) {
$wp_nonce_action = "wpda-query-{$this->table_name}{$wp_nonce_keys}";
$wp_nonce = wp_create_nonce( $wp_nonce_action );
// Build the row action. Use jQuery to add form to container.
// All items escaped in create_post_form().
$view_form = $this->create_post_form(
$item,
"view_form{$form_id}",
'view',
$url,
$wp_nonce,
$row_security_nonce_field,
$this->schema_name,
$this->table_name
);
?>
%s
',
__( 'View row data', 'wp-data-access' ),
"view_form{$form_id}",
__( 'View', 'wp-data-access' )
);
}
if ( 'on' === $this->allow_update || WPDA::is_wpda_table( $this->table_name ) ) {
$wp_nonce_action = "wpda-query-{$this->table_name}{$wp_nonce_keys}";
$wp_nonce = wp_create_nonce( $wp_nonce_action );
// Build the row action. Use jQuery to add form to container.
// All items escaped in create_post_form().
$edit_form = $this->create_post_form(
$item,
"edit_form{$form_id}",
'edit',
$url,
$wp_nonce,
$row_security_nonce_field,
$this->schema_name,
$this->table_name
);
?>
%s
',
__( 'Edit row data', 'wp-data-access' ),
"edit_form{$form_id}",
__( 'Edit', 'wp-data-access' )
);
}
if ( 'on' === $this->allow_delete || WPDA::is_wpda_table( $this->table_name ) ) {
$wp_nonce_action = "wpda-delete-{$this->table_name}{$wp_nonce_keys}";
$wp_nonce = wp_create_nonce( $wp_nonce_action );
// Build the row action. Use jQuery to add form to container.
// All items escaped in create_post_form().
$delete_form = $this->create_post_form(
$item,
"delete_form{$form_id}",
'delete',
$url,
$wp_nonce,
$row_security_nonce_field,
$this->schema_name,
$this->table_name
);
?>
%s
',
__( 'Delete row data (this cannot be undone)', 'wp-data-access' ),
$warning,
"delete_form{$form_id}",
__( 'Delete', 'wp-data-access' )
);
}
// Developers can add actions by adding their own implementation of following method.
$this->column_default_add_action( $item, $column_name, $actions );
if ( has_filter( 'wpda_column_default' ) ) {
// Use filter.
$filter = apply_filters(
'wpda_column_default',
'',
$item,
$column_name,
$this->table_name,
$this->schema_name,
$this->wpda_list_columns,
self::$list_number,
$this
);
if ( null !== $filter ) {
return sprintf( '%1$s %2$s', $filter, $this->row_actions( $actions ) );
}
}
return sprintf( '%1$s %2$s', $this->render_column_content( $item, $column_name ), $this->row_actions( $actions ) );
}
} else {
if ( substr( $column_name, 0, 15 ) === 'wpda_hyperlink_' ) {
$hyperlink_no = substr( $column_name, 15 );
if ( isset( $this->wpda_table_settings->hyperlinks[$hyperlink_no] ) ) {
$hyperlink = $this->wpda_table_settings->hyperlinks[$hyperlink_no];
$hyperlink_html = ( isset( $hyperlink->hyperlink_html ) ? $hyperlink->hyperlink_html : '' );
if ( '' !== $hyperlink_html ) {
// Substitute values.
foreach ( $item as $key => $value ) {
$hyperlink_html = str_replace( "\$\${$key}\$\$", str_replace( ' ', '%20', (string) $value ), $hyperlink_html );
}
}
$macro = new WPDA_Macro($hyperlink_html);
$hyperlink_html = $macro->exe_macro();
if ( '' !== $hyperlink_html ) {
// Link is not empty AFTER substitution.
if ( false !== strpos( ltrim( $hyperlink_html ), '<' ) ) {
return html_entity_decode( $hyperlink_html );
} else {
$hyperlink_label = ( isset( $hyperlink->hyperlink_label ) ? $hyperlink->hyperlink_label : '' );
$hyperlink_target = ( isset( $hyperlink->hyperlink_target ) ? $hyperlink->hyperlink_target : false );
$target = ( true === $hyperlink_target ? "target='_blank'" : '' );
if ( false === $hyperlink_target ) {
$json = json_decode( $hyperlink_html, true );
if ( isset( $json['url'] ) ) {
$hyperlink_target = $json['url'];
}
}
return "" . esc_attr( $hyperlink_label ) . "";
}
} else {
return '';
}
}
return 'ERROR';
} else {
// Check if column is of type media.
$media_type = WPDA_Media_Model::get_column_media( $this->table_name, $column_name, $this->schema_name );
if ( 'Image' === $media_type ) {
$image_ids = explode( ',', (string) $item[$column_name] );
// phpcs:ignore -- 8.1 proof
$image_src = '';
foreach ( $image_ids as $image_id ) {
$url = wp_get_attachment_url( esc_attr( $image_id ) );
if ( false !== $url ) {
$title = get_the_title( esc_attr( $image_id ) );
$image_src .= ( '' !== $image_src ? '
' : '' );
$image_src .= sprintf( '', esc_url( $url ), esc_attr( $title ) );
}
}
return $image_src;
} elseif ( 'ImageURL' === $media_type ) {
return sprintf( '
', esc_url( $item[$column_name] ) );
} elseif ( 'Attachment' === $media_type ) {
$media_ids = explode( ',', (string) $item[$column_name] );
// phpcs:ignore -- 8.1 proof
$media_links = '';
foreach ( $media_ids as $media_id ) {
$url = wp_get_attachment_url( esc_attr( $media_id ) );
if ( false !== $url ) {
$mime_type = get_post_mime_type( $media_id );
if ( false !== $mime_type ) {
$title = get_the_title( esc_attr( $media_id ) );
$media_links .= self::column_media_attachment( $url, $title, $mime_type );
}
}
}
return $media_links;
} elseif ( 'Hyperlink' === $media_type ) {
if ( null === $item[$column_name] || '' === $item[$column_name] ) {
return '';
} else {
if ( !(isset( $this->wpda_table_settings->table_settings->hyperlink_definition ) && 'text' === $this->wpda_table_settings->table_settings->hyperlink_definition) ) {
$hyperlink = json_decode( $item[$column_name], true );
if ( is_array( $hyperlink ) && isset( $hyperlink['label'] ) && isset( $hyperlink['url'] ) && isset( $hyperlink['target'] ) ) {
if ( '' === $hyperlink['url'] ) {
return '';
} else {
return "" . esc_attr( $hyperlink['label'] ) . "";
}
} else {
return '';
}
} else {
$hyperlink_label = $this->wpda_list_columns->get_column_label( $column_name );
return "" . esc_attr( $hyperlink_label ) . "";
}
}
} elseif ( 'Audio' === $media_type ) {
$audio_ids = explode( ',', (string) $item[$column_name] );
// phpcs:ignore -- 8.1 proof
$audio_src = '';
foreach ( $audio_ids as $audio_id ) {
if ( 'audio' === substr( get_post_mime_type( $audio_id ), 0, 5 ) ) {
$url = wp_get_attachment_url( esc_attr( $audio_id ) );
if ( false !== $url ) {
$title = get_the_title( esc_attr( $audio_id ) );
if ( false !== $url ) {
$audio_src .= '
has_items() ? 'style="padding-bottom:10px;"' : '' ); ?>> 'search-submit', ) ); } else { wpdadiehard_submit_button( $text, '', '', false, array( 'id' => 'search-submit', ) ); } ?>
schema_name, $this->table_name, $this->wpda_table_settings, $this->wpda_list_columns ); } /** * Get search value (entered by the user or taken from cookie). * * @return string * @since 1.5.0 */ protected function get_search_value() { if ( 'off' === WPDA::get_option( WPDA::OPTION_BE_REMEMBER_SEARCH ) ) { if ( isset( $_REQUEST[$this->search_item_name] ) ) { // phpcs:disable WordPress.Security.ValidatedSanitizedInput $value = wp_filter_nohtml_kses( wp_unslash( $_REQUEST[$this->search_item_name] ) ); // phpcs:enable WordPress.Security.ValidatedSanitizedInput return $value; } } if ( 'wpda_wpdp_' === substr( $this->page, 0, 10 ) ) { $cookie_name = $this->page; if ( isset( $_REQUEST['child_request'] ) ) { $cookie_name = 'NOCOOKIESFORCHILDREQUESTS'; // No search values stored for child tables. } foreach ( $_REQUEST as $key => $val ) { if ( strpos( $key, 'WPDA_PARENT_KEY*' ) === 0 ) { $cookie_name = 'NOCOOKIESFORCHILDREQUESTS'; // No search values stored for child tables. } } } else { $cookie_name = $this->page . '_search_' . str_replace( '.', '_', $this->table_name ); } if ( isset( $_REQUEST[$this->search_item_name] ) && '' !== $_REQUEST[$this->search_item_name] ) { // phpcs:disable WordPress.Security.ValidatedSanitizedInput $value = wp_filter_nohtml_kses( wp_unslash( $_REQUEST[$this->search_item_name] ) ); // phpcs:enable WordPress.Security.ValidatedSanitizedInput return $value; } elseif ( isset( $_COOKIE[$cookie_name] ) ) { // phpcs:disable WordPress.Security.ValidatedSanitizedInput $value = wp_filter_nohtml_kses( wp_unslash( $_COOKIE[$cookie_name] ) ); // phpcs:enable WordPress.Security.ValidatedSanitizedInput return $value; } else { return null; } } /** * Print column headers * * Overriding original method print_column_headers to support post instead of get. * Changes are marked! * * @param boolean $with_id Whether to set the id attribute or not. * * @since 1.0.0 * * @staticvar $cb_counter int */ public function print_column_headers( $with_id = true ) { list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info(); // phpcs:ignore -- 8.1 proof // ********************* // *** BEGIN CHANGES *** // ********************* // Code removed. // ******************* // *** END CHANGES *** // ******************* if ( isset( $_REQUEST['orderby'] ) ) { $current_orderby = sanitize_text_field( wp_unslash( $_REQUEST['orderby'] ) ); } else { $current_orderby = ''; } if ( isset( $_REQUEST['order'] ) && 'desc' === $_REQUEST['order'] ) { $current_order = 'desc'; } else { $current_order = 'asc'; } if ( !empty( $columns['cb'] ) ) { static $cb_counter = 1; $columns['cb'] = '' . ''; $cb_counter++; } foreach ( $columns as $column_key => $column_display_name ) { $class = array('manage-column', "column-{$column_key}"); if ( in_array( $column_key, (array) $hidden ) ) { // phpcs:ignore -- 8.1 proof $class[] = 'hidden'; } if ( 'cb' === $column_key ) { $class[] = 'check-column'; } elseif ( in_array( $column_key, array('posts', 'comments', 'links') ) ) { $class[] = 'num'; } if ( $column_key === $primary ) { $class[] = 'column-primary'; } if ( isset( $sortable[$column_key] ) ) { list( $orderby, $desc_first ) = (array) $sortable[$column_key]; // phpcs:ignore -- 8.1 proof if ( $current_orderby === $orderby ) { $order = ( 'asc' === $current_order ? 'desc' : 'asc' ); $class[] = 'sorted'; $class[] = $current_order; } else { $order = ( $desc_first ? 'desc' : 'asc' ); $class[] = 'sortable'; $class[] = ( $desc_first ? 'asc' : 'desc' ); } // ********************* // *** BEGIN CHANGES *** // ********************* // Code removed. // ******************* // *** END CHANGES *** // ******************* } $tag = ( 'cb' === $column_key ? 'td' : 'th' ); $scope = ( 'th' === $tag ? 'scope="col"' : '' ); $id = ( $with_id ? "id='{$column_key}'" : '' ); if ( !empty( $class ) ) { $class = "class='" . join( ' ', $class ) . "'"; } // ********************* // *** BEGIN CHANGES *** // ********************* echo '<' . esc_attr( $tag ) . ' ' . wp_kses_data( $scope ) . ' ' . wp_kses_data( $id ) . ' ' . wp_kses_data( $class ) . '>'; if ( isset( $sortable[$column_key] ) ) { ?> array( 'id' => array(), 'type' => array(), ), 'label' => array( 'class' => array(), 'for' => array(), ), ) ); } echo '' . esc_attr( $tag ) . '>'; // ******************* // *** END CHANGES *** // ******************* } } /** * Returns an associative array containing the bulk action * * @return array * @since 1.0.0 */ public function get_bulk_actions() { if ( !$this->bulk_actions_enabled ) { // Bulk actions disabled. return ''; } if ( empty( $this->wpda_list_columns->get_table_primary_key() ) ) { // Tables has no primary key: no bulk actions allowed! // Primary key is necessary to ensure uniqueness. return ''; } $actions = array(); if ( 'on' === $this->allow_delete ) { $actions = array( 'bulk-delete' => __( 'Delete Permanently', 'wp-data-access' ), ); } if ( $this->bulk_export_enabled && (WPDA::is_wpda_table( $this->table_name ) || WPDA::get_option( WPDA::OPTION_BE_EXPORT_ROWS ) === 'on') ) { if ( 'diehard' !== $this->page ) { // Not allowed on web page. $actions['bulk-export'] = __( 'Export to SQL', 'wp-data-access' ); } $actions['bulk-export-xml'] = __( 'Export to XML', 'wp-data-access' ); $actions['bulk-export-json'] = __( 'Export to JSON', 'wp-data-access' ); $actions['bulk-export-excel'] = __( 'Export to Excel', 'wp-data-access' ); $actions['bulk-export-csv'] = __( 'Export to CSV', 'wp-data-access' ); } return $actions; } /** * Generates the table navigation * * Generates the table navigation above or bellow the table and removes the * _wp_http_referrer and _wpnonce because it generates a error about URL too large. * * @param string $which CSS Class name. * * @return void * @since 1.0.0 */ protected function display_tablenav( $which ) { if ( !$this->hide_navigation && $this->items ) { ?>