custer v 0.1.6 added special request for post url
This commit is contained in:
@@ -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:
|
||||
*/
|
||||
|
||||
|
||||
@@ -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 $$<query>$$
|
||||
*
|
||||
*/
|
||||
if (empty($result))
|
||||
if (empty($result)) {
|
||||
return $matches[0];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user