- most prof states shoud be ok
- redirection partner page creation - user ids on checks states - reset cgv - restrict prof profil page
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function restrict_author_page_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
* if user->role is found in array of allowed role, no redirection needed
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* get_queried_object_id() would work too
|
||||
* here get_the_author_meta works and is more explicit
|
||||
*
|
||||
$author_id = get_queried_object_id();
|
||||
*/
|
||||
$author_id = get_the_author_meta( 'ID' );
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($current_user_id != $author_id) {
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect(home_url(), 301);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action('template_redirect', 'restrict_author_page_CIPF', 10);
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -17,8 +17,23 @@ if (!defined('ABSPATH')) {
|
||||
function hide_admin_bar_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
|
||||
if (!current_user_can($role_admin) && !is_admin()) {
|
||||
|
||||
/*
|
||||
* is admin page
|
||||
*
|
||||
*/
|
||||
if (is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* if
|
||||
*
|
||||
*/
|
||||
if (!current_user_can($role_admin)) {
|
||||
show_admin_bar(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,18 +17,17 @@ if (!defined('ABSPATH')) {
|
||||
*/
|
||||
function prof_after_form_CIPF($form_id, $post_array, $form_type) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
$acf_account_state = PLGNTLS_class::ACF_ACCOUNT_STATE;
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
$acf_id = 'user_'.$user_id;
|
||||
//$user_id = get_current_user_id();
|
||||
$user_id = $post_array['ID'];
|
||||
|
||||
|
||||
/*
|
||||
* reset cgv
|
||||
*
|
||||
*/
|
||||
update_field($acf_cgv['_name'], array(""), $acf_id);
|
||||
reset_acf_cgv_CIPF($user_id);
|
||||
|
||||
|
||||
/*
|
||||
@@ -39,20 +38,20 @@ function prof_after_form_CIPF($form_id, $post_array, $form_type) {
|
||||
* if transfert $ valid card : 'waiting_valid'
|
||||
*
|
||||
*/
|
||||
if (is_payment_method_paypal_CIPF()) {
|
||||
if (is_account_new_CIPF()) {
|
||||
set_account_to_pay_CIPF();
|
||||
if (is_payment_method_paypal_CIPF($user_id)) {
|
||||
if (is_account_new_CIPF($user_id)) {
|
||||
set_account_to_pay_CIPF($user_id);
|
||||
}
|
||||
if (is_account_expired_CIPF()) {
|
||||
set_account_to_pay_CIPF();
|
||||
if (is_account_expired_CIPF($user_id)) {
|
||||
set_account_to_pay_CIPF($user_id);
|
||||
}
|
||||
}
|
||||
else if (is_payment_method_transfert_CIPF()) {
|
||||
if (is_account_expired_CIPF()) {
|
||||
set_account_waiting_invalid_CIPF();
|
||||
else if (is_payment_method_transfert_CIPF($user_id)) {
|
||||
if (is_account_expired_CIPF($user_id)) {
|
||||
set_account_waiting_invalid_CIPF($user_id);
|
||||
}
|
||||
else if (is_account_valid_CIPF()) {
|
||||
set_account_waiting_valid_CIPF();
|
||||
else if (is_account_valid_CIPF($user_id)) {
|
||||
set_account_waiting_valid_CIPF($user_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,98 +60,34 @@ add_action('df_after_process', 'prof_after_form_CIPF', 10, 3);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* on renew page :
|
||||
* - check restrictions
|
||||
* - change some acf fields (if access granted)
|
||||
*
|
||||
* prevent users to fill the renew form if :
|
||||
* - they are not prof and logged in,
|
||||
* - and if their card is not in renewable state
|
||||
* - except admins and editor
|
||||
* redirections
|
||||
*
|
||||
*/
|
||||
function prof_form_restrictions_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
$base_url = home_url();
|
||||
|
||||
wp_reset_query();
|
||||
|
||||
if (!is_page('commande'))
|
||||
if (!is_page($slug_renew_card))
|
||||
return;
|
||||
|
||||
/*
|
||||
* is it good ?
|
||||
* -> dont' redirect if user not logged in, because new users need to acces this page
|
||||
*
|
||||
if (!is_user_logged_in()) {
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect($base_url, 301);
|
||||
exit;
|
||||
}
|
||||
*/
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
$current_user = wp_get_current_user();
|
||||
$acf_id = 'user_'.$current_user_id;
|
||||
// redirections here
|
||||
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
*
|
||||
$allowed_roles = array($role_admin, $role_fipf, $role_prof);
|
||||
if (!array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
* if prof, check card state
|
||||
* if cannot renew, redirect
|
||||
*
|
||||
if (current_user_can($role_prof)) {
|
||||
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
||||
if ($can_renew === false) {
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||
wp_redirect($redirect_url, 301);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
add_action('template_redirect', 'prof_form_restrictions_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* enqueue scripts and styles on page prof
|
||||
*
|
||||
* on the renew card page for prof
|
||||
* output the right message, depending of the status of the card
|
||||
* 'renouveler' or 'commander'
|
||||
*
|
||||
* #cipf_prof_carte_commande -> default display: block;
|
||||
* #cipf_prof_carte_renouvellement -> default display: none;
|
||||
*
|
||||
*/
|
||||
function renew_page_filter_message_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$acf_card_state = PLGNTLS_class::ACF_CARD_STATE;
|
||||
|
||||
if (!is_page($slug_renew_card))
|
||||
return;
|
||||
|
||||
@@ -10,104 +10,6 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
|
||||
|
||||
//function handle_prof_is_activ_CIPF($author_id) {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
// $slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
||||
//
|
||||
// $acf_id = 'user_' . $author_id;
|
||||
//
|
||||
// /*
|
||||
// * if prof is activ, do nothing more
|
||||
// *
|
||||
// */
|
||||
// $is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||
// if ($is_activ === $acf_prof_is_activ['activ'])
|
||||
// return;
|
||||
//
|
||||
//
|
||||
// /*
|
||||
// * else if prof inactiv
|
||||
// * if is admin or other allowed roles, see the page anyway
|
||||
// * no need to handle allowed roles, it's already
|
||||
// * taken care by author_restriction.php
|
||||
// *
|
||||
// */
|
||||
// $user_id = get_current_user_id();
|
||||
// if ($user_id !== $author_id)
|
||||
// return;
|
||||
//
|
||||
//
|
||||
// /*
|
||||
// * if prof is activ
|
||||
// * redirect to waiting page
|
||||
// *
|
||||
// $redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
||||
//
|
||||
// // Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
// nocache_headers();
|
||||
// wp_redirect($redirection_prof_inactiv, 301);
|
||||
// exit;
|
||||
// */
|
||||
//}
|
||||
|
||||
|
||||
/*
|
||||
* check acf field payment_status
|
||||
* if field value is 'success'
|
||||
* - show block 'failure'
|
||||
* - and update field to 'nothing', so it will not show next time
|
||||
* if field value is 'failure'
|
||||
* - show bloc success
|
||||
* - and update field to 'nothing', so it will not show next time
|
||||
* if field value is 'nothing'
|
||||
* - do nothing (keep blocs hidden)
|
||||
* if field value is 'started'
|
||||
* - do nothing (keep blocs hidden)
|
||||
*
|
||||
* .cipf_prof_paiement_message -> on row, added display none in page css
|
||||
* #cipf_prof_paiement_reussi -> on row
|
||||
* #cipf_prof_paiement_echoue -> on row
|
||||
*
|
||||
*/
|
||||
//function show_prof_paiement_messages_CIPF($user_id) {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||
// $acf_payment_status = PLGNTLS_class::ACF_CARD_PAYMENT_STATE;
|
||||
//
|
||||
// $acf_id = 'user_' . $user_id;
|
||||
//
|
||||
// /*
|
||||
// * if prof is inactive, do nothing more
|
||||
// *
|
||||
// */
|
||||
// $is_activ = get_field($acf_prof_is_activ['_name'], $acf_id);
|
||||
// if (is_null($is_activ))
|
||||
// return;
|
||||
// if (empty($is_activ))
|
||||
// return;
|
||||
// if ($is_activ === $acf_prof_is_activ['activ'])
|
||||
// return;
|
||||
//
|
||||
// $cipf_prof_payement = new PLGNTLS_class();
|
||||
//
|
||||
// $payement_status = get_field($acf_payment_status['_name'], $acf_id);
|
||||
// if ($payement_status === $acf_payment_status['success']) {
|
||||
// $cipf_prof_payement->add_to_front(array(
|
||||
// array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_reussi {display: block;}' )
|
||||
// ));
|
||||
// }
|
||||
// else if ($payement_status === $acf_payment_status['failure']) {
|
||||
// $cipf_prof_payement->add_to_front(array(
|
||||
// array( 'css' => '.cipf_prof_paiement_message#cipf_prof_paiement_echoue {display: block;}' )
|
||||
// ));
|
||||
// }
|
||||
//
|
||||
// update_field($acf_payment_status['_name'], $acf_payment_status['nothing'], $acf_id);
|
||||
//}
|
||||
|
||||
|
||||
/*
|
||||
* early checks on profil page
|
||||
*
|
||||
@@ -128,13 +30,13 @@ function prof_profil_check_CIPF() {
|
||||
* also check for waiting transfert : valid -> invalid
|
||||
*
|
||||
*/
|
||||
if (card_date_exists_CIPF()) {
|
||||
if (is_card_date_expired_CIPF()) {
|
||||
if (!is_account_expired_CIPF()) {
|
||||
set_account_expired_CIPF();
|
||||
if (card_date_exists_CIPF($author_id)) {
|
||||
if (is_card_date_expired_CIPF($author_id)) {
|
||||
if (!is_account_expired_CIPF($author_id)) {
|
||||
set_account_expired_CIPF($author_id);
|
||||
}
|
||||
if (is_account_waiting_valid_CIPF()) {
|
||||
set_account_waiting_invalid_CIPF();
|
||||
if (is_account_waiting_valid_CIPF($author_id)) {
|
||||
set_account_waiting_invalid_CIPF($author_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,6 +52,8 @@ add_action('wp', 'prof_profil_check_CIPF', 11);
|
||||
*/
|
||||
function prof_profil_redirects_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
// is an author page
|
||||
if (!is_author())
|
||||
@@ -158,7 +62,35 @@ function prof_profil_redirects_CIPF() {
|
||||
// the way to find the id of the author of an author_page
|
||||
$author_id = get_queried_object_id();
|
||||
|
||||
// redirections here
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
* if user->role is found in array of allowed role, no redirection needed
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* both 'get_queried_object_id' and 'get_the_author_meta' works here,
|
||||
* i don't knwo why it's not alwasy the case :
|
||||
*
|
||||
$author_id = get_the_author_meta( 'ID' );
|
||||
*/
|
||||
$author_id = get_queried_object_id();
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
/*
|
||||
* if connected user is not author, get out
|
||||
*
|
||||
*/
|
||||
if ($current_user_id != $author_id) {
|
||||
redirection_profil_CIPF();
|
||||
}
|
||||
|
||||
}
|
||||
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
||||
|
||||
@@ -38,6 +38,9 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
* [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok]
|
||||
*
|
||||
* [ ] cgv
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
@@ -315,9 +318,8 @@ function set_payment_nothing_CIPF($user_id = null) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* numero de carte
|
||||
*
|
||||
*/
|
||||
function set_card_number_CIPF($user_id = null) {
|
||||
@@ -336,4 +338,23 @@ function set_card_number_CIPF($user_id = null) {
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* cgv
|
||||
*
|
||||
*/
|
||||
function reset_acf_cgv_CIPF($user_id = null) {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$acf_cgv = PLGNTLS_class::ACF_PROF_CGV;
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
update_field($acf_cgv['_name'], array(""), $acf_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -103,4 +103,7 @@ add_action('template_redirect', 'redirection_page_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user