- updated states to work for user_id and post_id
- added states for partner page state publish-draft
This commit is contained in:
@@ -13,7 +13,6 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
/*
|
||||
* 278 : ../../../wordpress_docker/volumes/wp_volume/wp-admin/user-edit.php
|
||||
* 157 : ../../../wordpress_docker/volumes/wp_volume/wp-admin/user-edit.php
|
||||
*
|
||||
function admin_user_profil_css_CIPF($user_id) {
|
||||
*/
|
||||
@@ -27,7 +26,6 @@ function admin_user_profil_css_CIPF() {
|
||||
|
||||
Plgntls::add_to_front(array('css/fipf_user_profile.css'));
|
||||
}
|
||||
//add_action('edit_user_profile_update', 'admin_user_profil_css_CIPF');
|
||||
add_action('user_edit_form_tag', 'admin_user_profil_css_CIPF');
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
|
||||
function display_page_css_CIPF($user_id = null) {
|
||||
function display_states_css_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$css_for_states = array();
|
||||
Plgntls::add_to_front(array('css/display_states/_default.css'));
|
||||
@@ -92,6 +92,19 @@ function display_page_css_CIPF($user_id = null) {
|
||||
$css_for_states[] = 'css/display_states/type_virement.css';
|
||||
}
|
||||
|
||||
/*
|
||||
* page partenaire
|
||||
* - 'Publiee'
|
||||
* - 'Brouillon'
|
||||
*
|
||||
*/
|
||||
if (is_page_publish_CIPF($user_id)) {
|
||||
$css_for_states[] = 'css/display_states/page_partenaire_publish.css';
|
||||
}
|
||||
else if (is_page_draft_CIPF($user_id)) {
|
||||
$css_for_states[] = 'css/display_states/page_partenaire_draft.css';
|
||||
}
|
||||
|
||||
Plgntls::add_to_front($css_for_states);
|
||||
}
|
||||
|
||||
|
||||
66
plugins/cipf_plugin/php/partners_form.php
Normal file
66
plugins/cipf_plugin/php/partners_form.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* check if partner can access the form to create a new page
|
||||
*
|
||||
*/
|
||||
function partner_form_creation_page_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_partner = Plgntls::ROLE_PARTNER;
|
||||
$slug_partner_create_page = Plgntls::SLUG_PARTNER_CREATE_PAGE;
|
||||
|
||||
/*
|
||||
* only for the partner form creation page
|
||||
*
|
||||
*/
|
||||
if (!is_page($slug_partner_create_page)) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
|
||||
/*
|
||||
* redirect anyone that is not a partner
|
||||
*
|
||||
*/
|
||||
if (!is_user_logged_in()) {
|
||||
redirect_home_CIPF();
|
||||
}
|
||||
if (!current_user_can($role_partner)) {
|
||||
redirect_home_CIPF();
|
||||
}
|
||||
|
||||
/*
|
||||
* if a partner already has a page, redirect it
|
||||
*
|
||||
*/
|
||||
redirection_profil_CIPF();
|
||||
}
|
||||
add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -9,6 +9,36 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* utility function that checks if the current page is owned by the logged in partner
|
||||
*
|
||||
*/
|
||||
function is_own_partner() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_partner = Plgntls::ROLE_PARTNER;
|
||||
|
||||
if (!is_single()) {
|
||||
return false;
|
||||
}
|
||||
if (!is_user_logged_in()) {
|
||||
return false;
|
||||
}
|
||||
if (!current_user_can($role_partner)) {
|
||||
return false;
|
||||
}
|
||||
global $post;
|
||||
if (is_null($post)) {
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -18,35 +48,26 @@ if (!defined('ABSPATH')) {
|
||||
*/
|
||||
function partner_page_scripts_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_partner = Plgntls::ROLE_PARTNER;
|
||||
|
||||
/*
|
||||
* if on post, load css
|
||||
* - to hide partner own stuff
|
||||
* - for states
|
||||
*
|
||||
*/
|
||||
if (!is_single()) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* if on post, load css to hide partner own stuff
|
||||
*
|
||||
*/
|
||||
Plgntls::debug_infos();
|
||||
Plgntls::add_to_front(array('css/partner_page.css'));
|
||||
$post_id = get_the_ID();
|
||||
display_states_css_CIPF($post_id);
|
||||
|
||||
/*
|
||||
* then check if is partner own page
|
||||
*
|
||||
*/
|
||||
if (!is_user_logged_in()) {
|
||||
return;
|
||||
}
|
||||
if (!current_user_can($role_partner)) {
|
||||
return;
|
||||
}
|
||||
global $post;
|
||||
if (is_null($post)) {
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
if (!is_own_partner()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -61,6 +82,106 @@ add_action('wp_enqueue_scripts', 'partner_page_scripts_CIPF', 11);
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* listen to the front button to toggle page publish/draft
|
||||
*
|
||||
*/
|
||||
function toggle_partner_page_CIPF() {
|
||||
Plgntls::debug_infos();
|
||||
$toggle_partner_page = Plgntls::QUERY_TOGGLE_PARTNER_PAGE;
|
||||
|
||||
/*
|
||||
* check if :
|
||||
* - is own partner
|
||||
* - has query action
|
||||
*
|
||||
*/
|
||||
if (!is_own_partner()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
if (!isset($_GET['action'])) {
|
||||
return;
|
||||
}
|
||||
if ($_GET['action'] !== $toggle_partner_page) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* get the post id and object
|
||||
*
|
||||
*/
|
||||
$post_id = get_the_ID();
|
||||
$current_post = get_post($post_id);
|
||||
if (is_null($current_post)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* toogle the status
|
||||
*
|
||||
*/
|
||||
if ($current_post->post_status === 'publish') {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'draft',
|
||||
));
|
||||
set_page_draft_CIPF($post_id);
|
||||
}
|
||||
else if ($current_post->post_status === 'draft') {
|
||||
wp_update_post(array(
|
||||
'ID' => $post_id,
|
||||
'post_status' => 'publish',
|
||||
));
|
||||
set_page_publish_CIPF($post_id);
|
||||
}
|
||||
|
||||
/*
|
||||
* redirects without the query
|
||||
*
|
||||
*/
|
||||
$url = remove_query_arg('action');
|
||||
error_log("url: " . $url);
|
||||
wp_safe_redirect($url);
|
||||
exit;
|
||||
|
||||
|
||||
}
|
||||
add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* early checks on partner page
|
||||
*
|
||||
*/
|
||||
function page_partner_check_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
|
||||
// is partner own page
|
||||
if (!is_own_partner()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
|
||||
$post_id = get_the_ID();
|
||||
$current_post = get_post($post_id);
|
||||
|
||||
/*
|
||||
* checks if the acf state field is set accrodingly to page state
|
||||
*
|
||||
*/
|
||||
if ($current_post->post_status === 'publish') {
|
||||
set_page_publish_CIPF($post_id);
|
||||
}
|
||||
else if ($current_post->post_status === 'draft') {
|
||||
set_page_draft_CIPF($post_id);
|
||||
}
|
||||
}
|
||||
add_action('wp', 'page_partner_check_CIPF', 11);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ function payment_page_scripts_CIPF() {
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
// enqueue files here
|
||||
display_page_css_CIPF($user_id);
|
||||
display_states_css_CIPF($user_id);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'payment_page_scripts_CIPF');
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ function renew_page_filter_message_CIPF(){
|
||||
|
||||
$user_id = get_current_user_id();
|
||||
|
||||
display_page_css_CIPF($user_id);
|
||||
display_states_css_CIPF($user_id);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'renew_page_filter_message_CIPF');
|
||||
|
||||
|
||||
@@ -144,7 +144,7 @@ function prof_profil_scripts_CIPF() {
|
||||
// the way to find the id of the author of an author_page
|
||||
$author_id = get_queried_object_id();
|
||||
|
||||
display_page_css_CIPF($author_id);
|
||||
display_states_css_CIPF($author_id);
|
||||
}
|
||||
add_action('wp_enqueue_scripts', 'prof_profil_scripts_CIPF', 11);
|
||||
|
||||
|
||||
@@ -32,6 +32,10 @@ if (!defined('ABSPATH')) {
|
||||
* - 'Paypal' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok]
|
||||
* - 'Virement' -> ok 1/1 : [1: modified by diviformbuilder at form validation - ok]
|
||||
*
|
||||
* [/] etat partenaire ('etat_page_partenaire') :
|
||||
* - 'publie'
|
||||
* - 'brouillon'
|
||||
*
|
||||
* [/] numero de carte ('numero_de_la_carte') -> ok 1/1 : [1: after payment & card is 'commande' - ok]
|
||||
*
|
||||
* [/] etat_virement -> ko 2/3 : [1: at form validation - ok], [2: check on profil page - ko], [3: when transfert is started, reset - ok]]
|
||||
@@ -79,14 +83,9 @@ function get_field_init_CIPF($acf_field_name, $acf_id) {
|
||||
* global 'setter' and 'izzer' for this file
|
||||
*
|
||||
*/
|
||||
function is_acf_state_CIPF($acf_field, $state_name, $user_id = null) {
|
||||
function is_acf_state_CIPF($acf_field, $state_name, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
/*
|
||||
* when acf fields have not been initated a first time, you can't find them by name
|
||||
* - one solution is to use key instead
|
||||
@@ -107,14 +106,8 @@ function is_acf_state_CIPF($acf_field, $state_name, $user_id = null) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function set_acf_state_CIPF($acf_field, $state_name, $user_id = null) {
|
||||
function set_acf_state_CIPF($acf_field, $state_name, $acf_id) {
|
||||
Plgntls::debug_infos();
|
||||
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
|
||||
update_field($acf_field['_name'], $acf_field[$state_name], $acf_id);
|
||||
}
|
||||
|
||||
@@ -139,7 +132,11 @@ function set_acf_state_CIPF($acf_field, $state_name, $user_id = null) {
|
||||
function is_account_state_CIPF($state_name, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_account_state = Plgntls::ACF_ACCOUNT_STATE;
|
||||
return is_acf_state_CIPF($acf_account_state, $state_name, $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return is_acf_state_CIPF($acf_account_state, $state_name, $acf_id);
|
||||
}
|
||||
function is_account_new_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
@@ -182,7 +179,11 @@ function is_account_waiting_transfert_CIPF($user_id = null) {
|
||||
function set_account_state_CIPF($state_name, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_account_state = Plgntls::ACF_ACCOUNT_STATE;
|
||||
set_acf_state_CIPF($acf_account_state, $state_name, $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
set_acf_state_CIPF($acf_account_state, $state_name, $acf_id);
|
||||
}
|
||||
function set_account_new_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
@@ -220,25 +221,91 @@ function set_account_expired_CIPF($user_id = null) {
|
||||
* - 'Renouvellement'
|
||||
*
|
||||
*/
|
||||
function is_card_new_CIPF($user_id = null) {
|
||||
function is_card_state_CIPF($state, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_state = Plgntls::ACF_CARD_STATE;
|
||||
return is_acf_state_CIPF($acf_card_state, 'new', $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return is_acf_state_CIPF($acf_card_state, $state, $acf_id);
|
||||
}
|
||||
function is_card_new_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
return is_card_state_CIPF('new', $user_id);
|
||||
}
|
||||
function is_card_renew_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
return is_card_state_CIPF('renew', $user_id);
|
||||
}
|
||||
/*
|
||||
* setters :
|
||||
*/
|
||||
function set_card_state_CIPF($state, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_state = Plgntls::ACF_CARD_STATE;
|
||||
return is_acf_state_CIPF($acf_card_state, 'renew', $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
set_acf_state_CIPF($acf_card_state, $state, $acf_id);
|
||||
}
|
||||
function set_card_new_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_state = Plgntls::ACF_CARD_STATE;
|
||||
set_acf_state_CIPF($acf_card_state, 'new', $user_id);
|
||||
set_card_state_CIPF('new', $user_id);
|
||||
}
|
||||
function set_card_renew_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_state = Plgntls::ACF_CARD_STATE;
|
||||
set_acf_state_CIPF($acf_card_state, 'renew', $user_id);
|
||||
set_card_state_CIPF('renew', $user_id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* etat page partenaire ('etat_page_partenaire') :
|
||||
* - 'Publiee'
|
||||
* - 'Brouillon'
|
||||
*
|
||||
*/
|
||||
function is_page_state_CIPF($state, $post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_page_state = Plgntls::ACF_PAGE_STATE;
|
||||
if (is_null($post_id)) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
$acf_id = $post_id;
|
||||
return is_acf_state_CIPF($acf_page_state, $state, $acf_id);
|
||||
}
|
||||
function is_page_publish_CIPF($post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
return is_page_state_CIPF('publish', $post_id);
|
||||
}
|
||||
function is_page_draft_CIPF($post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
return is_page_state_CIPF('draft', $post_id);
|
||||
}
|
||||
/*
|
||||
* setters :
|
||||
*/
|
||||
function set_page_state_CIPF($state, $post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_page_state = Plgntls::ACF_PAGE_STATE;
|
||||
if (is_null($post_id)) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
$acf_id = $post_id;
|
||||
set_acf_state_CIPF($acf_page_state, $state, $acf_id);
|
||||
}
|
||||
function set_page_publish_CIPF($post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
set_page_state_CIPF('publish', $post_id);
|
||||
}
|
||||
function set_page_draft_CIPF($post_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
set_page_state_CIPF('draft', $post_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -252,15 +319,22 @@ function set_card_renew_CIPF($user_id = null) {
|
||||
* - 'transfert'=>'Virement'
|
||||
*
|
||||
*/
|
||||
function is_payment_method_paypal_CIPF($user_id = null) {
|
||||
function is_card_method_CIPF($state, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_payment_method = Plgntls::ACF_CARD_PAYMENT_METHOD;
|
||||
return is_acf_state_CIPF($acf_card_payment_method, 'paypal', $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return is_acf_state_CIPF($acf_card_payment_method, $state, $acf_id);
|
||||
}
|
||||
function is_payment_method_paypal_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
return is_card_method_CIPF('paypal', $user_id);
|
||||
}
|
||||
function is_payment_method_transfert_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_payment_method = Plgntls::ACF_CARD_PAYMENT_METHOD;
|
||||
return is_acf_state_CIPF($acf_card_payment_method, 'transfert', $user_id);
|
||||
return is_card_method_CIPF('transfert', $user_id);
|
||||
}
|
||||
|
||||
|
||||
@@ -281,7 +355,11 @@ function is_payment_method_transfert_CIPF($user_id = null) {
|
||||
function is_payment_state_CIPF($type, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_payment_state = Plgntls::ACF_CARD_PAYMENT_STATE;
|
||||
return is_acf_state_CIPF($acf_card_payment_state, $type, $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
return is_acf_state_CIPF($acf_card_payment_state, $type, $acf_id);
|
||||
}
|
||||
function is_payment_started_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
@@ -305,7 +383,11 @@ function is_payment_nothing_CIPF($user_id = null) {
|
||||
function set_payment_state_CIPF($type, $user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
$acf_card_payment_state = Plgntls::ACF_CARD_PAYMENT_STATE;
|
||||
set_acf_state_CIPF($acf_card_payment_state, $type, $user_id);
|
||||
if (is_null($user_id)) {
|
||||
$user_id = get_current_user_id();
|
||||
}
|
||||
$acf_id = 'user_'.$user_id;
|
||||
set_acf_state_CIPF($acf_card_payment_state, $type, $acf_id);
|
||||
}
|
||||
function set_payment_started_CIPF($user_id = null) {
|
||||
Plgntls::debug_infos();
|
||||
Reference in New Issue
Block a user