custer : changed namespace, now all function use it

This commit is contained in:
asus
2024-03-17 14:06:25 +01:00
parent fc41f7d36b
commit 70d8998a3f
6 changed files with 38 additions and 33 deletions

View File

@@ -42,7 +42,7 @@ include_once(PLGNTLS_class::root_path() . '/php/hide_admin.php');
include_once(PLGNTLS_class::root_path() . 'php/register_partenaires.php');
include_once(PLGNTLS_class::root_path() . 'php/redirections.php');
include_once(PLGNTLS_class::root_path() . 'php/author_restriction.php');
include_once(PLGNTLS_class::root_path() . 'php/filter_mail.php');
//include_once(PLGNTLS_class::root_path() . 'php/filter_mail.php');
include_once(PLGNTLS_class::root_path() . 'php/prof_check_page.php');
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');

View File

@@ -1,5 +1,5 @@
<?php
//namespace CUSTER;
namespace CUSTER;
/*
* it means someone outside wp is accessing the file, in this case kill it.

View File

@@ -39,7 +39,7 @@ function shortcode_change_id($options) {
if ($option === 'author') {
$id = get_author_id();
$id = \CUSTER\get_author_id();
Custer::set_current_user_backup();
wp_set_current_user($id);
}

View File

@@ -32,7 +32,7 @@ function replace_words($matches, $user_id = null) {
return "";
$query = $matches[1];
$result = format_user_info($query, $current_user, $user_id);
$result = \CUSTER\format_user_info($query, $current_user, $user_id);
/*
* if result is array, take the first element (not ideal)
@@ -41,16 +41,6 @@ function replace_words($matches, $user_id = null) {
if (is_array($result))
$result = reset($result);
/*
* if is special query __author_page__
* return author page url
*
*/
if ($query === '__author_page__') {
$current_user_id = get_current_user_id();
$result = get_author_posts_url($current_user_id);
}
/*
* if no match, return $$<query>$$
*

View File

@@ -10,13 +10,40 @@ if (!defined('ABSPATH')) {
/*
* return the result
*
*/
function return_result($output) {
if (is_array($output) && count($output) === 0)
$output = '';
if (!is_string($output))
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
return esc_html($output);
}
/*
* format the output
* if is acf, use acf default format
*/
function format_user_info($query, &$current_user, $user_id) {
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
$is_acf = false;
/*
* if is special query __author_page__
* return author page url
*
*/
if ($query === '__author_page__') {
$output = get_author_posts_url($user_id);
return \CUSTER\return_result($output);
}
/*
* check if it's an acf field, and a date
* second method : check what get_field_object() returns
@@ -67,21 +94,9 @@ function format_user_info($query, &$current_user, $user_id) {
}
}
/*
* return the result
*
*/
if (is_array($output) && count($output) === 0)
$output = '';
if (!is_string($output))
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
return esc_html($output);
return \CUSTER\return_result($output);
}
?>

View File

@@ -21,14 +21,14 @@ function extract_if_array_size_one($value) {
function merge_two_arrays($array1, $array2) {
$new_array = $array1;
foreach ($array2 as $key2 => $value2) {
$value = extract_if_array_size_one($value2);
$value = \CUSTER\extract_if_array_size_one($value2);
// if key was not in first array, add the new element to it
if (!isset($new_array[$key2])) {
$new_array[$key2] = $value2;
continue;
}
// if key was in first array, add both in an array
$value1 = extract_if_array_size_one($new_array[$key2]);
$value1 = \CUSTER\extract_if_array_size_one($new_array[$key2]);
if (empty($value1))
$new_array[$key2] = $value2;
else if (empty($value2))
@@ -47,7 +47,7 @@ function output_list_front($array, $current_user, $user_id) {
foreach ($array as $key => $value) {
if (str_starts_with($key, '_'))
continue ;
$value = format_user_info($key, $current_user, $user_id);
$value = \CUSTER\format_user_info($key, $current_user, $user_id);
$output .= '<li>';
$output .= '<span>';
$output .= $key;
@@ -158,8 +158,8 @@ function current_user_infos($atts) {
if ($output_all) {
$user_properties = (array) get_userdata($user_id)->data;
$user_metas = get_user_meta($user_id);
$user_infos = merge_two_arrays($user_metas, $user_properties);
return output_list_front($user_infos, $current_user, $user_id);
$user_infos = \CUSTER\merge_two_arrays($user_metas, $user_properties);
return \CUSTER\output_list_front($user_infos, $current_user, $user_id);
}
@@ -174,7 +174,7 @@ function current_user_infos($atts) {
$query = $atts;
else
return '';
return format_user_info($query, $current_user, $user_id);
return \CUSTER\format_user_info($query, $current_user, $user_id);
}
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');