created plugin custer, and removed shortcodes change_id and user_infos from cipf plugin
This commit is contained in:
87
plugins/custer/format_user_infos.php
Normal file
87
plugins/custer/format_user_infos.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
namespace CUSTER;
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function format_user_info($query, &$current_user, $user_id) {
|
||||
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
|
||||
|
||||
$is_acf = false;
|
||||
|
||||
|
||||
/*
|
||||
* check if it's an acf field, and a date
|
||||
* second method : check what get_field_object() returns
|
||||
*
|
||||
*/
|
||||
$acf_id = 'user_'.$user_id;
|
||||
$acf_object = get_field_object($query, $acf_id);
|
||||
if ($acf_object !== false)
|
||||
$is_acf = true;
|
||||
|
||||
|
||||
/*
|
||||
* if is acf, use the acf return format
|
||||
* otherwise, use the default wordpress value
|
||||
*
|
||||
*/
|
||||
if ($is_acf)
|
||||
$output = get_field($query, $acf_id);
|
||||
else
|
||||
$output = $current_user->$query;
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* try to extract a string
|
||||
*
|
||||
*/
|
||||
while (is_array($output) && count($output) === 1)
|
||||
$output = reset($output);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* if is not acf
|
||||
* check if is a date
|
||||
* and format it
|
||||
* to create a DateTime from a time stamp : https://stackoverflow.com/a/12039058/9497573
|
||||
*
|
||||
*/
|
||||
if (!$is_acf) {
|
||||
$timestamp = false;
|
||||
if (is_string($output)) {
|
||||
$timestamp = strtotime($output);
|
||||
}
|
||||
if ($timestamp !== false) {
|
||||
$date = new DateTime('@' . $timestamp);
|
||||
$output = $date->format($output_date_format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user