Thank you for your inquiry.
Yes, your hope can be achieved in this plugin.
As an example, I will propose the structure, such as the following.
Table for multiusers:
CREATE TABLE user_data (
ID bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
user_id bigint(20) unsigned NOT NULL,
username varchar(100) NOT NULL,
profile text,
created datetime NOT NULL DEFAULT '0000-00-00 00:00:00' COMMENT 'Created Datetime',
updated timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Updated Datetime',
PRIMARY KEY (<code>ID</code>)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
Shortcode to entry data page:
[cdbt-entry table="user_data" bootstrap_style="true" display_title="true" hidden_cols="created"]
Filter for entry forms:
function my_shortcode_custom_forms( $elements_options, $shortcode_name, $table ){
if ( ! is_admin() && 'cdbt-entry' === $shortcode_name && 'user_data' === $table ) {
$_current_user_id = 0; // For guest user
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$_current_user_id = $current_user->ID;
}
foreach ( $elements_options as $_i => $_option ) {
if ( 'user_id' === $_option['elementName'] ) {
$elements_options[$_i]['elementType'] = 'hidden';
$elements_options[$_i]['defaultValue'] = $_current_user_id;
}
}
}
return $elements_options;
}
add_filter( 'cdbt_shortcode_custom_forms', 'my_shortcode_custom_forms', 10, 3 );
Shortcode of viewing only data of specific user:
[cdbt-view table="user_data" exclude_cols="ID,user_id,created,updated"]
Filter for viewing specific user data only:
function custom_filter_get_data_sql( $sql, $table_name, $sql_clauses ) {
if ( ! is_admin() && 'user_data' === $table_name ) {
$_current_user_id = 0; // For guest user
if ( is_user_logged_in() ) {
$current_user = wp_get_current_user();
$_current_user_id = $current_user->ID;
}
$_new_sql = <<<SQL
SELECT %s
FROM %s
WHERE user_id=%s
%s %s
SQL;
$sql = sprintf( $_new_sql, $sql_clauses[0], $table_name, $_current_user_id, $sql_clauses[2], $sql_clauses[3] );
}
return $sql;
}
add_filter( 'cdbt_crud_get_data_sql', 'custom_filter_get_data_sql', 10, 3 );
Please try to refer.
Thank you,