more improves in optin gestion in class, automatic handling for basic cases
This commit is contained in:
@@ -55,31 +55,6 @@
|
||||
</form>
|
||||
|
||||
|
||||
<!--
|
||||
-->
|
||||
<h1>email a la creation de compte</h1>
|
||||
<form id="email_registration_cipf" method="POST" action="<?php echo admin_url( 'admin-post.php' ); ?>">
|
||||
<input type="hidden" name="action" value="<?php echo $admin_post_email_registration; ?>">
|
||||
<?php wp_nonce_field($nonce_email['_action'], $nonce_email['_name']); ?>
|
||||
|
||||
<div class="define_email_registration vertical_wrapper">
|
||||
<label for="define_email_registration_cipf">email : </label>
|
||||
<textarea id="define_email_registration_cipf" name="email"><?php echo $email_registration['email']; ?></textarea>
|
||||
</div>
|
||||
|
||||
<div class="send_email">
|
||||
<input type="checkbox" id="send_email_prof_cipf" name="is_email_prof" <?php if ($email_registration['is_email_prof'] === true) {echo 'checked';} ?> />
|
||||
<label for="send_email_prof_cipf">envoyer un email à l'inscription des profs ?</label>
|
||||
</div>
|
||||
|
||||
<div class="send_email">
|
||||
<input type="checkbox" id="send_email_partner_cipf" name="is_email_partner" <?php if ($email_registration['is_email_partner'] === true) {echo 'checked';} ?> />
|
||||
<label for="send_email_partner_cipf">envoyer un email à l'inscription des partenaires ?</label>
|
||||
</div>
|
||||
|
||||
<input type="submit" value="send"/>
|
||||
</form>
|
||||
|
||||
|
||||
<!--
|
||||
-->
|
||||
|
||||
@@ -32,10 +32,10 @@ function add_plugin_content_CIPF() {
|
||||
/*
|
||||
* registration email
|
||||
*
|
||||
*/
|
||||
$admin_post_payment_messages = Plgntls::ADMIN_POST_PAYMENT_MESSAGES;
|
||||
$nonce_payment_messages = Plgntls::ADMIN_MENU_NONCE_PAYMENT_MESSAGES;
|
||||
$payment_messages = get_payment_messages_option_CIPF();
|
||||
*/
|
||||
|
||||
ob_start();
|
||||
include(Plgntls::root_path() . '/html/menu/cipf_menu.html');
|
||||
|
||||
50
plugins/xtxpatch/html/admin_menu.html
Normal file
50
plugins/xtxpatch/html/admin_menu.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<style>
|
||||
h1 {
|
||||
margin-left: 15px;
|
||||
margin-top: 50px;
|
||||
}
|
||||
form {
|
||||
margin: 15px;
|
||||
border: 1px solid black;
|
||||
padding: 20px;
|
||||
}
|
||||
form > div {
|
||||
margin: 20px 0px;
|
||||
}
|
||||
.define_paypal_credentials_cipf input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
form .vertical_wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
form textarea {
|
||||
resize: vertical;
|
||||
height: 120px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<h1>email a la creation de compte</h1>
|
||||
<?php echo Plgntls_xtx::open_form_option($option_register_email_name); ?>
|
||||
<div class="define_email_registration vertical_wrapper">
|
||||
<label for="define_email_registration_cipf">email : </label>
|
||||
<textarea id="define_email_registration_cipf" name="email"><?php echo $option_register_email_value['email']; ?></textarea>
|
||||
</div>
|
||||
|
||||
<!--
|
||||
<div class="send_email">
|
||||
<input type="checkbox" id="send_email_prof_cipf" name="is_email_prof" <?php if ($email_registration['is_email_prof'] === true) {echo 'checked';} ?> />
|
||||
<label for="send_email_prof_cipf">envoyer un email à l'inscription des profs ?</label>
|
||||
</div>
|
||||
|
||||
<div class="send_email">
|
||||
<input type="checkbox" id="send_email_partner_cipf" name="is_email_partner" <?php if ($email_registration['is_email_partner'] === true) {echo 'checked';} ?> />
|
||||
<label for="send_email_partner_cipf">envoyer un email à l'inscription des partenaires ?</label>
|
||||
</div>
|
||||
-->
|
||||
|
||||
<input type="submit" value="send"/>
|
||||
</form>
|
||||
|
||||
@@ -487,9 +487,7 @@ class Plgntls_xtx {
|
||||
if ($file->ext === 'html')
|
||||
include($file->path);
|
||||
}
|
||||
$html = ob_get_clean();
|
||||
|
||||
return $html;
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -883,11 +881,8 @@ class Plgntls_xtx {
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*/
|
||||
|
||||
const SLUG_TOOGLE_ADMIN_MENU = "toggle_admin_menu_url_xtxpatch";
|
||||
const ACTION_TOOGLE_ADMIN_MENU = "toggle_admin_menu_url_xtxpatch";
|
||||
const OPTION_TOGGLE_MENU = [
|
||||
'_name'=>'toggle_admin_menu_option_xtxpatch',
|
||||
'_callback'=>__CLASS__.'::toggle_plugin_menu',
|
||||
'_default'=>'hide',
|
||||
'show'=>'show',
|
||||
'hide'=>'hide',
|
||||
@@ -919,7 +914,7 @@ class Plgntls_xtx {
|
||||
$menu_options = array('callback'=>$menu_options);
|
||||
}
|
||||
|
||||
self::_create_menu($options);
|
||||
self::_create_menu($menu_options);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1004,18 +999,13 @@ class Plgntls_xtx {
|
||||
* handle the toggle menu when url is reached
|
||||
*
|
||||
*/
|
||||
public static function toggle_plugin_menu($request, $option_name) {
|
||||
error_log("inside toggle_plugin_menu");
|
||||
|
||||
public static function toggle_plugin_menu($request, $option_name, $option_value) {
|
||||
if ($request[$option_name] === 'show') {
|
||||
update_option($option_name, 'show');
|
||||
}
|
||||
else if ($request[$option_name] === 'hide') {
|
||||
update_option($option_name, 'hide');
|
||||
}
|
||||
|
||||
self::redirect_menu_referer();
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@@ -1077,12 +1067,38 @@ class Plgntls_xtx {
|
||||
public static function get_option_safe($option) {
|
||||
/*
|
||||
* first init option, in case it was not already
|
||||
* it will returns the option name or false
|
||||
* it also works if the option is the name directly
|
||||
*
|
||||
*/
|
||||
if (false === self::_init_option($option)) {
|
||||
$option_name = self::_init_option($option);
|
||||
if (false === $option_name) {
|
||||
return;
|
||||
}
|
||||
return get_option($option['_name']);
|
||||
|
||||
$option_data = get_option($option_name);
|
||||
if (!is_string($option_data)) {
|
||||
$option_data = serialize($option_data);
|
||||
}
|
||||
return $option_data;
|
||||
}
|
||||
|
||||
public static function update_option_safe($option, $option_data) {
|
||||
/*
|
||||
* first init option, in case it was not already
|
||||
* it will returns the option name or false
|
||||
* it also works if the option is the name directly
|
||||
*
|
||||
*/
|
||||
$option_name = self::_init_option($option);
|
||||
if (false === $option_name) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!is_string($option_data)) {
|
||||
$option_data = serialize($option_data);
|
||||
}
|
||||
update_option($option_name, $option_data);
|
||||
}
|
||||
|
||||
public static function get_option_link_href($option_name) {
|
||||
@@ -1109,11 +1125,12 @@ class Plgntls_xtx {
|
||||
if (false === $option_data) {
|
||||
return null;
|
||||
}
|
||||
$form = '<form method="'.$method.'" action="'.admin_menu('admin-post.php').'">';
|
||||
$form .= '<input type="hidden" name="action" value="'.$option_data['_action'].'">';
|
||||
$form .= '<input type="hidden" name="option_name" value="'.$option_data['_name'].'">';
|
||||
$form .= wp_nonce_field($option_data["_nonce_action"], $option_data["_nonce_name"], true, true);
|
||||
return $fields;
|
||||
ob_start();
|
||||
echo '<form method="'.$method.'" action="'.admin_url('admin-post.php').'">';
|
||||
echo '<input type="hidden" name="action" value="'.$option_data['_action'].'">';
|
||||
echo '<input type="hidden" name="option_name" value="'.$option_data['_name'].'">';
|
||||
wp_nonce_field($option_data["_nonce_action"], $option_data["_nonce_name"], true, true);
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
@@ -1136,8 +1153,19 @@ class Plgntls_xtx {
|
||||
* if the option was retrieve in the database,
|
||||
* there is no need to check it again : special field _db = null
|
||||
*
|
||||
* returns the option name if ok, or false
|
||||
*
|
||||
*/
|
||||
private static function _init_option($option) {
|
||||
if (is_string($option)) {
|
||||
if (self::_is_in_list_option($option)) {
|
||||
return $option;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($option['_name'])) {
|
||||
return false;
|
||||
}
|
||||
@@ -1145,7 +1173,7 @@ class Plgntls_xtx {
|
||||
return false;
|
||||
}
|
||||
if (isset($option['_db'])) {
|
||||
return true;
|
||||
return $option['_name'];
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1164,14 +1192,14 @@ class Plgntls_xtx {
|
||||
* if you use another action, it will not trigger the class handler function
|
||||
* - _nonce_action
|
||||
* - _nonce_name
|
||||
* - _callback
|
||||
* - _callback, default
|
||||
*
|
||||
*/
|
||||
$default_option = array(
|
||||
'_action'=>self::$_options_action,
|
||||
'_nonce_action'=>'nonce_action_'.$name,
|
||||
'_nonce_name'=>'nonce_name_'.$name,
|
||||
'_callback'=>'',
|
||||
'_callback'=>__CLASS__.'::default_handle_admin_post_option',
|
||||
);
|
||||
foreach ($default_option as $key => $value) {
|
||||
if (!isset($option[$key])) {
|
||||
@@ -1194,7 +1222,13 @@ class Plgntls_xtx {
|
||||
$options_unserialized[$name] = $option;
|
||||
update_option(self::$_options_list, serialize($options_unserialized), '', 'no');
|
||||
|
||||
return true;
|
||||
return $name;
|
||||
}
|
||||
|
||||
private static function _is_in_list_option($option_name) {
|
||||
$options_serialized = get_option(self::$_options_list);
|
||||
$options_unserialized = unserialize($options_serialized);
|
||||
return isset($options_unserialized[$option_name]);
|
||||
}
|
||||
|
||||
|
||||
@@ -1223,6 +1257,7 @@ class Plgntls_xtx {
|
||||
$option_data['_nonce_action'],
|
||||
$option_data['_callback'])
|
||||
) {
|
||||
error_log("there has been a problem, the option data don't contains the necessary informations (request: " . json_encode($_REQUEST) . ")(option data: " . json_encode($option_data));
|
||||
self::redirect_menu_referer();
|
||||
exit;
|
||||
}
|
||||
@@ -1240,12 +1275,49 @@ class Plgntls_xtx {
|
||||
/*
|
||||
* if nonce passed, call the callback
|
||||
* - with the remaining of the request
|
||||
* - and the option name
|
||||
* - the option name
|
||||
* - and the option value
|
||||
*
|
||||
*/
|
||||
$nonce_callback($request, $option_name);
|
||||
$option_value = self::get_option_safe($option_name);
|
||||
if (false === $option_value) {
|
||||
self::redirect_menu_referer();
|
||||
exit;
|
||||
}
|
||||
$nonce_callback($request, $option_name, $option_value);
|
||||
|
||||
/*
|
||||
* then redirects
|
||||
*
|
||||
*/
|
||||
self::redirect_menu_referer();
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function default_handle_admin_post_option($request, $option_name, $option_data) {
|
||||
/*
|
||||
* in case the option only contains one value, just update it
|
||||
*
|
||||
*/
|
||||
if (is_string($option_data)) {
|
||||
self::update_option_safe($option_name, $request[$option_name]);
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* else, assuming it's a 1 dimension array
|
||||
* update each values
|
||||
*
|
||||
*/
|
||||
foreach ($option_data as $key) {
|
||||
if (isset($request[$key])) {
|
||||
$option_data[$key] = $request[$key];
|
||||
}
|
||||
}
|
||||
self::update_option_safe($option_name, $option_data);
|
||||
}
|
||||
|
||||
|
||||
public static function redirect_menu_referer() {
|
||||
if (wp_get_referer()) {
|
||||
wp_safe_redirect(wp_get_referer());
|
||||
|
||||
@@ -16,9 +16,18 @@ if (!defined('ABSPATH')) {
|
||||
*
|
||||
*/
|
||||
class Xtxpatch {
|
||||
const SLUG_TOOGLE_ADMIN_MENU = ['_name'=>'toogle_admin_menu_url_xtxpatch', 'toggle'=>'toggle', 'show'=>'show', 'hide'=>'hide'];
|
||||
const OPTION_TOGGLE_MENU = ['_name'=>'toggle_admin_menu_option_xtxpatch', 'show'=>'show', 'hide'=>'hide'];
|
||||
|
||||
const OPTION_REGISTER_EMAIL = [
|
||||
'_name'=>'define_email_at_register_xtxpatch',
|
||||
'_callback'=>__NAMESPACE__.'\define_register_email',
|
||||
'_default'=>[
|
||||
'email'=>
|
||||
'Bonjour,
|
||||
Vous venez de créer un compte sur le site carteprof.org avec l’identifiant : $$user_login$$
|
||||
La FIPF',
|
||||
'is_email_prof'=>true,
|
||||
'is_email_partner'=>true,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -33,13 +33,53 @@ add_action('admin_menu', __NAMESPACE__.'\add_plugin_menu');
|
||||
*
|
||||
*/
|
||||
function menu_content() {
|
||||
echo '<p>hello</p>';
|
||||
$option_register_email = Xtxpatch::OPTION_REGISTER_EMAIL;
|
||||
|
||||
$option_register_email_name = $option_register_email['_name'];
|
||||
$option_register_email_value = \Plgntls_xtx::get_option_safe($option_register_email);
|
||||
|
||||
ob_start();
|
||||
include(\Plgntls_xtx::root_path() . 'html/admin_menu.html');
|
||||
echo ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
function define_register_email($request, $option_name, $option_value) {
|
||||
/*
|
||||
* email
|
||||
*
|
||||
*/
|
||||
$email = '';
|
||||
if (isset($request['email'])) {
|
||||
$option_value['email'] = $request['email'];
|
||||
}
|
||||
|
||||
/*
|
||||
* is email ?
|
||||
*
|
||||
$is_email_prof = false;
|
||||
if (isset($post['is_email_prof']) && $post['is_email_prof'] === 'on') {
|
||||
$is_email_prof = true;
|
||||
}
|
||||
$is_email_partner = false;
|
||||
if (isset($post['is_email_partner']) && $post['is_email_partner'] === 'on') {
|
||||
$is_email_partner = true;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* update the option with new values
|
||||
*
|
||||
*/
|
||||
// Plgntls_xtx::update_option_safe($option_name, $email);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user