prefix . WPCoder::PREFIX; $result = $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); if ( $result ) { wp_safe_redirect( Link::remove_item() ); exit; } return false; } public static function delete( $id ) { if ( ! isset( $id ) ) { return false; } global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; return $wpdb->delete( $table, [ 'id' => $id ], [ '%d' ] ); } public static function create( $columns ): void { global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $sql = "CREATE TABLE $table ($columns) DEFAULT CHARACTER SET {$wpdb->charset} COLLATE {$wpdb->collate};"; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); dbDelta( $sql ); } public static function get_all_data() { global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $result = $wpdb->get_results( "SELECT * FROM $table ORDER BY id ASC" ); return ! empty( $result ) ? $result : false; } public static function get_data_by_id( $id = '' ) { if ( empty( $id ) ) { return false; } global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $query = $wpdb->prepare( "SELECT * FROM $table WHERE id=%d", absint( $id ) ); return $wpdb->get_row( $query ); } public static function get_data_by_title( $title = '' ) { if ( empty( $title ) ) { return false; } global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $query = $wpdb->prepare( "SELECT * FROM $table WHERE title=%s", sanitize_text_field( $title ) ); return $wpdb->get_row( $query ); } public static function update( $data, $where, $data_formats ): void { if ( ! current_user_can( 'unfiltered_html' ) ) { return; } global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $result = $wpdb->update( $table, $data, $where, $data_formats ); } public static function insert( $data, $data_formats ) { if ( ! current_user_can( 'unfiltered_html' ) ) { return false; } global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $result = $wpdb->insert( $table, $data, $data_formats ); if ( $result ) { return $wpdb->insert_id; } return false; } public static function check_row( $id = '' ): bool { global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; if ( empty( $id ) ) { return false; } $check_row = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$table} WHERE id = %d", $id ) ); if ( ! empty( $check_row ) ) { return true; } return false; } public static function get_columns() { global $wpdb; $table_name = $wpdb->prefix . WPCoder::PREFIX; return $wpdb->get_results( "DESCRIBE $table_name" ); } public static function display_tags(): void { global $wpdb; $table = $wpdb->prefix . WPCoder::PREFIX; $result = $wpdb->get_results( "SELECT * FROM $table order by tag desc", ARRAY_A ); $tags = []; if ( ! empty( $result ) ) { foreach ( $result as $column ) { if ( ! empty( $column['tag'] ) ) { $tags[ $column['tag'] ] = $column['tag']; } } } if ( ! empty( $tags ) ) { foreach ( $tags as $tag ) { echo '