replaced custer by a got module
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -4,3 +4,6 @@
|
||||
[submodule "wordpress_docker"]
|
||||
path = wordpress_docker
|
||||
url = git@bitbucket.org:hugogogo/docker_wordpress.git
|
||||
[submodule "plugins/custer"]
|
||||
path = plugins/custer
|
||||
url = git@bitbucket.org:hugogogo/2024_wordpres_plugin_custer.git
|
||||
|
||||
1
plugins/custer
Submodule
1
plugins/custer
Submodule
Submodule plugins/custer added at b551112094
@@ -1,74 +0,0 @@
|
||||
<style>
|
||||
#custer_notice_html_wrapper {
|
||||
margin: 15px 15px 15px 0px;
|
||||
#custer_notice_html {
|
||||
margin: 0px;
|
||||
<?php echo $option_notice['style']; ?>
|
||||
}
|
||||
}
|
||||
form.form_custer {
|
||||
margin: 50px 15px 15px 0px;
|
||||
border: 1px solid black;
|
||||
padding: 15px;
|
||||
details:not([open]) {
|
||||
summary {
|
||||
margin: 0px;
|
||||
}
|
||||
}
|
||||
details {
|
||||
summary {
|
||||
cursor: grab;
|
||||
h2 {
|
||||
display: inline;
|
||||
}
|
||||
}
|
||||
summary ~ * {
|
||||
margin-top: 20px;
|
||||
}
|
||||
label {
|
||||
display: block;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
textarea {
|
||||
resize: vertical;
|
||||
width: 100%;
|
||||
&.notice_style_custer {
|
||||
height: 120px;
|
||||
}
|
||||
&.notice_html_custer {
|
||||
height: 500px;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
|
||||
|
||||
<div id="custer_notice_html_wrapper">
|
||||
<div id="custer_notice_html">
|
||||
<?php echo wp_unslash($option_notice['html']); ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (current_user_can('administrator')) { ?>
|
||||
<?php echo Plgntls_custer::open_form_option($option_notice['_name'], 'POST', 'form_custer'); ?>
|
||||
<details class="">
|
||||
<summary><h2>modifier ce mode d'emplois :</h2></summary>
|
||||
|
||||
<div>
|
||||
<label for="<?php echo esc_html(stripslashes($option_notice['_name'])); ?>_modify_style_custer">style : </label>
|
||||
<textarea class="notice_style_custer" id="<?php echo esc_html(stripslashes($option_notice['_name'])); ?>_modify_style_custer" name="style"><?php echo esc_html(stripslashes($option_notice['style'])); ?></textarea>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label for="<?php echo esc_html(stripslashes($option_notice['_name'])); ?>_modify_html_custer">html : </label>
|
||||
<textarea class="notice_html_custer" id="<?php echo esc_html(stripslashes($option_notice['_name'])); ?>_modify_html_custer" name="html"><?php echo esc_html(stripslashes($option_notice['html'])); ?></textarea>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="send"/>
|
||||
</details>
|
||||
|
||||
</form>
|
||||
<?php } ?>
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* creates the plugin menu
|
||||
*
|
||||
*/
|
||||
function add_plugin_menu() {
|
||||
\Plgntls_custer::add_menu(__NAMESPACE__.'\menu_content');
|
||||
}
|
||||
add_action('admin_menu', __NAMESPACE__.'\add_plugin_menu');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* the construction of the admin menu page
|
||||
*
|
||||
*/
|
||||
function menu_content() {
|
||||
$option_notice_object = Custer::OPTION_NOTICE;
|
||||
|
||||
//delete_option($option_notice_object['_name']);
|
||||
$option_notice = \Plgntls_custer::get_option_safe($option_notice_object, true);
|
||||
|
||||
ob_start();
|
||||
include(\Plgntls_custer::root_path() . 'admin_menu.html');
|
||||
echo ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,147 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* change the current user to the author id of the current object
|
||||
* the only option is to force the author
|
||||
* -> there is no sens in forcing the logged_in, because it's already the default
|
||||
*
|
||||
* [custer_author_id] -> give current user the id of author
|
||||
* [custer_author_id off] -> reset to logged_in
|
||||
*
|
||||
* ! anchors not workink for the moment
|
||||
* //[custer_author_id set_anchor='anchor_name'] -> create anchor for author user
|
||||
* //[custer_author_id anchor='anchor_name'] -> give current user the id stored in the anchor_name
|
||||
*
|
||||
*/
|
||||
function shortcode_author_id($options) {
|
||||
$anchor_name = '';
|
||||
$option = '';
|
||||
$is_set_anchor = false;
|
||||
|
||||
|
||||
/*
|
||||
* set option value :
|
||||
* 'off', 'author', 'set_anchor', or 'anchor'
|
||||
*
|
||||
*/
|
||||
if (empty($options)) {
|
||||
$option = 'author';
|
||||
}
|
||||
if (isset($options['set_anchor'])) {
|
||||
$option = 'author';
|
||||
// $is_set_anchor = true;
|
||||
// $anchor_name = $options['set_anchor'];
|
||||
// if (empty($anchor_name)) {
|
||||
// return;
|
||||
// }
|
||||
unset($options['set_anchor']);
|
||||
}
|
||||
if (isset($options['anchor'])) {
|
||||
// if ($is_set_anchor) {
|
||||
// return;
|
||||
// }
|
||||
// $option = 'anchor';
|
||||
// $anchor_name = $options['anchor'];
|
||||
// if (empty($anchor_name)) {
|
||||
// return;
|
||||
// }
|
||||
unset($options['anchor']);
|
||||
}
|
||||
if (is_array($options) && in_array('off', $options)) {
|
||||
$option = 'off';
|
||||
}
|
||||
|
||||
if (empty($option)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* find id according to option
|
||||
* if option is set_anchor, it sets it and return 0
|
||||
*
|
||||
*/
|
||||
$id = \CUSTER\find_id_wih_option($option, $anchor_name);
|
||||
if ($id === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* set current user
|
||||
*
|
||||
*/
|
||||
if ($is_set_anchor) {
|
||||
\CUSTER\create_anchor($anchor_name, $id);
|
||||
}
|
||||
else {
|
||||
wp_set_current_user($id);
|
||||
}
|
||||
}
|
||||
add_shortcode('custer_author_id', __NAMESPACE__.'\shortcode_author_id');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function create_anchor($anchor_name, $id) {
|
||||
$option_anchor = Custer::OPTION_ANCHOR;
|
||||
|
||||
/*
|
||||
* if needed, create the option
|
||||
*
|
||||
*/
|
||||
if (false === get_option($option_anchor)) {
|
||||
add_option($option_anchor, array());
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* add or update the id for the anchor name
|
||||
*
|
||||
*/
|
||||
$anchors = get_option($option_anchor);
|
||||
$anchors[$anchor_name] = $id;
|
||||
update_option($option_anchor, $anchors);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find ids according to options :
|
||||
* - author : change the current user to the author of the page or post
|
||||
* - anchor : uses the id stored in options with anchor_name
|
||||
* - off : reset current user to the id before the changes
|
||||
*
|
||||
*/
|
||||
function find_id_wih_option($option, $anchor_name) {
|
||||
if ($option === 'author') {
|
||||
$id = \CUSTER\get_author_id();
|
||||
Custer::set_current_user_backup();
|
||||
}
|
||||
else if ($option === 'anchor') {
|
||||
$id = \CUSTER\get_anchor_id($anchor_name);
|
||||
Custer::set_current_user_backup();
|
||||
}
|
||||
else if ($option === 'off') {
|
||||
$id = Custer::reset_current_user_backup();
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
/*
|
||||
Plugin Name: hggg_custer
|
||||
Plugin URI:
|
||||
Description: customize user : output infos on page, on email, and change current user id momentarly
|
||||
Author: hugogogo
|
||||
Version: 0.2.6
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
include_once(plugin_dir_path(__FILE__) . '/plgntls_class.php');
|
||||
|
||||
include_once(Plgntls_custer::root_path() . 'custer_class.php');
|
||||
include_once(Plgntls_custer::root_path() . 'get_user_id.php');
|
||||
include_once(Plgntls_custer::root_path() . 'change_id.php');
|
||||
include_once(Plgntls_custer::root_path() . 'format_user_infos.php');
|
||||
include_once(Plgntls_custer::root_path() . 'user_infos.php');
|
||||
include_once(Plgntls_custer::root_path() . 'filter_mail.php');
|
||||
include_once(Plgntls_custer::root_path() . 'queries.php');
|
||||
|
||||
include_once(Plgntls_custer::root_path() . 'admin_menu.php');
|
||||
//include_once(Plgntls_custer::root_path() . 'admin_menu_toggle.php');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,423 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
class Custer {
|
||||
|
||||
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_custer', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
|
||||
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_custer', 'show'=>'show', 'hide'=>'hide'];
|
||||
const OPTION_NOTICE = [
|
||||
'_name'=>'notice_usage_custer',
|
||||
'_default' => [
|
||||
'style'=>
|
||||
'h1 {
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
h2 {
|
||||
margin-top: 50px;
|
||||
font-size: 1.5rem;
|
||||
border-bottom: 1px solid black;
|
||||
padding-bottom: 10px;
|
||||
}
|
||||
section {
|
||||
margin-left: 20px;
|
||||
}
|
||||
details {
|
||||
padding: 10px;
|
||||
}
|
||||
details.border {
|
||||
border: 1px solid black;
|
||||
}
|
||||
summary {
|
||||
cursor: grab;
|
||||
}
|
||||
summary:has(h2) {
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
summary > * {
|
||||
display: inline;
|
||||
}
|
||||
pre {
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
p, summary, pre, ul {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
ul {
|
||||
list-style-type: disc;
|
||||
list-style-position: outside;
|
||||
margin-left: 15px;
|
||||
}
|
||||
div:has(>ul) {
|
||||
border: 1px solid black;
|
||||
padding: 10px;
|
||||
}
|
||||
mark {
|
||||
background-color: lightgray;
|
||||
}
|
||||
div.example {
|
||||
border-left: 1px solid black;
|
||||
margin-left: 20px;
|
||||
padding-left: 10px;
|
||||
}
|
||||
.flex {
|
||||
display: flex;
|
||||
}
|
||||
.margin-right-10 {
|
||||
margin-right: 10px;
|
||||
}
|
||||
.margin-top-20 {
|
||||
margin-top: 20px;
|
||||
}',
|
||||
'html'=>
|
||||
'<h1>mode d\'emplois de custer</h1>
|
||||
|
||||
<details>
|
||||
<summary><h2>1. emails : <mark>$$mot-clé$$</mark></h2></summary>
|
||||
|
||||
<h3>1.1. mots-clés custer</h3>
|
||||
|
||||
<section>
|
||||
<p>dans les emails, aussi bien dans le message, que dans le sujet ou la personne destinataire, on peut utiliser un mot-clé custer.</p>
|
||||
<p>Qu\'est-ce que c\'est que ça ;) ?</p>
|
||||
<p>
|
||||
C\'est simplement un mot-clé écrit entre doubles dollars : <mark>$$mot-clé$$</mark><br>
|
||||
Lorsque un email contient ce schéma de mot entouré par des doubles dollars, il essaye de trouver la valeur associée à ce mot-clé.<br>
|
||||
Ces mots-clés correspondent en fait aux données que wordpress enregistre sur chaque personne.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<h3>1.2. trouver les mots-clés</h3>
|
||||
|
||||
<section>
|
||||
<p>Ce n\'est pas toujours facile de savoir les mots-clés qui sont disponibles, sans aller voir le code directement, donc voici un exemple de liste de mots-clés pour une utilisatrice fictive :</p>
|
||||
|
||||
<details class=\"border\">
|
||||
<summary>exemples de mots-clés et leur valeurs (la liste exacte peut dépendre de la personne, mais cet exemple contient les valeurs les plus communes)</summary>
|
||||
<pre>
|
||||
admin_color : fresh
|
||||
adresse_1 : 11 avenue Pauline
|
||||
adresse_2 :
|
||||
cgv : [\"\"]
|
||||
code_postal : 92700
|
||||
comment_shortcuts : false
|
||||
compte-actif : Actif
|
||||
description :
|
||||
dismissed_wp_pointers :
|
||||
display_name : AnneM
|
||||
email_asso : prez@asso.fr
|
||||
etablissement : École secondaire Waratinak
|
||||
etat_carte : Renouvellement
|
||||
etat_compte : carte valide
|
||||
etat_paiement : aucun
|
||||
etat_virement : [\"\"]
|
||||
fin_de_validite : 19/03/2094
|
||||
first_name : Anne
|
||||
fonction : Prof
|
||||
ID : 154
|
||||
image_test_ratio :
|
||||
justificatif : https://local-cipf-plugin.com/wp-content/uploads/de_fb_uploads/Attestation-1.pdf
|
||||
last_name : Martin
|
||||
livraison : Je préfère régler un supplément de 5 euros pour recevoir ma carte plastifiée
|
||||
locale :
|
||||
nickname : AnneM
|
||||
niveau_denseignement : Secondaire
|
||||
nom_asso : Mon asso
|
||||
numero_de_la_carte : 20240403154
|
||||
observations : J\'aime les bananes
|
||||
paiement : Paypal
|
||||
pays : Canada
|
||||
photo_du_profil : https://local-cipf-plugin.com/wp-content/uploads/de_fb_uploads/Exemple_profil.jpg
|
||||
president_asso : Le prez
|
||||
rich_editing : true
|
||||
session_tokens : {\"4003e23126f1697d7779ed03c9e45a70f2f6b34ce647a4507f573634d3c5469d\":{\"expiration\":1712437416,\"ip\":\"172.20.0.1\",\"ua\":\"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0\",\"login\":1712264616},\"0b63f8dbef4446bcf94af3f007df0595c8bc39095eea4c9c5042cdb066c3aeef\":{\"expiration\":1712479930,\"ip\":\"172.20.0.1\",\"ua\":\"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0\",\"login\":1712307130}}
|
||||
show_admin_bar_front : true
|
||||
somme_a_regler : 20
|
||||
syntax_highlighting : true
|
||||
tarif : Je suis hors réseau FIPF et je souhaite commander la carte à 15 €
|
||||
telephone :
|
||||
user_activation_key :
|
||||
user_email : temlevorku@gufum.com
|
||||
user_login : AnneM
|
||||
user_login(1) :
|
||||
user_nicename : annem
|
||||
user_pass : $P$BwMtApJkSSYdE38By6PcLbs3Xk9crj.
|
||||
user_registered : 14/03/2024
|
||||
user_status :
|
||||
user_url :
|
||||
use_ssl :
|
||||
ville : Colombes
|
||||
wp_503463_capabilities : 1
|
||||
wp_503463_user_level :
|
||||
xoo-el-password :
|
||||
xoo-el-rp-pass :
|
||||
xoo-el-rp-pass-again :
|
||||
xoo-el-sing-user :
|
||||
xoo-el-username :
|
||||
xoo_el_reg_email :
|
||||
xoo_el_reg_fname :
|
||||
xoo_el_reg_lname :
|
||||
xoo_el_reg_pass :
|
||||
xoo_el_reg_pass_again :
|
||||
xoo_el_reg_terms :
|
||||
xoo_el_reg_username :
|
||||
__admin_email__ : hugulumu@protonmail.com
|
||||
__author_page_url__ : https://local-cipf-plugin.com/author/annem/
|
||||
__base_url__ : https://local-cipf-plugin.com
|
||||
__user_post_url__ :
|
||||
</pre>
|
||||
</details>
|
||||
|
||||
<p>
|
||||
On peut remarquer que certains mot-clés sont sous la forme <strong>\'__mot_clé__\'</strong> avec deux doubles underscores avant et apres : "__"moit-clé"__"<br>
|
||||
Ce sont des mot-clés qui ne sont pas définis par worpdress de base, mais rajoutés par ce plugin (custer), plus d\'explication plus bas, dans la section suivante 1.3.
|
||||
</p>
|
||||
<p>Une méthode pour voir tous les mots-clés disponibles pour une personne connectée, c\'est d\'utiliser le shortcode <strong>[custer_user_info]</strong>, comme expliqué dans la partie 2 de ce mode d\'emplois.</p>
|
||||
</section>
|
||||
|
||||
<h3>1.3. mots-clés speciaux \'__mot_clé__\'</h3>
|
||||
|
||||
<section>
|
||||
<p>Certains mot-clés sont entourés par des doubles underscore : <strong>__mot_clé__</strong>, ce sont des mot-clés definis par custer, voici leur signification :</p>
|
||||
<ul>
|
||||
<li><strong>__admin_email__</strong> : l\'adresse email définie dans le menu \'Réglages\' > \'Général\' > \'Adresse e-mail d’administration\'</li>
|
||||
<li><strong>__author_page_url__</strong> : la page de profil de la personne connectée, appellée \'page auteur\' par wordpress (c\'est une page un peu speciale, qui ne peut pas être construite comme les autres pages, mais par le theme directement) -> ici elle sert pour les profs, c\'est leur page de profile</li>
|
||||
<li><strong>__user_post_url__</strong> : l\'adresse du plus récent article de la personne connectée -> ici ça correspond a la page de profil des partenaires, qui est construite comme un article, avec chaque partenaire n\'ayant droit qu\'à un seul article</li>
|
||||
<li><strong>__base_url__</strong> : l\'url de base du site, typiquement \'www.quelque-chose.com\'</li>
|
||||
</ul>
|
||||
<p></p>
|
||||
</section>
|
||||
|
||||
<h3>1.4. exemple dans un email</h3>
|
||||
|
||||
<section>
|
||||
<p>Un exemple d\'utilisation dans un email, avec les données de l\'exemple précédent :</p>
|
||||
<div>
|
||||
<ul>
|
||||
<li><strong>destinataire : </strong><mark>$$user_email$$</mark></li>
|
||||
<li><strong>sujet : </strong>compte de <mark>$$nickname$$</mark></li>
|
||||
<li><strong>message : </strong>Bonjour <mark>$$first_name$$</mark> <mark>$$last_name$$</mark>, votre carte numero <mark>$$numero_de_la_carte$$</mark> va bientot arriver a expiration, connectez-vous a votre compte pour la renouveler : <mark>$$__author_page_url__$$</mark></li>
|
||||
</ul>
|
||||
</div>
|
||||
<p>et une fois les mot-clés convertis, cet email devient :</p>
|
||||
<div>
|
||||
<ul>
|
||||
<li><strong>destinataire : </strong>temlevorku@gufum.com</li>
|
||||
<li><strong>sujet : </strong>compte de AnneM</li>
|
||||
<li><strong>message : </strong>Bonjour Anne Martin, votre carte numero 20240403154 va bientot arriver a expiration, connectez-vous a votre compte pour la renouveler : https://local-cipf-plugin.com/author/annem/</li>
|
||||
</ul>
|
||||
</div>
|
||||
</section>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<details>
|
||||
<summary><h2>2. shortcode : <mark>[custer_user_info mot-clé]</mark></h2></summary>
|
||||
|
||||
<h3>2.1. qu\'est-ce que c\'est ce shortcode</h3>
|
||||
|
||||
<section>
|
||||
<p>Les shortcodes sont des \'petits codes\' qu\'on peut ecrire sur les pages front de wordpress, et qui vont executer un code côté serveur, et souvent être remplacés par le resultat de ce code.</p>
|
||||
<p>C\'est à dire, plus concretement, qu\'on peut écrire un shortcode [mon-shortcode], et qu\'il se transformera en autre chose, par exemple \'salut\'.</p>
|
||||
<p>
|
||||
Le shortcode de custer s\'appelle \'custer_user_info\', et il permet de retrouver la valeur du mot-clé qu\'on lui donne, les mêmes mots-clés que décrits dans la partie 1 de ce mode d\'emplois, à propos des emails.<br>
|
||||
Cette fois-ci, au lieu d\'ecrire le mot-clé entre double dollars <mark>$$mot_clé$$</mark>, on l\'écrit dans le shortcode : <mark>[custer_user_info mot-clé]</mark>.
|
||||
</p>
|
||||
<p>
|
||||
Le shortcode de custer possède plus d\'options que le simple mot-clé des emails, elles sont décrites dans les sections suivantes.<br>
|
||||
Mais pourquoi utiliser un shortcode ET une version avec les doubles dollars ? Tout simplement parce que dans les emails les shortcodes ne marchent pas :)
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<h3>2.2. [custer_user_info]</h3>
|
||||
|
||||
<section>
|
||||
<p>En utilisant le shortcode seul, c\'est à dire uniquement avec son nom et sans aucun autre argument : <mark>[custer_user_info]</mark>, on obtient une liste de tous les mots-clés et leur valeur de quelqu\'un. De qui ? He bien, soit de la personne connectée, soit de la personne qui à ecrit la page, mais ce point est expliqué dans la section 2.4.</p>
|
||||
<p>C\'est cette méthode, le shortcode de base, qui a été utilisée pour obtenir la liste montrée plus haut dans la section email, et qui donne quelque chose comme :</p>
|
||||
<div class="flex">
|
||||
<p class="margin-right-10"><mark>[custer_user_info]</mark> --></p>
|
||||
<pre class="margin-top-20">
|
||||
display_name : AnneM
|
||||
etat_compte : carte valide
|
||||
fin_de_validite : 19/03/2094
|
||||
first_name : Anne
|
||||
fonction : Prof
|
||||
ID : 154
|
||||
nickname : AnneM
|
||||
...
|
||||
</pre>
|
||||
</div>
|
||||
<p>Ce n\'est pas prévu pour être vraiment utilisé sur le site finale, uniquement comme un outil pour voir les valeurs disponibles.</p>
|
||||
</section>
|
||||
|
||||
<h3>2.3. [custer_user_info mot-clé]</h3>
|
||||
|
||||
<section>
|
||||
<p>C\'est sous cette forme de base que le shortcode va fonctionner : afficher la valeur d\'un mot-clé.</p>
|
||||
<p>Par exemple, si la prof connectée s\'appelle AnneM sur le site, on peut obtenir ce surnom en ecrivant <mark>[custer_user_info nickname]</mark></p>
|
||||
<p>exemples :</p>
|
||||
<ul>
|
||||
<li><mark>[custer_user_info nickname]</mark> --> AnneM</li>
|
||||
<li><mark>[custer_user_info first-name]</mark> --> Anne</li>
|
||||
<li><mark>[custer_user_info fonction]</mark> --> Prof</li>
|
||||
</ul>
|
||||
<p>C\'est assez simple, cependant il y à un point important qui est expliqué dans la section suivante, c\'est de choisir de qui on affiche les infos.</p>
|
||||
</section>
|
||||
|
||||
<h3>2.4. [custer_user_info mot-clé id=status]</h3>
|
||||
|
||||
<section>
|
||||
<p>
|
||||
Il y a un petit piège dans la version de base du shortcode avec juste le mot-clé (<mark>[custer_user_info nickname]</mark>) :<br>
|
||||
on ne veut pas obligatoirement que s\'affiche les infos de la personne connectée.
|
||||
</p>
|
||||
<p>Comment ca ?</p>
|
||||
<p>
|
||||
En effet, par exemple sur une page de profil, si elle peut être vue par d\'autre personnes que simplement soi-même, alors on ne veut pas voir ses propres informations quand on va sur le profil de quelqu\'un d\'autre. Pourtant, si le shortcode affiche le nom de la personne connectée, on à beau visiter la page de quelqu\'un d\'autre, c\'est bien nous la personne connectée.<br>
|
||||
Généralement les pages de profils ne sont pas visibles publiquement, mais une personne avec les droits d\'administration peut y avoir accès, et rencontrer ce probleme.
|
||||
</p>
|
||||
<p>Le même probleme apparait, et de manière encore plus courante, sur un article : si on veut afficher le nom de la personne qui a écrit l\'article par exemple, on ne veut pas que ce soit le nom de la personne connectée qui s\'affiche, encore une fois !</p>
|
||||
<p>Donc, pour palier à ce probleme, le shortcode possede 2 status : la personne connectée, ou la personne autrice de la page.</p>
|
||||
<p>Et en fait, comme la plupart du temps ce qu\'on veut ce sont les infos de la personnes qui a crée la page, le shortcode est configuré par defaut pour afficher ces infos-la, et non pas les infos de la personne connectée. C\'est ça le piège ;)</p>
|
||||
<p>Donc, pour choisir si on veut la valeur de la personne connectée ou de la personne à qui appartient la page, on peut rajouter un argument : <strong>\'id\'</strong> qui peut avoir deux valeurs :</p>
|
||||
<ul>
|
||||
<li><strong>id=\'logged_in\'</strong> : l\'info affiché sera celle de la personne connectée</li>
|
||||
<li><strong>id=\'\'author</strong> (par défaut) : l\'info affichée sera celle de la personne ayant crée la page</li>
|
||||
</ul>
|
||||
<p>Exemple, je suis connecté en tant que hugogogo et je vais voir la page de profil de AnneM :</p>
|
||||
<ul>
|
||||
<li><mark>[custer_user_info nickname]</mark> -> AnneM</li>
|
||||
<li><mark>[custer_user_info nickname id=\'logged_in\']</mark> -> hugogogo</li>
|
||||
<li><mark>[custer_user_info nickname id=\'author\']</mark> -> AnneM</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<h3>2.5. [custer_user_info mot-clé if_empty=value]</h3>
|
||||
|
||||
<section>
|
||||
<p>Il y a un autre argument qu\'on peut rajouter à ce shortcode, c\'est la valeur qu\'on veut voir si le mot-clé ne trouve aucune valeur correspondante.</p>
|
||||
<p>En effet, si on demande la description d\'une personne par exemple, et qu\'elle n\'est pas remplie, le shortcode va juste retourner rien du tout, par defaut.</p>
|
||||
<p>Mais peut-etre qu\'on prefèrerait qu\'il affiche quelque chose comme \'description non-fournie\' ?</p>
|
||||
<p>Dans ce cas c\'est très simple, il suffit de le préciser dans l\'arguement <mark>if_empty=\'description non-fournie\'</marks> (ça fonctionne avec id=\'\' aussi)</p>
|
||||
<p>Exemples si Hugo visite la page d\'une personne qui n\'a pas de description, et la description de Hugo est "hugogogo est un rigolo" :</p>
|
||||
<ul>
|
||||
<li><mark>[custer_user_info description]</mark> -> </li>
|
||||
<li><mark>[custer_user_info description if_empty=\'pas de description\']</mark> -> pas de description</li>
|
||||
<li><mark>[custer_user_info description id=\'logged_in\']</mark> -> hugogogo est un rigolo</li>
|
||||
<li><mark>[custer_user_info description id=\'logged_in\' if_empty=\'pas de description\']</mark> -> hugogogo est un rigolo</li>
|
||||
<li><mark>[custer_user_info description id=\'author\' if_empty=\'pas de description\']</mark> -> pas de description</li>
|
||||
</ul>
|
||||
</section>
|
||||
</details>
|
||||
|
||||
|
||||
|
||||
<details>
|
||||
<summary><h2>3. shortcode : <mark>[custer_author_id]</mark></h2></summary>
|
||||
|
||||
<h3>3.1. qu\'est-ce que c\'est ce nouveau shortcode la ??</h3>
|
||||
|
||||
<section>
|
||||
<p>Celui-ci est très simple, il permet de changer momentanément la valeur de la personne connectée par celle de la personne autrice de la page.</p>
|
||||
<p>Pour bien comprendre, il faut d\'abord voir un exemple :</p>
|
||||
<p><strong>--> connecté en tant que hugogogo, visite la page de AnneM :</strong></p>
|
||||
<div class=\"example\">
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
<p>[custer_author_id]</p>
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
<p>[custer_author_id off]</p>
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
</div>
|
||||
<p>ce code va donner le resultat suivant :</p>
|
||||
<div class=\"example\">
|
||||
<p>vous êtes connecté-e en tant que : hugogogo</p>
|
||||
<p>vous êtes connecté-e en tant que : AnneM</p>
|
||||
<p>vous êtes connecté-e en tant que : hugogogo</p>
|
||||
</div>
|
||||
<p>Qu\'est-ce qui s\'est passé ?</p>
|
||||
<p>He bien en fait, lorsque le shortcode <mark>[custer_author_id]</mark> est ecrit, il modifie dans wordpress l\'information concernant la personne connectée, et il la rétablie lorsqu\'on ecrit le deuxième shortcode avec l\'argument \'off\' : <mark>[custer_author_id]</mark></p>
|
||||
<p>Mais attention ! Il modifie vraiment cette valeur pour tout wordpress, ce qui peut creer des problemes avec d\'autres éléments de la page, d\'autres plugins, d\'autres bout du thème, etc... Donc, il est recommandé de ne l\'utiliser que sur une courte portion de la page, pour un acte bien précis.</p>
|
||||
</section>
|
||||
|
||||
<h3>3.1. et pour finir, l\'argument \'important\'</h3>
|
||||
|
||||
<section>
|
||||
<p>Et ce n\'est pas tout :p Si par hasard, vous avez besoin d\'utiliser ce shortcode sur une portion de la page, et que dans cette portion vous avez quand-même besoin de récupérer une info sur la personne connectée avec le shortcode <mark>[custer_user_info mot-clé]</mark>, la vraie personne connectée, comment faire ? Il y a une solution, en ajoutant l\'argument <strong>important</strong> au shortcode. Exemple :</p>
|
||||
<p><strong>--> connecté en tant que hugogogo, visite la page de AnneM :</strong></p>
|
||||
<div class=\"example\">
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
<p>[custer_author_id]</p>
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\' important]</p>
|
||||
<p>[custer_author_id off]</p>
|
||||
<p>vous êtes connecté-e en tant que : [custer_user_info nickname id=\'logged_in\']</p>
|
||||
</div>
|
||||
<p>ce code va donner le resultat suivant :</p>
|
||||
<div class=\"example\">
|
||||
<p>vous êtes connecté-e en tant que : hugogogo</p>
|
||||
<p>vous êtes connecté-e en tant que : AnneM</p>
|
||||
<p>vous êtes connecté-e en tant que : hugogogo</p>
|
||||
<p>vous êtes connecté-e en tant que : hugogogo</p>
|
||||
</div>
|
||||
<p>On voit qu\'avec l\'argument <strong>important</strong> on retrouve la valeur de la vraie personne connectée</p>
|
||||
<p>À noter que cet argument <strong>important</strong> n\'a pas d\'impact utilisé avec l\'autre <strong>id</strong>, ou en dehors du shortcode <strong>custer_author_id</strong>.</p>
|
||||
|
||||
</details>',
|
||||
],
|
||||
];
|
||||
|
||||
const USER_INFO_DATE_FORMAT = 'd/m/Y'; // for user_infos.php (date format : https://www.php.net/manual/fr/datetime.format.php)
|
||||
const OPTION_ANCHOR = 'custer_anchor_ids';
|
||||
const QUERIES = [
|
||||
'__author_page_url__',
|
||||
'__user_post_url__',
|
||||
'__admin_email__',
|
||||
'__base_url__',
|
||||
];
|
||||
|
||||
private static $_backup_current_user = null;
|
||||
|
||||
|
||||
/*
|
||||
* setter and getter for current user backup
|
||||
*
|
||||
*/
|
||||
public static function set_current_user_backup() {
|
||||
if (self::$_backup_current_user !== null)
|
||||
return;
|
||||
self::$_backup_current_user = get_current_user_id();
|
||||
}
|
||||
public static function get_current_user_backup() {
|
||||
return self::$_backup_current_user;
|
||||
}
|
||||
public static function reset_current_user_backup() {
|
||||
$backup_user = self::$_backup_current_user;
|
||||
if ($backup_user === null) {
|
||||
$backup_user = get_current_user_id();
|
||||
}
|
||||
self::$_backup_current_user = null;
|
||||
return $backup_user;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,154 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* callback to provide the user info corresponding to the $$key_word$$
|
||||
*
|
||||
*/
|
||||
function replace_words($matches, $user_id = null) {
|
||||
if ($user_id !== null) {
|
||||
$current_user = get_user_by('id', $user_id);
|
||||
}
|
||||
else if (is_user_logged_in()) {
|
||||
$user_id = get_current_user_id();
|
||||
$current_user = wp_get_current_user();
|
||||
}
|
||||
|
||||
$query = $matches[1];
|
||||
$result = \CUSTER\format_user_info($query, $user_id);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* filter emails in the form-builder hook, before the wp_mail hook
|
||||
* it receives the id of the user, no need to have the user still logged-in
|
||||
*
|
||||
*/
|
||||
//function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||
// PLGNTLS_class::debug_infos();
|
||||
// $id = $post_array['ID'];
|
||||
// // pattern : anything surrounded by '$$', ex : $$value$$
|
||||
// $pattern = '/\$\$(.*?)\$\$/';
|
||||
//
|
||||
// // inline callback, with 'use' to get the id
|
||||
// $new_body = preg_replace_callback($pattern, function($matches) use ($id) {
|
||||
// return replace_words_CIPF($matches, $id);
|
||||
// }, $reply_body);
|
||||
//
|
||||
// return $new_body;
|
||||
//}
|
||||
//add_filter('df_confirmation_body', __NAMESPACE__.'\filter_email_fb_CIPF', 10, 2); // the receive an email
|
||||
//add_filter('df_notification_body', __NAMESPACE__.'\filter_email_fb_CIPF', 10, 2); // the admin receive a notification
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* filter emails at the final point : the wp_mail hook
|
||||
* it uses a callback that rely on the logged-in user
|
||||
* it will works well most of the time, but it's possible
|
||||
* that a user logged out before the email is sent
|
||||
* or event that a different user has already logged in
|
||||
*/
|
||||
function filter_email_wp($args) {
|
||||
// pattern : anything surrounded by '$$', ex : $$value$$
|
||||
$pattern = '/\$\$(.*?)\$\$/';
|
||||
|
||||
$user_id = \CUSTER\find_user_id_from_headers($args);
|
||||
|
||||
/*
|
||||
* loop through args
|
||||
* if one arg is itself an array, loop through it
|
||||
* and replace all $$words$$ by their values
|
||||
*
|
||||
*/
|
||||
foreach ($args as $arg_key => $arg) {
|
||||
if (is_array($arg)) {
|
||||
$new_arg = array();
|
||||
foreach ($arg as $key => $value) {
|
||||
$new_arg[$key] = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$new_arg = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $arg);
|
||||
}
|
||||
$args[$arg_key] = $new_arg;
|
||||
}
|
||||
|
||||
return $args;
|
||||
}
|
||||
add_filter('wp_mail', __NAMESPACE__.'\filter_email_wp', 10, 1);
|
||||
|
||||
|
||||
/*
|
||||
* add this filter specifically for the new users, since otherwise we would not have their id
|
||||
*
|
||||
*/
|
||||
function filter_regitration_email_CIPF($wp_new_user_notification_email, $user, $blogname) {
|
||||
$user_id = $user->ID;
|
||||
$pattern = '/\$\$(.*?)\$\$/';
|
||||
|
||||
$old_body = $wp_new_user_notification_email['message'];
|
||||
$new_body = preg_replace_callback($pattern, function($matches) use ($user_id) {
|
||||
return \CUSTER\replace_words($matches, $user_id);
|
||||
}, $old_body);
|
||||
$wp_new_user_notification_email['message'] = $new_body;
|
||||
|
||||
return $wp_new_user_notification_email;
|
||||
}
|
||||
add_filter('wp_new_user_notification_email', __NAMESPACE__.'\filter_regitration_email_CIPF', 22, 3);
|
||||
|
||||
|
||||
|
||||
|
||||
function find_user_id_from_headers(&$args) {
|
||||
if (empty($args)) {
|
||||
return null;
|
||||
}
|
||||
if (!isset($args['headers'])) {
|
||||
return null;
|
||||
}
|
||||
$headers = $args['headers'];
|
||||
if (empty($headers)) {
|
||||
return null;
|
||||
}
|
||||
if (!is_array($headers)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$user_id = null;
|
||||
|
||||
// isset returns false if the key exists but its value is null : 'user_id'=>null : https://stackoverflow.com/questions/3803282/check-if-value-isset-and-null
|
||||
if (array_key_exists('user_id', $headers)) {
|
||||
$user_id = $headers['user_id'];
|
||||
unset($headers['user_id']);
|
||||
$headers = array_values($headers);
|
||||
}
|
||||
|
||||
$args['headers'] = $headers;
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,145 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* return the result
|
||||
*
|
||||
*/
|
||||
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 not scalar, stringify output
|
||||
*
|
||||
*/
|
||||
if (!is_scalar($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, $user_id, $if_empty = '') {
|
||||
$output_date_format = Custer::USER_INFO_DATE_FORMAT;
|
||||
$special_queries = Custer::QUERIES;
|
||||
|
||||
$is_acf = false;
|
||||
|
||||
|
||||
/*
|
||||
* if is special query
|
||||
*
|
||||
*/
|
||||
if (in_array($query, $special_queries, true)) {
|
||||
$trimmed_query = trim($query, '_');
|
||||
$function_name = __NAMESPACE__.'\find_'.$trimmed_query;
|
||||
$output = $function_name($user_id);
|
||||
return \CUSTER\return_result($output, $if_empty);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* for the rest, we need the user
|
||||
*
|
||||
*/
|
||||
$current_user = get_user_by('id', $user_id);
|
||||
if (empty($current_user)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* check if it's an acf field
|
||||
*
|
||||
*/
|
||||
$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 single entity
|
||||
* for example : ["string"] -> "string"
|
||||
* or : ["", "string"] -> "string"
|
||||
*
|
||||
*/
|
||||
$output = \CUSTER\extract_smallest_entity($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);
|
||||
$date = date_create('@' . $timestamp);
|
||||
$output = $date->format($output_date_format);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* check options to format the result
|
||||
*
|
||||
*/
|
||||
return \CUSTER\return_result($output, $if_empty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,69 +0,0 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* get the current author id
|
||||
* return 0 if not found
|
||||
* get id outside loop : https://wordpress.stackexchange.com/q/65548
|
||||
*
|
||||
*/
|
||||
function get_author_id() {
|
||||
if (is_author()) {
|
||||
$user_id = get_queried_object_id();
|
||||
}
|
||||
else {
|
||||
$user_id = get_the_author_meta('ID');
|
||||
}
|
||||
|
||||
return $user_id;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* get the anker user id
|
||||
* return 0 if not found
|
||||
*
|
||||
*/
|
||||
//function get_anchor_id($anchor_name) {
|
||||
// $option_anchor = Custer::OPTION_ANCHOR;
|
||||
//error_log("anchor_name:");
|
||||
//error_log($anchor_name);
|
||||
//
|
||||
// $anchors = get_option($option_anchor);
|
||||
//error_log("anchors:");
|
||||
//error_log(json_encode($anchors));
|
||||
// if ($anchors === false) {
|
||||
//error_log("anchors === false");
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// if (isset($anchors[$anchor_name])) {
|
||||
// $user_id = $anchors[$anchor_name];
|
||||
// }
|
||||
//
|
||||
// if (empty($user_id)) {
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// return $user_id;
|
||||
//}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,94 +0,0 @@
|
||||
<?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 get_queries($user_id, $if_empty = '') {
|
||||
$special_queries = Custer::QUERIES;
|
||||
if (is_null($user_id)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$queries = array();
|
||||
foreach($special_queries as $query) {
|
||||
$queries[$query] = \CUSTER\format_user_info($query, $user_id, $if_empty);
|
||||
}
|
||||
return $queries;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function find_author_page_url($user_id) {
|
||||
if (is_null($user_id)) {
|
||||
return null;
|
||||
}
|
||||
return get_author_posts_url($user_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* find the posts of the user and return the first one
|
||||
*
|
||||
*/
|
||||
function find_user_post_url($user_id) {
|
||||
if (is_null($user_id)) {
|
||||
return null;
|
||||
}
|
||||
$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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function find_admin_email($user_id = null) {
|
||||
$admin_email = get_option( 'admin_email' );
|
||||
return $admin_email;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
*/
|
||||
function find_base_url($user_id = null) {
|
||||
$base_url = home_url();
|
||||
return $base_url;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,195 +0,0 @@
|
||||
<?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 extract_smallest_entity($value) {
|
||||
$size = 1;
|
||||
while (is_array($value) && $size === 1) {
|
||||
// https://stackoverflow.com/questions/2216052/how-to-check-whether-an-array-is-empty-using-php#answer-20177855
|
||||
$tmp_array = array_filter($value);
|
||||
$size = count($tmp_array);
|
||||
if ($size === 1) {
|
||||
$value = reset($tmp_array);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
function merge_arrays(...$arrays) {
|
||||
// extract first element
|
||||
$new_array = array_shift($arrays);
|
||||
// then loop through the next arrays
|
||||
foreach ($arrays as $array) {
|
||||
foreach ($array as $key => $value) {
|
||||
$value = \CUSTER\extract_smallest_entity($value);
|
||||
// if key does not already exist, simply add it and the value to new array
|
||||
if (!isset($new_array[$key])) {
|
||||
$new_array[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
// if key already exist, add a new key with a (number) suffix
|
||||
$i = 1;
|
||||
while (isset($new_array[$key.'('.$i.')'])) {
|
||||
++$i;
|
||||
}
|
||||
$new_array[$key.'('.$i.')'] = $value;
|
||||
}
|
||||
}
|
||||
uksort($new_array, 'strnatcasecmp');
|
||||
return $new_array;
|
||||
}
|
||||
|
||||
|
||||
function output_list_front($array, $user_id, $if_empty) {
|
||||
$output = '<ul>';
|
||||
foreach ($array as $key => $value) {
|
||||
if (str_starts_with($key, '_')) {
|
||||
if (!str_starts_with($key, '__')) {
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
$value = \CUSTER\format_user_info($key, $user_id, $if_empty);
|
||||
$output .= '<li>';
|
||||
$output .= '<span>';
|
||||
$output .= $key;
|
||||
$output .= ' : ';
|
||||
$output .= $value;
|
||||
$output .= '</span>';
|
||||
$output .= '</li>';
|
||||
}
|
||||
$output .= '</ul>';
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* shortcode to write user info of post author
|
||||
* 0 or 1 argument, usage :
|
||||
* - [custer_user_info] -> list of all availables infos
|
||||
* - [custer_user_info user_email] -> display the email
|
||||
* - [custer_user_info user_email user_login] -> display the email
|
||||
* - [custer_user_info user_email id='logged_in'] -> display the email of the connected user
|
||||
* - [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) {
|
||||
$is_important = false;
|
||||
|
||||
|
||||
/*
|
||||
* choose the default id target :
|
||||
* - logged_in
|
||||
* - author
|
||||
*
|
||||
$id_is = 'logged_in';
|
||||
*/
|
||||
$id_is = 'author';
|
||||
$if_empty = '';
|
||||
|
||||
|
||||
/*
|
||||
* has parameter 'id' ?
|
||||
* has parameter important ?
|
||||
* has parameter if_empty ?
|
||||
* if yes, handle them and removes them from $atts
|
||||
*
|
||||
*/
|
||||
if (is_array($atts)) {
|
||||
if (isset($atts['id'])) {
|
||||
$id_is = $atts['id'];
|
||||
unset($atts['id']);
|
||||
}
|
||||
if ($id_is === 'logged_in') {
|
||||
if (in_array('important', $atts)) {
|
||||
$is_important = true;
|
||||
$key = array_search('important', $atts);
|
||||
unset($atts[$key]);
|
||||
}
|
||||
}
|
||||
if (isset($atts['if_empty'])) {
|
||||
$if_empty = $atts['if_empty'];
|
||||
unset($atts['if_empty']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* should output all or a specific parameter ?
|
||||
*
|
||||
*/
|
||||
$output_all = false;
|
||||
if (empty($atts))
|
||||
$output_all = true;
|
||||
else if (count($atts) === 0)
|
||||
$output_all = true;
|
||||
|
||||
|
||||
/*
|
||||
* get id according to attributes,
|
||||
* and the atts of the other shortcode 'custer_change_id' if in use
|
||||
*
|
||||
*/
|
||||
if ($id_is === 'logged_in') {
|
||||
if ($is_important) {
|
||||
$user_id = Custer::get_current_user_backup();
|
||||
if ($user_id === null)
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
else {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
}
|
||||
else if ($id_is === 'author') {
|
||||
$user_id = \CUSTER\get_author_id();
|
||||
}
|
||||
else {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* output all the available parameters (for help)
|
||||
*
|
||||
*/
|
||||
if ($output_all) {
|
||||
$user_properties = (array) get_userdata($user_id)->data;
|
||||
$user_metas = get_user_meta($user_id);
|
||||
$queries = \CUSTER\get_queries($user_id, $if_empty);
|
||||
$user_infos = \CUSTER\merge_arrays($user_metas, $user_properties, $queries);
|
||||
return \CUSTER\output_list_front($user_infos, $user_id, $if_empty);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* real purpose of this shortcode :
|
||||
* only return the first argument
|
||||
*
|
||||
*/
|
||||
if (is_array($atts))
|
||||
$query = $atts[0];
|
||||
else if (is_string($atts))
|
||||
$query = $atts;
|
||||
else
|
||||
return '';
|
||||
return \CUSTER\format_user_info($query, $user_id, $if_empty);
|
||||
}
|
||||
add_shortcode('custer_user_info', __NAMESPACE__.'\current_user_infos');
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user