updated filter email to filter the author page special keyword

This commit is contained in:
asus
2024-03-07 19:03:42 +01:00
parent 31c3ed55f4
commit 4916defcaa
4 changed files with 55 additions and 29 deletions

View File

@@ -14,8 +14,6 @@ function restrict_author_page_CIPF() {
if (!is_author())
return;
error_log("in restrict_author_page_CIPF");
$can_access = false;
if (current_user_can('administrator')) {
$can_access = true;

View File

@@ -11,25 +11,68 @@ if (!defined('ABSPATH')) {
/*
* callback to provide the user info corresponding to the $$key_word$$
*
*/
function replace_words_CIPF($matches, $user_id = null) {
if ($user_id !== null) {
$current_user = get_user_by('id', $user_id);
}
else if (is_user_logged_in()) {
$current_user = wp_get_current_user();
}
else {
return "";
}
if ($current_user === false)
return "";
$query = $matches[1];
$result = $current_user->$query;
/*
* if result is array, take the first element (not ideal)
*
*/
if (is_array($result))
$result = reset($result);
/*
* if is special query __author_page__
* return author page url
*
*/
if ($querry === '__page_author__') {
$current_user_id = get_current_user_id();
$result = get_author_posts_url($current_user_id);
}
/*
* if no match, return $$<query>$$
*
*/
if (empty($result))
return $matches[0];
return $result;
}
/*
* filter emails in the form-builder hook, before the wp_mail hook
* it receives the id of the user, no need to have the user still logged-in
*
*/
function filter_email_fb_CIPF($reply_body, $post_array) {
$id = $post_array['ID'];
// pattern : anything surrounded by '$$', ex : $$value$$
$pattern = '/\$\$(.*?)\$\$/';
// old version, using an outside callback, better readibility but cannot pass $id
//$new_body = preg_replace_callback($pattern, 'replace_words_CIPF', $reply_body);
// inline callback, with 'use' to get the id
$new_body = preg_replace_callback($pattern, function($matches) use ($id) {
$current_user = get_user_by('id', $id);
$query = $matches[1];
$result = $current_user->$query;
return $result;
return replace_words_CIPF($matches, $id);
}, $reply_body);
return $new_body;
@@ -38,18 +81,9 @@ add_filter('df_confirmation_body', 'filter_email_fb_CIPF', 10, 2); // the receiv
add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the administrator receive a notification
/*
* callback to provide the user info corresponding to the $$key_word$$
*/
function replace_words_CIPF($matches) {
error_log("in replace_words_CIPF");
if (!is_user_logged_in())
return "";
$current_user = wp_get_current_user();
$query = $matches[1];
$result = $current_user->$query;
return $result;
}
/*
* filter emails at the final point : the wp_mail hook
* it uses a callback that rely on the logged-in user

View File

@@ -15,19 +15,15 @@ function handle_prof_is_activ_CIPF($author_id) {
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
error_log("in handle_prof_is_activ_CIPF");
$acf_id = 'user_' . $author_id;
/*
* if prof is activ, do nothing more
*
*/
error_log("is activ ?");
$is_activ = get_field($acf_prof_is_activ, $acf_id);
if ($is_activ === 'Actif')
return;
error_log("...is inactiv");
/*
@@ -48,8 +44,6 @@ error_log("in handle_prof_is_activ_CIPF");
*
*/
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
error_log("redirection_prof_inactiv");
error_log($redirection_prof_inactiv);
wp_redirect($redirection_prof_inactiv);
exit;
@@ -65,7 +59,6 @@ function check_prof_page_CIPF() {
// is an author page
if (!is_author())
return;
error_log("in check_prof_page_CIPF");
// the way to find the id of the author of an author_page
$author_id = get_queried_object_id();

View File

@@ -186,7 +186,8 @@ function current_user_infos_CIPF($atts) {
if (!empty($wp_query->posts))
$user_id = $wp_query->posts[0]->post_author;
}
$current_user = new WP_User($user_id);
//$current_user = new WP_User($user_id);
$current_user = get_user_by('id', $user_id);
}
/*