) ';
}
Common_Table::init( $table_name );
?>
) ';
}
Common_Table::init( $table_name );
?>
', \esc_attr( $page ) );
printf( ' ', \esc_attr( $paged ) );
printf( ' ', \esc_attr( Table_List::SEARCH_INPUT ), \esc_attr( Table_List::escaped_search_input() ) );
printf( ' ', \esc_attr( $table_name ) );
$id = isset( $_GET['id'] ) ? \sanitize_text_field( \wp_unslash( $_GET['id'] ) ) : '';
\wp_nonce_field( Table_List::NONCE_NAME );
echo ' ';
echo ' ';
$record = Common_Table::load_row_data(
$id
);
$columns = Common_Table::get_columns_info();
?>
prepare_items();
$core_table = '';
if ( in_array( $table_name, Common_Table::get_wp_core_tables(), true ) ) {
$core_table = ' ( ) ';
}
?>
Table_List::TABLE_MENU_SLUG,
'action' => 'add_table_data',
'show_table' => $table_name,
),
\admin_url( 'admin.php' )
);
$add_new_url = \wp_nonce_url( $add_new_url, 'add-row' );
?>
', \esc_attr( $page ) );
printf( ' ', \esc_attr( $paged ) );
printf( ' ', \esc_attr( $table_name ) );
echo '';
$table->search_box(
__( 'Search', '0-day-analytics' ),
strtolower( $table->get_table_name() ) . '-find'
);
echo '
';
$table->display();
?>
' . \__( 'This screen allows you to see all the tables in your Database where your WordPress site is currently running.', '0-day-analytics' ) . '';
$help_text .= '' . \__( 'You can specify how many rows to be shown, or filter and search for given value(s).', '0-day-analytics' ) . '
';
$help_text .= '' . \__( 'You can delete rows - keep in mind that this operation is destructive and can not be undone - make a backup first.', '0-day-analytics' ) . '
';
$help_text .= '' . \__( 'Bulk operations are supported.', '0-day-analytics' ) . '
';
$help_text .= '' . \__( 'Use the drop-down to select different table.', '0-day-analytics' ) . '
';
return $help_text;
}
/**
* Options Help
*
* Return help text for options screen
*
* @return string Help Text
*
* @since 2.4.1
*/
public static function add_config_content_table() {
if ( '' === Common_Table::get_name() ) {
$table_name = Common_Table::get_default_table();
if ( isset( $_REQUEST['show_table'] ) ) {
if ( \in_array( $_REQUEST['show_table'], Common_Table::get_tables() ) ) {
$table_name = $_REQUEST['show_table']; // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash
}
}
Common_Table::init( $table_name );
}
$table_info = Common_Table::get_table_status();
$help_text = '';
if ( ! empty( $table_info ) && isset( $table_info[0] ) ) {
\ob_start();
if ( isset( $table_info[0]['Name'] ) ) {
?>
Table_List::TABLE_MENU_SLUG,
Table_List::SEARCH_INPUT => Table_List::escaped_search_input(),
'show_table' => rawurlencode( $table ),
),
( ( $is_network ) ? \network_admin_url( 'admin.php' ) : \admin_url( 'admin.php' ) )
)
)
);
exit;
}
}
}
/**
* Removes unnecessary arguments if present and reloads.
*
* @return void
*
* @since 2.3.0
*/
public static function page_load() {
if ( ! empty( $_GET['_wp_http_referer'] ) ) {
\wp_safe_redirect(
\remove_query_arg( array( '_wp_http_referer' ), \wp_unslash( $_SERVER['REQUEST_URI'] ) )
);
exit;
}
}
/**
* Collects all the data from the form and updates the table.
*
* @return void
*
* @since 4.0.0
*/
public static function update_table() {
// Capability guard: only allow administrators (or users with equivalent capability).
if ( ! \current_user_can( 'manage_options' ) ) {
\wp_die( \esc_html__( 'You do not have permission to manage tables.', '0-day-analytics' ) );
}
// Bail if malformed Transient request.
if ( empty( $_REQUEST['record_id'] ) || empty( $_REQUEST['show_table'] ) ) {
return;
}
// Bail if nonce fails.
if ( empty( $_REQUEST['_wpnonce'] ) || ! WP_Helper::verify_admin_nonce( Table_List::NONCE_NAME ) ) {
return;
}
// Sanitize data.
$record_id = \sanitize_key( $_REQUEST['record_id'] );
$table_name = \sanitize_key( $_REQUEST['show_table'] );
if ( ! Common_Table::check_table_exists( $table_name ) ) {
return new \WP_Error( 'table_not_found', 'Table not found.' );
}
Common_Table::init( $table_name );
$columns = Common_Table::get_columns_info();
$cols_data = array();
$no_primary_key = true;
foreach ( $columns as $column ) {
$name = \esc_attr( $column['Field'] );
$extra = strtolower( $column['Extra'] );
// Skip auto-increment primary key.
if ( 'auto_increment' === $extra ) {
$cols_data[ $name ] = $record_id;
$no_primary_key = false;
continue;
}
if ( isset( $_POST[ $name ] ) ) {
$cols_data[ $name ] = \wp_unslash( $_POST[ $name ] );
}
}
$where = null;
if ( $no_primary_key ) {
$record = Common_Table::load_row_data(
$record_id
);
$where = array(
Common_Table::get_real_id_name() => $record[ Common_Table::get_real_id_name() ],
);
}
Common_Table::insert_row_record( $table_name, $cols_data, $where );
$context = isset( $_REQUEST['context'] ) ? \sanitize_text_field( $_REQUEST['context'] ) : 'site';
$is_network = ( $context === 'network' && \is_multisite() );
\wp_safe_redirect(
\remove_query_arg(
array( 'deleted' ),
\add_query_arg(
array(
'page' => Table_List::TABLE_MENU_SLUG,
'paged' => ( isset( $_POST['paged'] ) ) ? filter_input( INPUT_POST, 'paged', FILTER_SANITIZE_NUMBER_INT ) : 1,
Table_List::SEARCH_INPUT => ( isset( $_POST[ Table_List::SEARCH_INPUT ] ) ) ? \sanitize_text_field( \wp_unslash( $_POST[ Table_List::SEARCH_INPUT ] ) ) : '',
'updated' => true,
'show_table' => $table_name,
'event_type' => ( isset( $_REQUEST['event_type'] ) ? \sanitize_text_field( \wp_unslash( $_REQUEST['event_type'] ) ) : '' ),
),
( ( $is_network ) ? \network_admin_url( 'admin.php' ) : \admin_url( 'admin.php' ) )
)
)
);
exit;
}
/**
* Collects all the data from the form and inserts a new row.
*
* @return void|\WP_Error
*
* @since 4.4.0
*/
public static function insert_table() {
// Capability guard: only allow administrators (or users with equivalent capability).
if ( ! \current_user_can( 'manage_options' ) ) {
\wp_die( \esc_html__( 'You do not have permission to manage tables.', '0-day-analytics' ) );
}
// Bail if malformed request.
if ( empty( $_REQUEST['show_table'] ) ) {
\wp_die( \esc_html__( 'Missing table name.', '0-day-analytics' ) );
}
// Bail if nonce fails.
if ( empty( $_REQUEST['_wpnonce'] ) || ! \wp_verify_nonce( \wp_unslash( $_REQUEST['_wpnonce'] ), Table_List::NONCE_NAME ) ) {
\wp_die( \esc_html__( 'Security check failed.', '0-day-analytics' ) );
}
// Sanitize data.
$table_name = \sanitize_key( $_REQUEST['show_table'] );
if ( ! Common_Table::check_table_exists( $table_name ) ) {
return new \WP_Error( 'table_not_found', 'Table not found.' );
}
Common_Table::init( $table_name );
$columns = Common_Table::get_columns_info();
$cols_data = array();
foreach ( $columns as $column ) {
$name = \esc_attr( $column['Field'] );
$extra = strtolower( $column['Extra'] );
// Skip auto-increment primary key - it will be generated.
if ( 'auto_increment' === $extra ) {
continue;
}
// Only add data if field is present in POST.
if ( isset( $_POST[ $name ] ) ) {
$cols_data[ $name ] = \wp_unslash( $_POST[ $name ] );
}
}
// Insert without $where parameter - this creates a new row.
Common_Table::insert_row_record( $table_name, $cols_data );
$context = isset( $_REQUEST['context'] ) ? \sanitize_text_field( $_REQUEST['context'] ) : 'site';
$is_network = ( 'network' === $context && \is_multisite() );
\wp_safe_redirect(
\remove_query_arg(
array( 'deleted' ),
\add_query_arg(
array(
'page' => Table_List::TABLE_MENU_SLUG,
'paged' => ( isset( $_POST['paged'] ) ) ? filter_input( INPUT_POST, 'paged', FILTER_SANITIZE_NUMBER_INT ) : 1,
Table_List::SEARCH_INPUT => ( isset( $_POST[ Table_List::SEARCH_INPUT ] ) ) ? \sanitize_text_field( \wp_unslash( $_POST[ Table_List::SEARCH_INPUT ] ) ) : '',
'inserted' => true,
'show_table' => $table_name,
'event_type' => ( isset( $_REQUEST['event_type'] ) ? \sanitize_text_field( \wp_unslash( $_REQUEST['event_type'] ) ) : '' ),
),
( ( $is_network ) ? \network_admin_url( 'admin.php' ) : \admin_url( 'admin.php' ) )
)
)
);
exit;
}
}
}