- 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

@@ -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();
}