updated filter email to filter the author page special keyword
This commit is contained in:
@@ -14,8 +14,6 @@ function restrict_author_page_CIPF() {
|
|||||||
if (!is_author())
|
if (!is_author())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
error_log("in restrict_author_page_CIPF");
|
|
||||||
|
|
||||||
$can_access = false;
|
$can_access = false;
|
||||||
if (current_user_can('administrator')) {
|
if (current_user_can('administrator')) {
|
||||||
$can_access = true;
|
$can_access = true;
|
||||||
|
|||||||
@@ -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
|
* 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
|
* 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) {
|
function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||||
$id = $post_array['ID'];
|
$id = $post_array['ID'];
|
||||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||||
$pattern = '/\$\$(.*?)\$\$/';
|
$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
|
// inline callback, with 'use' to get the id
|
||||||
$new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
$new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
||||||
$current_user = get_user_by('id', $id);
|
return replace_words_CIPF($matches, $id);
|
||||||
$query = $matches[1];
|
|
||||||
$result = $current_user->$query;
|
|
||||||
return $result;
|
|
||||||
}, $reply_body);
|
}, $reply_body);
|
||||||
|
|
||||||
return $new_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
|
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
|
* filter emails at the final point : the wp_mail hook
|
||||||
* it uses a callback that rely on the logged-in user
|
* it uses a callback that rely on the logged-in user
|
||||||
|
|||||||
@@ -15,19 +15,15 @@ function handle_prof_is_activ_CIPF($author_id) {
|
|||||||
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
|
||||||
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
|
||||||
|
|
||||||
error_log("in handle_prof_is_activ_CIPF");
|
|
||||||
|
|
||||||
$acf_id = 'user_' . $author_id;
|
$acf_id = 'user_' . $author_id;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if prof is activ, do nothing more
|
* if prof is activ, do nothing more
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
error_log("is activ ?");
|
|
||||||
$is_activ = get_field($acf_prof_is_activ, $acf_id);
|
$is_activ = get_field($acf_prof_is_activ, $acf_id);
|
||||||
if ($is_activ === 'Actif')
|
if ($is_activ === 'Actif')
|
||||||
return;
|
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;
|
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
|
||||||
error_log("redirection_prof_inactiv");
|
|
||||||
error_log($redirection_prof_inactiv);
|
|
||||||
|
|
||||||
wp_redirect($redirection_prof_inactiv);
|
wp_redirect($redirection_prof_inactiv);
|
||||||
exit;
|
exit;
|
||||||
@@ -65,7 +59,6 @@ function check_prof_page_CIPF() {
|
|||||||
// is an author page
|
// is an author page
|
||||||
if (!is_author())
|
if (!is_author())
|
||||||
return;
|
return;
|
||||||
error_log("in check_prof_page_CIPF");
|
|
||||||
|
|
||||||
// the way to find the id of the author of an author_page
|
// the way to find the id of the author of an author_page
|
||||||
$author_id = get_queried_object_id();
|
$author_id = get_queried_object_id();
|
||||||
|
|||||||
@@ -186,7 +186,8 @@ function current_user_infos_CIPF($atts) {
|
|||||||
if (!empty($wp_query->posts))
|
if (!empty($wp_query->posts))
|
||||||
$user_id = $wp_query->posts[0]->post_author;
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user