custer : changed namespace, now all function use it
This commit is contained in:
@@ -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/register_partenaires.php');
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/redirections.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/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/prof_check_page.php');
|
||||||
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
include_once(PLGNTLS_class::root_path() . 'php/renew_card.php');
|
||||||
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
//include_once(PLGNTLS_class::root_path() . 'php/reset_card_form.php');
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
//namespace CUSTER;
|
namespace CUSTER;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* it means someone outside wp is accessing the file, in this case kill it.
|
* it means someone outside wp is accessing the file, in this case kill it.
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function shortcode_change_id($options) {
|
|||||||
|
|
||||||
|
|
||||||
if ($option === 'author') {
|
if ($option === 'author') {
|
||||||
$id = get_author_id();
|
$id = \CUSTER\get_author_id();
|
||||||
Custer::set_current_user_backup();
|
Custer::set_current_user_backup();
|
||||||
wp_set_current_user($id);
|
wp_set_current_user($id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ function replace_words($matches, $user_id = null) {
|
|||||||
return "";
|
return "";
|
||||||
|
|
||||||
$query = $matches[1];
|
$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)
|
* 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))
|
if (is_array($result))
|
||||||
$result = reset($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>$$
|
* if no match, return $$<query>$$
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -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) {
|
function format_user_info($query, &$current_user, $user_id) {
|
||||||
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
|
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
|
||||||
|
|
||||||
$is_acf = false;
|
$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
|
* check if it's an acf field, and a date
|
||||||
* second method : check what get_field_object() returns
|
* second method : check what get_field_object() returns
|
||||||
@@ -67,21 +94,9 @@ function format_user_info($query, &$current_user, $user_id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return \CUSTER\return_result($output);
|
||||||
|
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -21,14 +21,14 @@ function extract_if_array_size_one($value) {
|
|||||||
function merge_two_arrays($array1, $array2) {
|
function merge_two_arrays($array1, $array2) {
|
||||||
$new_array = $array1;
|
$new_array = $array1;
|
||||||
foreach ($array2 as $key2 => $value2) {
|
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 key was not in first array, add the new element to it
|
||||||
if (!isset($new_array[$key2])) {
|
if (!isset($new_array[$key2])) {
|
||||||
$new_array[$key2] = $value2;
|
$new_array[$key2] = $value2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// if key was in first array, add both in an array
|
// 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))
|
if (empty($value1))
|
||||||
$new_array[$key2] = $value2;
|
$new_array[$key2] = $value2;
|
||||||
else if (empty($value2))
|
else if (empty($value2))
|
||||||
@@ -47,7 +47,7 @@ function output_list_front($array, $current_user, $user_id) {
|
|||||||
foreach ($array as $key => $value) {
|
foreach ($array as $key => $value) {
|
||||||
if (str_starts_with($key, '_'))
|
if (str_starts_with($key, '_'))
|
||||||
continue ;
|
continue ;
|
||||||
$value = format_user_info($key, $current_user, $user_id);
|
$value = \CUSTER\format_user_info($key, $current_user, $user_id);
|
||||||
$output .= '<li>';
|
$output .= '<li>';
|
||||||
$output .= '<span>';
|
$output .= '<span>';
|
||||||
$output .= $key;
|
$output .= $key;
|
||||||
@@ -158,8 +158,8 @@ function current_user_infos($atts) {
|
|||||||
if ($output_all) {
|
if ($output_all) {
|
||||||
$user_properties = (array) get_userdata($user_id)->data;
|
$user_properties = (array) get_userdata($user_id)->data;
|
||||||
$user_metas = get_user_meta($user_id);
|
$user_metas = get_user_meta($user_id);
|
||||||
$user_infos = merge_two_arrays($user_metas, $user_properties);
|
$user_infos = \CUSTER\merge_two_arrays($user_metas, $user_properties);
|
||||||
return output_list_front($user_infos, $current_user, $user_id);
|
return \CUSTER\output_list_front($user_infos, $current_user, $user_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ function current_user_infos($atts) {
|
|||||||
$query = $atts;
|
$query = $atts;
|
||||||
else
|
else
|
||||||
return '';
|
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');
|
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user