fixed error in checks partner own page and modify to draft
This commit is contained in:
@@ -4,7 +4,7 @@ Plugin Name: hggg_cipf
|
||||
Plugin URI:
|
||||
Description:
|
||||
Author: hugogogo
|
||||
Version: 0.5.2.2
|
||||
Version: 0.5.3
|
||||
Author URI:
|
||||
*/
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ if (!defined('ABSPATH')) {
|
||||
function redirect_home_CIPF(){
|
||||
Plgntls::debug_infos();
|
||||
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect(home_url(), 301);
|
||||
exit;
|
||||
}
|
||||
@@ -32,6 +34,8 @@ function redirect_prof_command_CIPF(){
|
||||
Plgntls::debug_infos();
|
||||
$slug_command_card = Cipf::SLUG_COMMAND_CARD;
|
||||
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect(home_url($slug_command_card), 301);
|
||||
exit;
|
||||
}
|
||||
@@ -54,10 +58,6 @@ function redirection_profil_CIPF(){
|
||||
$partner_page_creation = home_url($slug_partner_create_page);
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
// 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();
|
||||
|
||||
|
||||
if (!is_user_logged_in()) {
|
||||
redirect_home_CIPF();
|
||||
@@ -69,6 +69,8 @@ function redirection_profil_CIPF(){
|
||||
*/
|
||||
if (current_user_can($role_prof)) {
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect($user_page, 301);
|
||||
exit;
|
||||
}
|
||||
@@ -85,6 +87,8 @@ function redirection_profil_CIPF(){
|
||||
else {
|
||||
$redirect_url = get_permalink($partner_post->ID);
|
||||
}
|
||||
// Set up nocache headers before redirecting : https://developer.wordpress.org/reference/functions/wp_safe_redirect/#user-contributed-notes
|
||||
nocache_headers();
|
||||
wp_redirect($redirect_url, 301);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ function is_partner_form_creation_page_CIPF() {
|
||||
|
||||
/*
|
||||
* 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() {
|
||||
|
||||
@@ -10,43 +10,30 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
/*
|
||||
* utility function that checks if the current page is owned by the logged in partner
|
||||
* checks if the current page is owned by the logged in partner
|
||||
* dont work in 'init' hook
|
||||
* works in 'wp' hook
|
||||
*
|
||||
*/
|
||||
function is_own_partner() {
|
||||
function is_own_partner_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
$role_partner = Cipf::ROLE_PARTNER;
|
||||
|
||||
/*
|
||||
* is_single() will only return true for published post
|
||||
* so instead checks for both is_singular and post_type
|
||||
*
|
||||
if (!is_partner()) {
|
||||
return false;
|
||||
}
|
||||
if (!is_single()) {
|
||||
return false;
|
||||
}
|
||||
if (!is_singular()) {
|
||||
return false;
|
||||
}
|
||||
error_log("post type: " . get_post_type());
|
||||
if (get_post_type() !== 'post') {
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
Plgntls::debug_infos();
|
||||
|
||||
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_post_author_id = (int)($post->post_author);
|
||||
$current_user_id = (int)get_current_user_id();
|
||||
if ($current_user_id !== $current_post_author) {
|
||||
if ($current_user_id !== $current_post_author_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -55,6 +42,29 @@ error_log("post type: " . get_post_type());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* action to be done at the init state of the page
|
||||
*
|
||||
*/
|
||||
function partner_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('action');
|
||||
}
|
||||
add_action('init','partner_page_init_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* upload scripts and styles on partner page
|
||||
*
|
||||
@@ -79,10 +89,10 @@ function partner_page_scripts_CIPF() {
|
||||
/*
|
||||
* then check if is partner own page
|
||||
*
|
||||
if (!is_own_partner()) {
|
||||
*/
|
||||
if (!is_own_partner_CIPF()) {
|
||||
return;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* on partner own page, load css to show own stuff
|
||||
@@ -100,23 +110,23 @@ add_action('wp_enqueue_scripts', 'partner_page_scripts_CIPF', 11);
|
||||
*
|
||||
*/
|
||||
function toggle_partner_page_CIPF() {
|
||||
Plgntls::debug_infos();
|
||||
Plgntls::debug_infos(2);
|
||||
$toggle_partner_page = Cipf::QUERY_TOGGLE_PARTNER_PAGE;
|
||||
|
||||
/*
|
||||
* check if :
|
||||
* - is own partner
|
||||
* - has query action
|
||||
* to check for 'action' query, add 'action' to query vars in 'init' hook
|
||||
* -> https://developer.wordpress.org/reference/functions/get_query_var/#more-information
|
||||
*
|
||||
*/
|
||||
if (!is_own_partner()) {
|
||||
if (!is_own_partner_CIPF()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
if (!isset($_GET['action'])) {
|
||||
return;
|
||||
}
|
||||
if ($_GET['action'] !== $toggle_partner_page) {
|
||||
$is_action_toggle = get_query_var('action', false);
|
||||
if ($is_action_toggle !== $toggle_partner_page) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -159,7 +169,62 @@ function toggle_partner_page_CIPF() {
|
||||
|
||||
|
||||
}
|
||||
//add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||
add_action('template_redirect', 'toggle_partner_page_CIPF');
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* if url uses post id : /?p=40772
|
||||
* make redirects to its post_name version : /la-fipf
|
||||
*
|
||||
*/
|
||||
//function partner_page_check_url_CIPF() {
|
||||
// Plgntls::debug_infos(2);
|
||||
// if (!is_own_partner_CIPF()) {
|
||||
// return;
|
||||
// }
|
||||
// Plgntls::debug_infos();
|
||||
//
|
||||
// /*
|
||||
// * get the post name
|
||||
// *
|
||||
// */
|
||||
// $post_id = get_the_ID();
|
||||
// $current_post = get_post($post_id);
|
||||
// if (is_null($current_post)) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// /*
|
||||
// *
|
||||
// *
|
||||
// $is_query_id = get_query_var('p', false);
|
||||
// if (false === $is_query_id) {
|
||||
// return;
|
||||
// }
|
||||
// else {
|
||||
// wp_safe_redirect(home_url($current_post->post_name));
|
||||
// }
|
||||
// */
|
||||
// $current_url = untrailingslashit(get_permalink());
|
||||
// if (false === $current_url) {
|
||||
// return;
|
||||
// }
|
||||
// $url = untrailingslashit(home_url($current_post->post_name));
|
||||
//global $wp;
|
||||
//error_log("wp: " . json_encode($wp));
|
||||
//error_log("wp->request: " . json_encode($wp->request));
|
||||
//error_log("url: " . json_encode($url));
|
||||
//error_log("current_url: " . json_encode($current_url));
|
||||
//error_log("current_post->post_name: " . json_encode($current_post->post_name));
|
||||
// if ($url !== $current_url) {
|
||||
// wp_safe_redirect(home_url($current_post->post_name));
|
||||
// exit;
|
||||
// }
|
||||
//}
|
||||
//add_action('template_redirect', 'partner_page_check_url_CIPF');
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -173,7 +238,7 @@ function page_partner_check_CIPF() {
|
||||
Plgntls::debug_infos(2);
|
||||
|
||||
// is partner own page
|
||||
if (!is_own_partner()) {
|
||||
if (!is_own_partner_CIPF()) {
|
||||
return;
|
||||
}
|
||||
Plgntls::debug_infos();
|
||||
|
||||
Reference in New Issue
Block a user