db schema for storing multiple choices user settings

I am working on a project with the following data structure :

datamodel

A user need to be able to perform personal filtering on a given project, and this filtering needs to be saved (for each user/project pair). For example, he can choose to filter based on attribute1, attribute 2.

For storing such user settings, I did use this schema:

enter image description here

and I can have for example a setting for attribute1 filtering, and in my user_setting table store the corresponding value.

My problem is that the user needs to be able to perform a manual filtering on the objects (i.e. filtering them with checkbox). That would result in choosing objectIDs among all the object IDs.

My first thought was to store them in setting_value as comma separated values, but I read that I should not denormalize (note that there can be a lot of objects, and a lot of projects).

Is it a good approach or should I rethink my user setting storage approach?

Shortcode letting user to “join” the multiple user roles

It is possible to create some sort of shortcode which allows users to "join" the particular user role from frontend? Like if user is subscriber by default to let him join also user role such as "supporter" so he will be subscriber but also supporter?

And the second one the opposite – to let users from frontend "leave" the particular user role if they are members of it.

I’ve tried to google it, but I found only code to let users to switch between roles and I can’t figure out how to make it to let users to be member of multiple roles.

P. S. I am using plugin which allows me to have multiple user roles, so I am not limited by default WP functionality in this.

Most efficient way to calculate user compatibility from per user

I’m looking for an efficient way to calculate user to user compatibility.

A user has various preferences:

  • age range (min & max integer)
  • various choice based categories (multiple choice)
  • distance max
  • correlated desire (probably most complex; a user can hate/love/curious about "giving" say a "hug" and is thus looking for a user who love/curious about "receiving" a "hug"; in my actual application it’s not "hug" and some users are only interested in giving and some only in receiving)

Example user preference: age: between 21 and 50, gender: female, hair color: brown, interested in: reading, nature, giving "hugs": loves, receiving "hugs": hates

I’m open to any data structure that would assist the matching, but right now I have tables like "gender", "interests", "desires", and tables joining to users like "users_genders" (user_id, gender_id) to indicate what user is what gender, etc.

Ideally I’m looking to calculate a compatibility % but even just getting a list of users who are compatible enough would be acceptable

My previous approach was to have a function that took two user IDs returning the % compatibility between the two. Then for each user I’d loop through all other users, calling that function to calculate compatibility. Then I’d store this data in a table (user_id1, user_id2, compatibility). This "worked" and resulted in fast lookups that could even be sorted by compatibility (a definite plus but not required) but quickly created a HUGE table that crashed with <100K users. The table crashed because it became extremely large. I’m ideally looking for an approach that doesn’t use N*(N-1) rows for N users.

Doing the math, I see why, since I’m doing N*(N-1) compare & stores for N users.

I suppose I could try to address that by splitting the compatibility table by user so each table would have at most N-1 rows, but this isn’t ideal

The other approach I can think of is to turn the preference criteria into SQL. This wouldn’t easily get me a percentage score but at least I could get all matches compatible enough for a user (maybe removing conditions and trying again if no results)

My current approach is in MySQL. But I’m open to a different DB.

I found these related questions on Stackoverflow (though they really seem they belong more here)

https://stackoverflow.com/questions/27928548/representing-compatibility-between-two-users-in-mysql

https://stackoverflow.com/questions/31919589/how-to-get-the-best-match-without-looping-through-the-entire-database

which all seem to indicate that the (user_id1, user_id2, compatibility) table is probably my best bet, but I’m hoping that’s changed since these were asked or db wizards here have better ideas

Call external API in wordpress based on user input

I want to create a simple wordpress website in which I want to display a search box on a page. On searching a string in text/search box, an external API call should be made based on that string and the data returned by the API should be shown to user. I have successfully referred code from below URL so far – https://rapidapi.com/blog/integrate-external-api-wordpress/.

But I am not able to make a call to API based on string passed in text box. I have done below code so for in the child theme file page:-

<div id="primary" <?php generate_do_element_classes( 'content' ); ?>>     <main id="main" <?php generate_do_element_classes( 'main' ); ?>>         <form action="" method="post">         Enter query:         <input type=text name="t1">         <br>         <br>         <input type=submit name="s">         <?php         /**          * generate_before_main_content hook.          *          * @since 0.1          */         do_action( 'generate_before_main_content' );          if(isset($  _POST['s'])){         echo "good";             $  curl = curl_init();          curl_setopt_array($  curl, [             CURLOPT_URL => "******API URL*****/".$  _POST['t1'],             CURLOPT_RETURNTRANSFER => true,             CURLOPT_FOLLOWLOCATION => true,             CURLOPT_ENCODING => "",             CURLOPT_MAXREDIRS => 10,             CURLOPT_TIMEOUT => 30,             CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,             CURLOPT_CUSTOMREQUEST => "GET",             CURLOPT_HTTPHEADER => [                 "x-rapidapi-host: XYZ",                 "x-rapidapi-key: ABc"             ],         ]);          $  response = curl_exec($  curl);         $  err = curl_error($  curl);          curl_close($  curl);          if ($  err) {             echo "cURL Error #:" . $  err;         } else {             echo $  response;         }     }                           /**          * generate_after_main_content hook.          *          * @since 0.1          */         do_action( 'generate_after_main_content' );         ?>         </form>     </main> </div>  <?php /**  * generate_after_primary_content_area hook.  *  * @since 2.0  */ do_action( 'generate_after_primary_content_area' );  generate_construct_sidebars();  get_footer(); 

When I click on Submit button, it gives ‘Page not Found’.

What function can I use to determine new user registration?

I have created a function that sends a message to members. I would like this function to fire only if the user has just registered.

function send_message_to_new_member() {     // If user has just created account    if( is_new_user() ) { //is_new_user() doesn't exist, so how can I go about this?            // Do something     } } add_action( 'woocommerce_order_status_completed', 'send_message_to_new_member', 2 ); 

Registration will take place at the Woocommerce checkout… not sure is the method of registration is different there compared to standard WordPress registration?

how to script out database users and permissions in all user databases in the instance

Can anyone help please?

I would like to use Steve Kusen’s script at https://www.sqlservercentral.com/forums/topic/script-db-level-permissions/page/4/#post-1954202

to loop through all the user databases automatically, using Aaron Bertrand’s sp_ineachdb. Has anyone got this to work? Kindly advise on how to do it please.

Thank you

Is it possible to set permission to other user for the table created by current user with PostgreSQL?

In PostgreSQL, created these 2 roles and grant different permissions to them.

create user user1 with login; create role operator; grant operator to user1;  create user user2 with login; create role readwrite; grant readwrite to user2; 

When created a table by user1, such as table1, user2 can’t use this table. It got permission denied.

Is it the right feature for PostgreSQL? If it is, how to make the table also can be used for user2?

Alter user in Postgres and change the ownership of the user to amended user

I am doing an audit and amending usernames in our postgres database (9.6) environment.

I can amend the user to a new username via the ALTER USER name RENAME TO new_name command however I want to also amend the ownership of the user on any objects they may have to the new renamed user.

If I rename the user I am then unable to make the ownership change as the old username would no longer exist.

Is there a way round this? or would it simply be easier to create a brand new username and move the ownership to the new username and then delete the old username.

Thanks

Short code to modify the user profile from the frontend

I am trying to pass a template that I found here to a short code to display on a page on the frontend.

Now now I have the following:

// profile action hook - catches form submission and acts accordingly add_action('init','profile_form_submission'); function profile_form_submission() {      /* Get user info. */     global $  current_user, $  wp_roles;     //get_currentuserinfo(); //deprecated since 3.1      /* Load the registration file. */     //require_once( ABSPATH . WPINC . '/registration.php' ); //deprecated since 3.1     $  error = array();         /* If profile was saved, update profile. */     if ( 'POST' == $  _SERVER['REQUEST_METHOD'] && !empty( $  _POST['action'] ) && $  _POST['action'] == 'update-user' ) {          /* Update user password. */         if ( !empty($  _POST['pass1'] ) && !empty( $  _POST['pass2'] ) ) {         if ( $  _POST['pass1'] == $  _POST['pass2'] )             wp_update_user( array( 'ID' => $  current_user->ID, 'user_pass' => esc_attr( $  _POST['pass1'] ) ) );         else             $  error[] = __('Las contraseñas no son iguales, por lo tanto, no fueron actualizadas.', 'profile');         }          /* Update user information. */         if ( !empty( $  _POST['url'] ) )         wp_update_user( array( 'ID' => $  current_user->ID, 'user_url' => esc_url( $  _POST['url'] ) ) );         if ( !empty( $  _POST['email'] ) ){         if (!is_email(esc_attr( $  _POST['email'] )))             $  error[] = __('Este email no es valido, pruebe otra vez.', 'profile');         elseif(email_exists(esc_attr( $  _POST['email'] )) != $  current_user->id )             $  error[] = __('Este email ya esta en uso por otro usuario, pruebe con otro.', 'profile');         else{             wp_update_user( array ('ID' => $  current_user->ID, 'user_email' => esc_attr( $  _POST['email'] )));         }         }           /* Redirect so the page will show updated info.*/       /*I am not Author of this Code- i dont know why but it worked for me after changing below line to if ( count($  error) == 0 ){ */         if ( count($  error) == 0 ) {         //action hook for plugins and extra fields saving         do_action('edit_user_profile_update', $  current_user->ID);         wp_redirect( get_permalink() );         exit;         }     } }  // shows login form (or a message, if user already logged in) function get_profile_customers_form($  redirect) {             if ( !is_user_logged_in() ) {         $  return = .__('Tienes que estar logueado para modificar esta pagina.', 'profile');             else {                 if ( count($  error) > 0 ) echo '<p class="error">' . implode("<br />", $  error) . '</p>';                 <form method="post" id="adduser" action="<?php the_permalink(); ?>">                     <p class="form-email">                         <label for="email"><?php _e('E-mail *', 'profile'); ?></label>                         <input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $  current_user->ID ); ?>" />                     </p><!-- .form-email -->                     <p class="form-password">                         <label for="pass1"><?php _e('Contraseña *', 'profile'); ?> </label>                         <input class="text-input" name="pass1" type="password" id="pass1" />                     </p><!-- .form-password -->                     <p class="form-password">                         <label for="pass2"><?php _e('Confirmar *', 'profile'); ?></label>                         <input class="text-input" name="pass2" type="password" id="pass2" />                     </p><!-- .form-password -->                      <?php                          //action hook for plugin and extra fields                         do_action('edit_user_profile',$  current_user);                      ?>                     <p class="form-submit">                         <?php echo $  referer; ?>                         <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Actualizar cuenta', 'profile'); ?>" />                         <?php wp_nonce_field( 'update-user' ) ?>                         <input name="action" type="hidden" id="action" value="update-user" />                     </p><!-- .form-submit -->                 </form><!-- #adduser -->    }  // adds a handy [profile_form_submission] shortcode to use in posts/pages add_shortcode('profile_form_submission','profile_form_submission_shortcode'); function vr_login_shortcode ($  atts,$  content=false) {   $  atts = shortcode_atts(array(     'redirect' => home_url()   ), $  atts);   return get_profile_customers_form($  atts['redirect']); } 

I don’t know how to do the part of the code that the form shows. It is from "// shows login form (or a message, if user already logged in)".

The original code that I am trying to adapt was the following:

    <?php if ( !is_user_logged_in() ) : ?>             <p class="warning">                 <?php _e('Tienes que estar logueado para modificar esta pagina.', 'profile'); ?>             </p><!-- .warning -->     <?php else : ?>         <?php if ( count($  error) > 0 ) echo '<p class="error">' . implode("<br />", $  error) . '</p>'; ?>         <form method="post" id="adduser" action="<?php the_permalink(); ?>">             <p class="form-email">                 <label for="email"><?php _e('E-mail *', '<br />', 'profile'); ?></label>                 <input class="text-input" name="email" type="text" id="email" value="<?php the_author_meta( 'user_email', $  current_user->ID ); ?>" />             </p><!-- .form-email -->             <p class="form-password">                 <label for="pass1"><?php _e('Contraseña *',"<br>", 'profile'); ?> </label>                 <input class="text-input" name="pass1" type="password" id="pass1" />             </p><!-- .form-password -->             <p class="form-password">                 <label for="pass2"><?php _e('Confirmar *',"<br>", 'profile'); ?></label>                 <input class="text-input" name="pass2" type="password" id="pass2" />             </p><!-- .form-password -->              <?php                  //action hook for plugin and extra fields                 do_action('edit_user_profile',$  current_user);              ?>             <p class="form-submit">                 <?php echo $  referer; ?>                 <input name="updateuser" type="submit" id="updateuser" class="submit button" value="<?php _e('Actualizar cuenta', 'profile'); ?>" />                 <?php wp_nonce_field( 'update-user' ) ?>                 <input name="action" type="hidden" id="action" value="update-user" />             </p><!-- .form-submit -->         </form><!-- #adduser -->