updated plgntls options to improve default with new options
This commit is contained in:
@@ -167,24 +167,38 @@ function update_paypal_credentials_CIPF($request, $option_name, $option_data, $o
|
||||
function update_emails_settings_option_CIPF($request, $option_name, $option_data, $option_default) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
//error_log("---");
|
||||
//error_log("request: " . json_encode($request));
|
||||
//error_log("option_data bedore: " . json_encode($option_data));
|
||||
foreach ($option_data as $email_type => $email_options) {
|
||||
//error_log("email_type: " . $email_type);
|
||||
// if ($email_type === '_name') {
|
||||
// continue;
|
||||
// }
|
||||
// $ret_email = update_email_by_type_CIPF($email_type, $email_options, $request);
|
||||
// if ($ret_email !== false) {
|
||||
// $option_data[$email_type] = $ret_email;
|
||||
// }
|
||||
|
||||
$option_data[$email_type] = update_email_by_type_CIPF($email_type, $email_options, $request);
|
||||
$ret_update = update_email_by_type_CIPF($email_type, $email_options, $request);
|
||||
if ($ret_update !== false) {
|
||||
$option_data[$email_type] = $ret_update;
|
||||
}
|
||||
}
|
||||
//error_log("option_data after : " . json_encode($option_data));
|
||||
|
||||
Plgntls::update_option_safe($option_name, $option_data);
|
||||
/*
|
||||
* to reorder and add new data with the default data
|
||||
* also take the name of the default
|
||||
* not really good :p
|
||||
*
|
||||
*/
|
||||
$new_option = array();
|
||||
foreach ($option_default as $email => $options) {
|
||||
if (isset($option_data[$email])) {
|
||||
$new_option[$email] = $option_data[$email];
|
||||
}
|
||||
else {
|
||||
// it means it was not in the saved data, but was added in the default
|
||||
$ret_update = update_email_by_type_CIPF($email, $options, $request);
|
||||
if ($ret_update !== false) {
|
||||
$new_option[$email] = $ret_update;
|
||||
}
|
||||
else {
|
||||
$new_option[$email] = $options;
|
||||
}
|
||||
}
|
||||
$new_option[$email]['name'] = $options['name'];
|
||||
}
|
||||
|
||||
Plgntls::update_option_safe($option_name, $new_option);
|
||||
}
|
||||
|
||||
|
||||
@@ -195,10 +209,7 @@ function update_emails_settings_option_CIPF($request, $option_name, $option_data
|
||||
*/
|
||||
function update_email_by_type_CIPF($email_type, $email_options, $request) {
|
||||
Plgntls::debug_infos();
|
||||
//error_log("email type: " . $email_type);
|
||||
//if ($email_type === '_name') {
|
||||
// return false;
|
||||
//}
|
||||
$is_new = false;
|
||||
|
||||
/*
|
||||
* set notification/confirmation_send to false by default,
|
||||
@@ -220,19 +231,21 @@ function update_email_by_type_CIPF($email_type, $email_options, $request) {
|
||||
if ($new_value === $value) {
|
||||
continue;
|
||||
}
|
||||
$is_new = true;
|
||||
if ($option === 'notification_send' || $option === 'confirmation_send') {
|
||||
$email_options[$option] = true;
|
||||
}
|
||||
else {
|
||||
// error_log("option: " . $option);
|
||||
// error_log("- previous value: " . $value);
|
||||
// error_log("- newvalue : " . $new_value);
|
||||
$email_options[$option] = $new_value;
|
||||
}
|
||||
}
|
||||
|
||||
//error_log("email_options: " . json_encode($email_options));
|
||||
return $email_options;
|
||||
if ($is_new === false) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return $email_options;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,25 +17,44 @@ function is_own_partner() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_partner = Cipf::ROLE_PARTNER;
|
||||
|
||||
error_log("in toggle A");
|
||||
/*
|
||||
* is_single() will only return true for published post
|
||||
* so instead checks for both is_singular and post_type
|
||||
*
|
||||
if (!is_single()) {
|
||||
return false;
|
||||
}
|
||||
if (!is_singular()) {
|
||||
return false;
|
||||
}
|
||||
error_log("post type: " . get_post_type());
|
||||
if (get_post_type() !== 'post') {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
error_log("in toggle B");
|
||||
if (!is_user_logged_in()) {
|
||||
return false;
|
||||
}
|
||||
error_log("in toggle C");
|
||||
if (!current_user_can($role_partner)) {
|
||||
return false;
|
||||
}
|
||||
error_log("in toggle D");
|
||||
global $post;
|
||||
if (is_null($post)) {
|
||||
return false;
|
||||
}
|
||||
error_log("in toggle E");
|
||||
Plgntls::debug_infos();
|
||||
$current_post_author = (int)($post->post_author);
|
||||
$current_user_id = (int)get_current_user_id();
|
||||
if ($current_user_id !== $current_post_author) {
|
||||
return false;
|
||||
}
|
||||
error_log("in toggle F");
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -66,10 +85,10 @@ function partner_page_scripts_CIPF() {
|
||||
/*
|
||||
* then check if is partner own page
|
||||
*
|
||||
*/
|
||||
if (!is_own_partner()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* on partner own page, load css to show own stuff
|
||||
@@ -96,16 +115,20 @@ function toggle_partner_page_CIPF() {
|
||||
* - has query action
|
||||
*
|
||||
*/
|
||||
error_log("in toggle 1");
|
||||
if (!is_own_partner()) {
|
||||
return;
|
||||
}
|
||||
error_log("in toggle 2");
|
||||
Plgntls::debug_infos();
|
||||
if (!isset($_GET['action'])) {
|
||||
return;
|
||||
}
|
||||
error_log("in toggle 3");
|
||||
if ($_GET['action'] !== $toggle_partner_page) {
|
||||
return;
|
||||
}
|
||||
error_log("in toggle 4");
|
||||
|
||||
/*
|
||||
* get the post id and object
|
||||
@@ -116,6 +139,7 @@ function toggle_partner_page_CIPF() {
|
||||
if (is_null($current_post)) {
|
||||
return;
|
||||
}
|
||||
error_log("in toggle 5");
|
||||
|
||||
/*
|
||||
* toogle the status
|
||||
@@ -141,13 +165,12 @@ function toggle_partner_page_CIPF() {
|
||||
*
|
||||
*/
|
||||
$url = remove_query_arg('action');
|
||||
error_log("url: " . $url);
|
||||
wp_safe_redirect($url);
|
||||
exit;
|
||||
|
||||
|
||||
}
|
||||
add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||
//add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -86,6 +86,7 @@ function redirection_profil_CIPF(){
|
||||
'post_type' => 'post',
|
||||
'author' => $current_user_id,
|
||||
'posts_per_page' => 1,
|
||||
'post_status' => array('publish', 'draft'),
|
||||
);
|
||||
$posts = get_posts($args);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user