108 lines
2.4 KiB
PHP
108 lines
2.4 KiB
PHP
<?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!');
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* the earliest hook to use is_..() is parse_query
|
|
* -> https://developer.wordpress.org/apis/hooks/action-reference/
|
|
*
|
|
*/
|
|
function is_partner_form_creation_page_CIPF() {
|
|
Plgntls::debug_infos();
|
|
$slug_partner_create_page = Cipf::SLUG_PARTNER_CREATE_PAGE;
|
|
|
|
/*
|
|
* only for the partner form creation page
|
|
* first available hook is parse_query
|
|
* -> https://developer.wordpress.org/apis/hooks/action-reference/
|
|
* 584 : wordpress_docker/volumes/wp_volume/wp-includes/query.php
|
|
* 4427 : wordpress_docker/volumes/wp_volume/wp-includes/class-wp-query.php
|
|
*
|
|
*/
|
|
if (!is_page($slug_partner_create_page)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
* action to be done at the init state of the page
|
|
* cannot check if user is logged in or partner at this step
|
|
*
|
|
*/
|
|
function partner_form_creation_page_init_CIPF() {
|
|
Plgntls::debug_infos(2);
|
|
|
|
if (!is_partner()) {
|
|
return;
|
|
}
|
|
Plgntls::debug_infos();
|
|
|
|
// https://developer.wordpress.org/reference/functions/get_query_var/#more-information
|
|
global $wp;
|
|
$wp->add_query_var('pid');
|
|
}
|
|
add_action('init','partner_form_creation_page_init_CIPF');
|
|
|
|
|
|
|
|
|
|
/*
|
|
* check if partner can access the form to create a new page
|
|
*
|
|
*/
|
|
function partner_form_creation_page_CIPF() {
|
|
Plgntls::debug_infos(2);
|
|
|
|
if (!is_partner()) {
|
|
return;
|
|
}
|
|
if (!is_partner_form_creation_page_CIPF()) {
|
|
return;
|
|
}
|
|
Plgntls::debug_infos();
|
|
|
|
/*
|
|
* -> if partner don't have page yet && this is not edit page -> let him access it
|
|
* if partner dont' have page yet && this is edit page -> redirect him
|
|
* if partner have page && this is not edit page -> redirect him
|
|
* -> if partner have page && this is edit page && this edit its page -> let him access it
|
|
* if partner have page && this is edit page && this dont edit its page -> redirect him
|
|
*
|
|
* to check for pid, add 'pid' to query vars in 'init' hook
|
|
* -> https://developer.wordpress.org/reference/functions/get_query_var/#more-information
|
|
*
|
|
*/
|
|
$is_edit_id = get_query_var('pid', false);
|
|
$partner_post = has_partner_post();
|
|
if (false === $partner_post) {
|
|
if (false === $is_edit_id) {
|
|
return;
|
|
}
|
|
}
|
|
else {
|
|
$post_id = $partner_post->ID;
|
|
if ($is_edit_id == $post_id) {
|
|
return;
|
|
}
|
|
}
|
|
redirection_profil_CIPF();
|
|
}
|
|
add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
|
|
|
|
|
|
|
|
|
|
|
?>
|