Hi Brajesh,
1- Ok, Old code “Plugin Name: BuddyPress Featured Member Expirable Membership Addon” in https://pastebin.com/13kNA2x8
I made a code that can not work.
You say that only one thing can work!
I do not know if it is possible (or not) to have a duration according to the field xprofile (“I am”) and / or (paypal paypal / your button “”I will retranslate* in non real code, the initial wish
If no payment (OR press button “SET Featured”)
If roleWp = member1 and xprofile (“Je suis”) = ‘Femme’ => duration 24 days
If roleWp = member1 and xprofile (“Je suis”) = ‘Homme’ => duration 12 days
If roleWp = member0 and xprofile (“Je suis”) = ‘Femme’ => duration 16 days
If roleWp = member0 and xprofile (“Je suis”) = ‘Homme’ => duration 08 days
If payment
If roleWp = member1 and xprofile (“Je suis”) = ‘Femme’ => duration 40 days
If roleWp = member1 and xprofile (“Je suis”) = ‘Homme’ => duration 20 days
If roleWp = member0 and xprofile (“Je suis”) = ‘Femme’ => duration 30 days
If roleWp = member0 and xprofile (“Je suis”) = ‘Homme’ => duration 15 daysRegards
* ************************************
$nbr_jour_a_la_une='0'; $field_jesuis = '23'; //57 $user_id = bp_loggedin_user_id(); $jesuis = xprofile_get_field_data($field_jesuis,$user_id ); $user_info = get_userdata($user_id); $user_roles = isset($user_info->roles)?$user_info->roles:array(); $meta_paie = get_user_meta( $user_id, _paid_featured , true); if ($meta_paie=='1'){ // utilisateur payant if ( ($jesuis=='Une femme') AND (in_array('membre1', $user_roles)) ){$nbr_jour_a_la_une='0.04'; $varHD.='Attendu2: 0.04 ';} if ( ($jesuis=='Une femme') AND (in_array('membre0', $user_roles)) ){$nbr_jour_a_la_une='0.03'; $varHD.='Attendu2: 0.03 ';} if ( ($jesuis=='Un homme') AND (in_array('membre1', $user_roles)) ){$nbr_jour_a_la_une='0.02'; $varHD.='Attendu2: 0.02 ';} if ( ($jesuis=='Un homme') AND (in_array('membre0', $user_roles)) ){$nbr_jour_a_la_une='0.01'; $varHD.='Attendu2: 0.01 ';} update_user_meta( $user_id, '_paid_featured', 0 ); // remise à 0 meta disant que le membre ne paye plus , mis à 1 dans fonction si paiement } else { if ( ($jesuis=='Une femme') AND (in_array('membre1', $user_roles)) ){$nbr_jour_a_la_une='4'; } // si membre de base ET une femme $user->has_cap('membre0') if ( ($jesuis=='Une femme') AND (in_array('membre0', $user_roles)) ){$nbr_jour_a_la_une='3'; } // si membre de base ET une femme $user->has_cap('membre0') if ( ($jesuis=='Un homme') AND (in_array('membre1', $user_roles)) ){$nbr_jour_a_la_une='2'; } // si membre de base ET une femme $user->has_cap('membre0') if ( ($jesuis=='Un homme') AND (in_array('membre0', $user_roles)) ){$nbr_jour_a_la_une='1'; } // si membre de base ET une femme $user->has_cap('membre0') }
Hi Herve,
Thank you.1. You should keep this from your old code.
add_action( 'super_after_paypal_ipn_payment_verified', 'ajout_membre_a_la_une_apres_paiement' ); function ajout_membre_a_la_une_apres_paiement($data){ $custom = explode('|', $data['post']['custom']); $form_id = $custom[0]; $user_id = $custom[3]; if( $form_id==112 ) { bp_featured_members()->add_user($user_id); update_user_meta( $custom[3], '_paid_featured', 1 ); } }
The top section before class and replace everything else with the new code.
Thank you for clarification.
It seems to me that you will need two different interval methods depending on whether a user is paid or not.
We will need to update the code again to have the 2 situations. I will share the function in next 2 days.
Thank you
BrajeshHi Brajesh,
I replaced your code as you told me.
I replaced by$map = array( 'membre0' => 1, // 60 days 'membre0' => 1, 'author' => 30, 'contributor' => 20, 'subscriber' => 5, );
See the complete file https://pastebin.com/naWV91sH
“Set featured” was done after paypal payment
At the end of the programmed time (1 day), it is not removed
I do not have an error message except
“PHP Warning: mysqli_real_connect (): (HY000 / 2002): Connection timed out in /home/xxx/-AM.88h.ovh/wp-includes/wp-db.php on line 1538”
A priori not related to your code because appears before!
An idea ?
To speed up the resolution, I will want to do tests with short times.
What is the minimum amount of time I can put? I know there is one but I do not remember which one.
Can I put 0.1 days or 0.01 days?
RegardsHi Herve,
Do you have access to phpmyadmin? If yes, Can you please check in the wp_usermeta(or yourprefix_usermeta) table that “_bpfm_featured_expiry_time” is set and has some value?Also, Install cron control plugin and check if the cron job is scheduled.
For smaller interval, you can use the multiplcation factor as MINUTE_IN_SECONDS instead of HOUR_IN_SECONDS
Regards
BrajeshHi Brajesh,
I did 2 other tests. the members stay “set featured”
I have many values (cf phpmyadmin)
I put that in your function and I refreshed the page regularly (normally it should work)
Do you want admin access?
Regards***
private function get_role_based_interval( $user_id ) { $default = 10; // 10 days by default? A MODIF $user = get_user_by( 'id', $user_id ); if ( empty( $user ) ) { return $default * MINUTE_IN_SECONDS; //DAY_IN_SECONDS } $user_roles = $user->roles; if ( empty( $user_roles ) ) { return $default * MINUTE_IN_SECONDS; //DAY_IN_SECONDS } // Map role to days. $map = array( 'membre0' => 2, // 60 days 'membre1' => 3, 'author' => 30, 'contributor' => 20, 'subscriber' => 5, ); $allowed_days = 0; // 0 days. // calculate the max allowed days. foreach ( $user_roles as $role ) { if ( isset( $map[ $role ] ) && $map[ $role ] > $allowed_days ) { $allowed_days = $map[ $role ]; } } // if no user role has mapped value. if ( ! $allowed_days ) { $allowed_days = $default; } return $allowed_days * MINUTE_IN_SECONDS; //DAY_IN_SECONDS
Hi Herve,
I will need admin as well as phpmyadmin details to check if the changes are being saved in the database or not.
Please share the details and I will look into it.
Regards
BrajeshHello Brajesh,
It worked by testing on 2 members with different roles 🙂
sorry, I thought I activated the plugin 🙁
Only problem is that I have a 404 error systematically if I go to the http://wptest-am.88h.ovh/tableau-de-bord-membres/ page
Can this be related to your program? because it worked well before!
I do not have a message in the logs.
I momentarily solve the problem by saving the permalinks againNot urgent, but as you have the memory now, do not hesitate if you can advance on the improvement of 2 desires
(cf https://buddydev.com/support/forums/topic/paiement-with-featured-member/page/5/#post-18599)
Thank you
HervéHi Herve,
Thank you for confirming that my update was working.I have checked and the 404 is not due to my code. You should check and see if you have the page on the site.
Also, what is the second desire? using member type for time?
Regards
BrajeshHi Brajesh,
that’s what I said in https://buddydev.com/support/forums/topic/paiement-with-featured-member/page/5/#post-18596The idea says otherwise if it’s not too difficult to have a different expiration time (also depends on the value of a field)
a) if the administrator press the “set featured” button
b) in the case of payment by paypalis that clearer ?
Regards- This reply was modified 6 years, 1 month ago by Hervé.
Please add it at the bottom of the code
/** * Get time interval when a user is marked featured via payment. * * @param int $user_id use id. * * @return int */ function bpfm_paypal_get_role_based_interval( $user_id ) { $default = 10; // 10 days by default? $user = get_user_by( 'id', $user_id ); if ( empty( $user ) ) { return $default * DAY_IN_SECONDS; } $user_roles = $user->roles; if ( empty( $user_roles ) ) { return $default * DAY_IN_SECONDS; } // Map role to days. $map = array( 'administrator' => 60, // 60 days 'editor' => 40, 'author' => 30, 'contributor' => 20, 'subscriber' => 5, ); $allowed_days = 0; // 0 days. // calculate the max allowed days. foreach ( $user_roles as $role ) { if ( isset( $map[ $role ] ) && $map[ $role ] > $allowed_days ) { $allowed_days = $map[ $role ]; } } // if no user role has mapped value. if ( ! $allowed_days ) { $allowed_days = $default; } return $allowed_days * DAY_IN_SECONDS; }
Now look for this line(I(t is your code)
update_user_meta( $custom[3], '_paid_featured', 1 );
Just after that line, please add another line
update_user_meta( $custom[3], '_bpfm_featured_expiry_time', time() + bpfm_paypal_get_role_based_interval( $custom[3] ) );
That will do it.
Regards
Brajesh
The topic ‘ [Resolved] paiement with featured Member’ is closed to new replies.