- reorganized files
- fixed error in partner edti/creation page
This commit is contained in:
@@ -40,14 +40,15 @@ include_once(Plgntls::root_path() . 'php/partners_register.php');
|
|||||||
include_once(Plgntls::root_path() . 'php/partners_page.php');
|
include_once(Plgntls::root_path() . 'php/partners_page.php');
|
||||||
include_once(Plgntls::root_path() . 'php/partners_form.php');
|
include_once(Plgntls::root_path() . 'php/partners_form.php');
|
||||||
// utils
|
// utils
|
||||||
//include_once(Plgntls::root_path() . '/php/menus.php');
|
include_once(Plgntls::root_path() . 'php/_utils_states.php');
|
||||||
include_once(Plgntls::root_path() . 'php/states.php');
|
include_once(Plgntls::root_path() . 'php/_utils_redirections.php');
|
||||||
include_once(Plgntls::root_path() . 'php/redirections.php');
|
include_once(Plgntls::root_path() . 'php/_utils_display_css.php');
|
||||||
include_once(Plgntls::root_path() . 'php/display_css.php');
|
include_once(Plgntls::root_path() . 'php/_utils_checks_roles.php');
|
||||||
include_once(Plgntls::root_path() . 'php/payments.php');
|
// actions
|
||||||
include_once(Plgntls::root_path() . 'php/random_posts.php');
|
include_once(Plgntls::root_path() . 'php/_actions_payments.php');
|
||||||
include_once(Plgntls::root_path() . 'php/scheduled_events.php');
|
include_once(Plgntls::root_path() . 'php/_actions_random_posts.php');
|
||||||
include_once(Plgntls::root_path() . 'php/emails.php');
|
include_once(Plgntls::root_path() . 'php/_actions_scheduled_events.php');
|
||||||
|
include_once(Plgntls::root_path() . 'php/_actions_emails.php');
|
||||||
// admin
|
// admin
|
||||||
include_once(Plgntls::root_path() . 'php/admin_hide_bar.php');
|
include_once(Plgntls::root_path() . 'php/admin_hide_bar.php');
|
||||||
include_once(Plgntls::root_path() . 'php/admin_user_profil.php');
|
include_once(Plgntls::root_path() . 'php/admin_user_profil.php');
|
||||||
|
|||||||
81
plugins/cipf_plugin/php/_utils_checks_roles.php
Normal file
81
plugins/cipf_plugin/php/_utils_checks_roles.php
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?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!');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function has_partner_post() {
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
$current_user_id = get_current_user_id();
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'post_type' => 'post',
|
||||||
|
'author' => $current_user_id,
|
||||||
|
'posts_per_page' => 1,
|
||||||
|
'post_status' => array('publish', 'draft'),
|
||||||
|
);
|
||||||
|
$post = get_posts($args);
|
||||||
|
if (empty($post)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return reset($post);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* to use is_user_logged_in at early init hook
|
||||||
|
* 1162 : wordpress_docker/volumes/wp_volume/wp-includes/pluggable.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function is_user_logged_in_CIPF() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
if (function_exists('is_user_logged_in')) {
|
||||||
|
return is_user_logged_in();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
return $user->exists();
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* to use current_user_can at early init hook
|
||||||
|
* 877 : wordpress_docker/volumes/wp_volume/wp-includes/capabilities.php
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function current_user_can_CIPF($capability) {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
if (function_exists('current_user_can')) {
|
||||||
|
return current_user_can($capability);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
return user_can($user, $capability);
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -18,7 +18,8 @@ function redirect_home_CIPF(){
|
|||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||||
nocache_headers();
|
// i dont really know what it does, but it creates a warning sometimes : 'PHP Warning: Cannot modify - header information headers already sent in /var/www/html/wp-includes/pluggable.php'
|
||||||
|
//nocache_headers();
|
||||||
|
|
||||||
wp_redirect(home_url(), 301);
|
wp_redirect(home_url(), 301);
|
||||||
exit;
|
exit;
|
||||||
@@ -31,7 +32,7 @@ function redirect_home_CIPF(){
|
|||||||
* redirects new prof to commande
|
* redirects new prof to commande
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
function redirect_command_CIPF(){
|
function redirect_prof_command_CIPF(){
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
||||||
|
|
||||||
@@ -82,25 +83,12 @@ function redirection_profil_CIPF(){
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (current_user_can($role_partner)) {
|
if (current_user_can($role_partner)) {
|
||||||
$args = array(
|
$partner_post = has_partner_post();
|
||||||
'post_type' => 'post',
|
if (false === $partner_post) {
|
||||||
'author' => $current_user_id,
|
|
||||||
'posts_per_page' => 1,
|
|
||||||
'post_status' => array('publish', 'draft'),
|
|
||||||
);
|
|
||||||
$posts = get_posts($args);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* if post exists, redirects to it
|
|
||||||
* otherwise redirects to post creation
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (empty($posts)) {
|
|
||||||
$redirect_url = $partner_page_creation;
|
$redirect_url = $partner_page_creation;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$query = reset($posts);
|
$redirect_url = get_permalink($partner_post->ID);
|
||||||
$redirect_url = get_permalink($query->ID);
|
|
||||||
}
|
}
|
||||||
wp_redirect($redirect_url, 301);
|
wp_redirect($redirect_url, 301);
|
||||||
exit;
|
exit;
|
||||||
@@ -150,6 +138,31 @@ add_action('template_redirect', 'redirection_page_CIPF');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* checks if partner current user is partner
|
||||||
|
* works as soon as 'init' hook
|
||||||
|
*
|
||||||
|
* first hook to use is...() is parse_query
|
||||||
|
* -> https://developer.wordpress.org/apis/hooks/action-reference/
|
||||||
|
* - after 'init', before 'wp'
|
||||||
|
* but 'init' already has set user, so we can recreate the functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
function redirects_home_if_not_partner() {
|
||||||
|
Plgntls::debug_infos(2);
|
||||||
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
|
||||||
|
if (!is_user_logged_in_CIPF()) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
if (!current_user_can_CIPF($role_partner)) {
|
||||||
|
redirect_home_CIPF();
|
||||||
|
}
|
||||||
|
Plgntls::debug_infos();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
<?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!');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
* menu deconnexion
|
|
||||||
* 1. il faut creer un menu personalisé dans Apparence > Menus
|
|
||||||
* 2. dans le code ci-dessous, changer la valeur de $menu_title pour correspondre au titre du menu
|
|
||||||
* 3. et si besoin changer la valeur de $menu_redirect pour choisir la page de redirection :
|
|
||||||
* - si laissée vide, la redirection se fera sur la page de connexion de wordpress
|
|
||||||
* - avec $current_url la redirection se fera sur la page actuelle
|
|
||||||
* - avec $base_url on redirige vers la page d'accueil du site (l'url sans chemin supplementaire)
|
|
||||||
* cette variable $base_url peut etre utilisee pour construire une autre url :
|
|
||||||
* - $menu_redirect = $base_url -> https://le_site_actuel.com/
|
|
||||||
* - $menu_redirect = $base_url . 'contact' -> https://le_site_actuel.com/contact
|
|
||||||
* - $menu_redirect = $current_url -> https://le_site_actuel.com/la_meme_page
|
|
||||||
* - $menu_redirect = 'www.un_autre_site.net/contact' -> https://www.un_autre_site.net/contact
|
|
||||||
*/
|
|
||||||
function change_menu_logout($items){
|
|
||||||
Plgntls::debug_infos();
|
|
||||||
$menu_title = 'special logout';
|
|
||||||
|
|
||||||
// quelques urls utiles :
|
|
||||||
$base_url = home_url();
|
|
||||||
$current_url = home_url( $_SERVER['REQUEST_URI'] );
|
|
||||||
|
|
||||||
$menu_redirect = '';
|
|
||||||
foreach($items as $item){
|
|
||||||
if( $item->title === $menu_title){
|
|
||||||
$item->url = wp_nonce_url( wp_logout_url( $menu_redirect ), 'log-out' );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $items;
|
|
||||||
}
|
|
||||||
add_filter('wp_nav_menu_objects', 'change_menu_logout');
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -9,6 +9,44 @@ if (!defined('ABSPATH')) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
|
||||||
|
redirects_home_if_not_partner();
|
||||||
|
|
||||||
|
// 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');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -18,33 +56,37 @@ if (!defined('ABSPATH')) {
|
|||||||
*/
|
*/
|
||||||
function partner_form_creation_page_CIPF() {
|
function partner_form_creation_page_CIPF() {
|
||||||
Plgntls::debug_infos(2);
|
Plgntls::debug_infos(2);
|
||||||
$role_partner = Cipf::ROLE_PARTNER;
|
|
||||||
$slug_partner_create_page = Cipf::SLUG_PARTNER_CREATE_PAGE;
|
|
||||||
|
|
||||||
/*
|
redirects_home_if_not_partner();
|
||||||
* only for the partner form creation page
|
if (!is_partner_form_creation_page_CIPF()) {
|
||||||
*
|
|
||||||
*/
|
|
||||||
if (!is_page($slug_partner_create_page)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* redirect anyone that is not a partner
|
* -> 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
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (!is_user_logged_in()) {
|
$is_edit_id = get_query_var('pid', false);
|
||||||
redirect_home_CIPF();
|
$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;
|
||||||
}
|
}
|
||||||
if (!current_user_can($role_partner)) {
|
|
||||||
redirect_home_CIPF();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* if a partner already has a page, redirect it
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
redirection_profil_CIPF();
|
redirection_profil_CIPF();
|
||||||
}
|
}
|
||||||
add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
||||||
@@ -62,5 +104,4 @@ add_action('template_redirect', 'partner_form_creation_page_CIPF');
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ function is_own_partner() {
|
|||||||
Plgntls::debug_infos(2);
|
Plgntls::debug_infos(2);
|
||||||
$role_partner = Cipf::ROLE_PARTNER;
|
$role_partner = Cipf::ROLE_PARTNER;
|
||||||
|
|
||||||
error_log("in toggle A");
|
|
||||||
/*
|
/*
|
||||||
* is_single() will only return true for published post
|
* is_single() will only return true for published post
|
||||||
* so instead checks for both is_singular and post_type
|
* so instead checks for both is_singular and post_type
|
||||||
@@ -34,27 +33,22 @@ error_log("post type: " . get_post_type());
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
error_log("in toggle B");
|
|
||||||
if (!is_user_logged_in()) {
|
if (!is_user_logged_in()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
error_log("in toggle C");
|
|
||||||
if (!current_user_can($role_partner)) {
|
if (!current_user_can($role_partner)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
error_log("in toggle D");
|
|
||||||
global $post;
|
global $post;
|
||||||
if (is_null($post)) {
|
if (is_null($post)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
error_log("in toggle E");
|
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
$current_post_author = (int)($post->post_author);
|
$current_post_author = (int)($post->post_author);
|
||||||
$current_user_id = (int)get_current_user_id();
|
$current_user_id = (int)get_current_user_id();
|
||||||
if ($current_user_id !== $current_post_author) {
|
if ($current_user_id !== $current_post_author) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
error_log("in toggle F");
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -115,20 +109,16 @@ function toggle_partner_page_CIPF() {
|
|||||||
* - has query action
|
* - has query action
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
error_log("in toggle 1");
|
|
||||||
if (!is_own_partner()) {
|
if (!is_own_partner()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error_log("in toggle 2");
|
|
||||||
Plgntls::debug_infos();
|
Plgntls::debug_infos();
|
||||||
if (!isset($_GET['action'])) {
|
if (!isset($_GET['action'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error_log("in toggle 3");
|
|
||||||
if ($_GET['action'] !== $toggle_partner_page) {
|
if ($_GET['action'] !== $toggle_partner_page) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error_log("in toggle 4");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* get the post id and object
|
* get the post id and object
|
||||||
@@ -139,7 +129,6 @@ error_log("in toggle 4");
|
|||||||
if (is_null($current_post)) {
|
if (is_null($current_post)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
error_log("in toggle 5");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* toogle the status
|
* toogle the status
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ function prof_profil_redirects_CIPF() {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (is_account_new_CIPF()) {
|
if (is_account_new_CIPF()) {
|
||||||
redirect_command_CIPF();
|
redirect_prof_command_CIPF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
add_action('template_redirect', 'prof_profil_redirects_CIPF', 11);
|
||||||
|
|||||||
Reference in New Issue
Block a user