From 90fb5bc0b639af33bbdf88a2a83f21d588bd6d05 Mon Sep 17 00:00:00 2001 From: asus Date: Mon, 25 Mar 2024 21:42:33 +0100 Subject: [PATCH] custer v 0.1.6 added special request for post url --- plugins/cipf_plugin/php/redirections.php | 1 - plugins/custer/custer.php | 2 +- plugins/custer/filter_mail.php | 9 ++++-- plugins/custer/format_user_infos.php | 38 ++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/plugins/cipf_plugin/php/redirections.php b/plugins/cipf_plugin/php/redirections.php index 215b7b8..606390f 100644 --- a/plugins/cipf_plugin/php/redirections.php +++ b/plugins/cipf_plugin/php/redirections.php @@ -99,7 +99,6 @@ function redirection_profil_CIPF(){ } else { $query = reset($posts); - $post_id = $query->ID; $redirect_url = get_permalink($query->ID); } wp_redirect($redirect_url, 301); diff --git a/plugins/custer/custer.php b/plugins/custer/custer.php index 1b3fc4b..417f597 100644 --- a/plugins/custer/custer.php +++ b/plugins/custer/custer.php @@ -4,7 +4,7 @@ Plugin Name: custer_plugin Plugin URI: Description: customize user : output infos on page, on email, and change current user id momentarly Author: hugogogo -Version: 0.1.5 +Version: 0.1.6 Author URI: */ diff --git a/plugins/custer/filter_mail.php b/plugins/custer/filter_mail.php index 713ab39..6c8f8fb 100644 --- a/plugins/custer/filter_mail.php +++ b/plugins/custer/filter_mail.php @@ -28,8 +28,9 @@ function replace_words($matches, $user_id = null) { return ""; } - if ($current_user === false) + if ($current_user === false) { return ""; + } $query = $matches[1]; $result = \CUSTER\format_user_info($query, $current_user, $user_id); @@ -38,15 +39,17 @@ function replace_words($matches, $user_id = null) { * if result is array, take the first element (not ideal) * */ - if (is_array($result)) + if (is_array($result)) { $result = reset($result); + } /* * if no match, return $$$$ * */ - if (empty($result)) + if (empty($result)) { return $matches[0]; + } return $result; } diff --git a/plugins/custer/format_user_infos.php b/plugins/custer/format_user_infos.php index 8c948db..28a2410 100644 --- a/plugins/custer/format_user_infos.php +++ b/plugins/custer/format_user_infos.php @@ -49,6 +49,17 @@ function format_user_info($query, &$current_user, $user_id) { } + /* + * if is special query __user_post__ + * return author page url + * + */ + if ($query === '__user_post__') { + $output = \CUSTER\find_user_post_url($user_id); + return \CUSTER\return_result($output); + } + + /* * check if it's an acf field * @@ -104,4 +115,31 @@ function format_user_info($query, &$current_user, $user_id) { +/* +* find the posts of the user and return the first one +* +*/ +function find_user_post_url($user_id) { + $user_post_url = ''; + + $args = array( + 'post_type' => 'post', + 'author' => $user_id, + 'posts_per_page' => 1, + ); + $posts = get_posts($args); + + if (empty($posts)) { + $user_post_url = ''; + } + else { + $query = reset($posts); + $user_post_url = get_permalink($query->ID); + } + + return $user_post_url; +} + + + ?>