- wip filter page prof

- upgraded user info shortcode to default behavior on author page
This commit is contained in:
asus
2024-03-07 17:05:55 +01:00
parent b244b59deb
commit d65af4cd43
6 changed files with 73 additions and 43 deletions

View File

@@ -1,5 +1,13 @@
<?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() {

View File

@@ -1,14 +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!');
}
?>

View File

@@ -1,5 +1,13 @@
<?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!');
}

View File

@@ -1,24 +1,43 @@
<?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 check_prof_page_CIPF() {
//add_action('template_redirect', 'is_prof_activ_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();
// is_prof_activ_CIPF($author_id);
}
add_action('init', 'check_prof_page_CIPF');
add_action('template_redirect', 'check_prof_page_CIPF');
function is_prof_activ_CIPF() {
function is_prof_activ_CIPF($author_id) {
$acf_prof_is_activ = PLGNTLS_class::ACF_PROF_IS_ACTIV;
$slug_wait_activation = PLGNTLS_class::SLUG_PROF_INACTIV;
//$current_user = wp_get_current_user();
$user_id = get_current_user_id();
$acf_id = 'user_' . $user_id;
//$user_id = get_current_user_id();
//$acf_id = 'user_' . $user_id;
$acf_id = 'user_' . $author_id;
error_log("is activ ?");
$is_activ = get_field($acf_prof_is_activ, $acf_id);
if (!empty($is_activ))
if ($is_activ === 'Actif')
return;
error_log("...is inactiv");
$redirection_prof_inactiv = home_url() . '/' . $slug_wait_activation;
error_log("redirection_prof_inactiv");
@@ -31,4 +50,3 @@ function is_prof_activ_CIPF() {
?>

View File

@@ -1,5 +1,13 @@
<?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 reset_some_fields_CIPF($form_id, $user_id, $post_array) {

View File

@@ -117,45 +117,42 @@ function format_user_info_CIPF($output, $query, &$current_user, $user_id) {
/*
* shortcode to write user info of the logged in user
* shortcode to write user info of post author
* 0 or 1 argument, usage :
* - [cipf_user_info] -> list of all availables infos
* - [cipf_user_info user_email] -> display the email
* - [cipf_user_info user_email user_login] -> display the email
* - [cipf_user_info user_email author] -> display the email of the author of the page/post instead of the connected user
* - [cipf_user_info] -> list of all availables infos
* - [cipf_user_info user_email] -> display the email
* - [cipf_user_info user_email user_login] -> display the email
* - [cipf_user_info user_email author='logged_in'] -> display the email of the connected user
* - [cipf_user_info user_email author='post_creator'] -> display the email of the creator of the page/post
*
*/
function current_user_infos_CIPF($atts) {
if (!is_user_logged_in())
return ;
error_log("--atts");
error_log(json_encode($atts));
$current_user = wp_get_current_user();
$user_id = get_current_user_id();
/*
* choose the default id target : logged in user, or post creator ?
*
$author_is = 'logged_in'; // logged in user
*/
$author_is = 'post_creator'; // creator of post (also for author pages)
/*
* has parameter 'author' ?
* if yes, removes it from $atts
*
*/
$has_author = false;
if (is_array($atts)) {
$needle_key = array_search('author', $atts);
if ($needle_key !== false) {
unset($atts[$needle_key]);
$has_author = true;
}
}
else {
if ($atts === 'author') {
$atts = '';
$has_author = true;
$author = $atts['author'];
if (isset($author)) {
$author_is = $author;
unset($atts['author']);
}
}
error_log(json_encode($atts));
/*
* should output all or a specific parameter ?
*
@@ -166,11 +163,16 @@ function current_user_infos_CIPF($atts) {
else if (count($atts) === 0)
$output_all = true;
/*
* get author id outside loop and outside singular page : https://wordpress.stackexchange.com/q/65548
*
*/
if ($has_author) {
if ($author_is === 'logged_in') {
$current_user = wp_get_current_user();
$user_id = get_current_user_id();
}
else {
if (is_author()) {
$user_id = get_queried_object_id();
}