added message payments in admin menu

This commit is contained in:
asus
2024-03-27 17:18:14 +01:00
parent a0018c903b
commit dd0d4dfbeb
13 changed files with 229 additions and 34 deletions

View File

@@ -14,16 +14,32 @@ if (!defined('ABSPATH')) {
* return the result
*
*/
function return_result($output) {
if (is_array($output) && count($output) === 0) {
$output = '';
function return_result($output, $if_empty = '') {
/*
* if empty, apply options, or default empty string ''
*
*/
if (empty($output)) {
$output = $if_empty;
}
/*
* if number, output a string
*
*/
if (is_numeric($output)) {
$output = (string)$output;
}
if (!is_string($output)) {
/*
* if not scalar, stringify output
*
*/
if (!is_scalar($output)) {
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
}
return esc_html($output);
}
@@ -32,7 +48,7 @@ function return_result($output) {
* format the output
* if is acf, use acf default format
*/
function format_user_info($query, $current_user, $user_id) {
function format_user_info($query, $current_user, $user_id, $if_empty = '') {
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
$is_acf = false;
@@ -75,10 +91,12 @@ function format_user_info($query, $current_user, $user_id) {
* otherwise, use the default wordpress value
*
*/
if ($is_acf)
if ($is_acf) {
$output = get_field($query, $acf_id);
else
}
else {
$output = $current_user->$query;
}
@@ -86,8 +104,9 @@ function format_user_info($query, $current_user, $user_id) {
* try to extract a string
*
*/
while (is_array($output) && count($output) === 1)
while (is_array($output) && count($output) === 1) {
$output = reset($output);
}
@@ -110,7 +129,12 @@ function format_user_info($query, $current_user, $user_id) {
}
}
return \CUSTER\return_result($output);
/*
* check options to format the result
*
*/
return \CUSTER\return_result($output, $if_empty);
}

View File

@@ -72,6 +72,7 @@ function output_list_front($array, $current_user, $user_id) {
* - [custer_user_info user_email id='author'] -> display the email of the creator of the page/post
* - [custer_user_info user_email id='logged_in' important] -> display the email of the connected user, even if surrounded by shortcode 'custer_change_id'
* important keyword has no effect if id='author'
* - [custer_user_info user_email if_empty="value"] -> display 'value' if the user_email is empty or does not exist
*
*/
function current_user_infos($atts) {
@@ -86,12 +87,14 @@ function current_user_infos($atts) {
$id_is = 'logged_in';
*/
$id_is = 'author';
$if_empty = '';
/*
* has parameter 'id' ?
* has parameter important ?
* if yes, removes them from $atts
* has parameter if_empty ?
* if yes, handle them and removes them from $atts
*
*/
if (is_array($atts)) {
@@ -106,6 +109,10 @@ function current_user_infos($atts) {
unset($atts[$key]);
}
}
if (isset($atts['if_empty'])) {
$if_empty = $atts['if_empty'];
unset($atts['if_empty']);
}
}
@@ -175,7 +182,7 @@ function current_user_infos($atts) {
$query = $atts;
else
return '';
return \CUSTER\format_user_info($query, $current_user, $user_id);
return \CUSTER\format_user_info($query, $current_user, $user_id, $if_empty);
}
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');