custer v 0.1.6 added special request for post url

This commit is contained in:
asus
2024-03-25 21:42:33 +01:00
parent 44a5d93f77
commit 90fb5bc0b6
4 changed files with 45 additions and 5 deletions

View File

@@ -99,7 +99,6 @@ function redirection_profil_CIPF(){
} }
else { else {
$query = reset($posts); $query = reset($posts);
$post_id = $query->ID;
$redirect_url = get_permalink($query->ID); $redirect_url = get_permalink($query->ID);
} }
wp_redirect($redirect_url, 301); wp_redirect($redirect_url, 301);

View File

@@ -4,7 +4,7 @@ Plugin Name: custer_plugin
Plugin URI: Plugin URI:
Description: customize user : output infos on page, on email, and change current user id momentarly Description: customize user : output infos on page, on email, and change current user id momentarly
Author: hugogogo Author: hugogogo
Version: 0.1.5 Version: 0.1.6
Author URI: Author URI:
*/ */

View File

@@ -28,8 +28,9 @@ function replace_words($matches, $user_id = null) {
return ""; return "";
} }
if ($current_user === false) if ($current_user === false) {
return ""; return "";
}
$query = $matches[1]; $query = $matches[1];
$result = \CUSTER\format_user_info($query, $current_user, $user_id); $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 result is array, take the first element (not ideal)
* *
*/ */
if (is_array($result)) if (is_array($result)) {
$result = reset($result); $result = reset($result);
}
/* /*
* if no match, return $$<query>$$ * if no match, return $$<query>$$
* *
*/ */
if (empty($result)) if (empty($result)) {
return $matches[0]; return $matches[0];
}
return $result; return $result;
} }

View File

@@ -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 * 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;
}
?> ?>