post_author); $current_user_id = (int)get_current_user_id(); if ($current_user_id !== $current_post_author_id) { return false; } return true; } /* * action to be done at the init state of the page * */ function partner_page_init_CIPF() { Plgntls::debug_infos(2); if (!is_partner_CIPF()) { 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 * */ function partner_page_scripts_CIPF() { Plgntls::debug_infos(2); /* * if on post, load css * - to hide partner own stuff * - for states * */ if (!is_single()) { return; } 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_own_partner_CIPF()) { return; } /* * on partner own page, load css to show own stuff * */ Plgntls::add_to_front(array('css/partner_page_own.css')); } add_action('wp_enqueue_scripts', 'partner_page_scripts_CIPF', 11); /* * prevent access to the post if in draft * */ function restrict_partner_page_draft_CIPF() { Plgntls::debug_infos(2); /* * the restrictions only concerns logged in users * and on post (partner pages) * -> own partners are not restricted * -> also not admin and fipf * */ if (!is_single()) { return; } if (!is_user_logged_in()) { return; } if (is_fipf_CIPF()) { return; } if (is_admin_CIPF()) { return; } if (is_own_partner_CIPF()) { return; } Plgntls::debug_infos(); /* * get the post id and object * */ $post_id = get_the_ID(); $current_post = get_post($post_id); if (is_null($current_post)) { return; } /* * if post is draft, nobody should see it, * except own partner (but they are already out this function) * */ if ($current_post->post_status === 'draft') { redirect_home_CIPF(); } } add_action('template_redirect', 'restrict_partner_page_draft_CIPF'); /* * listen to the front button to toggle page publish/draft * */ function toggle_partner_page_CIPF() { 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_CIPF()) { return; } Plgntls::debug_infos(); $is_action_toggle = get_query_var('action', false); if ($is_action_toggle !== $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'); wp_safe_redirect($url); exit; } add_action('template_redirect', 'toggle_partner_page_CIPF'); /* * if url uses post id, ex: /?p=40772 * make redirects to its post_name version, ex: /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; } /* * * */ $current_slug = trim($_SERVER['REQUEST_URI'], '/'); $slug = trim($current_post->post_name, '/'); if ($slug !== $current_slug) { wp_safe_redirect(home_url($slug)); exit; } } add_action('template_redirect', 'partner_page_check_url_CIPF', 9); /* 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)); error_log("get_page_uri: " . json_encode(get_page_uri())); error_log("_SERVER: " . json_encode($_SERVER)); error_log("_SERVER[REQUEST_URI]: " . json_encode(trim($_SERVER['REQUEST_URI'], '/'))); error_log("_REQUEST: " . json_encode($_REQUEST)); error_log("_GET: " . json_encode($_GET)); error_log("_POST: " . json_encode($_POST)); wp: {"public_query_vars":{"0":"m","1":"p","2":"posts","3":"w","4":"cat","5":"withcomments","6":"withoutcomments","7":"s","8":"search","9":"exact","10":"sentence","11":"calendar","12":"page","13":"paged","14":"more","15":"tb","16":"pb","17":"author","18":"order","19":"orderby","20":"year","21":"monthnum","22":"day","23":"hour","24":"minute","25":"second","26":"name","27":"category_name","28":"tag","29":"feed","30":"author_name","31":"pagename","32":"page_id","33":"error","34":"attachment","35":"attachment_id","36":"subpost","37":"subpost_id","38":"preview","39":"robots","40":"favicon","41":"taxonomy","42":"term","43":"cpage","44":"post_type","45":"embed","46":"post_format","50":"test","51":"rest_route","52":"sitemap","53":"sitemap-subtype","54":"sitemap-stylesheet","55":"action","56":"pid","57":"et_code_snippet_type","58":"et_pb_preview"},"private_query_vars":["offset","posts_per_page","posts_per_archive_page","showposts","nopaging","post_type","post_status","category__in","category__not_in","category__and","tag__in","tag__not_in","tag__and","tag_slug__in","tag_slug__and","tag_id","post_mime_type","perm","comments_per_page","post__in","post__not_in","post_parent","post_parent__in","post_parent__not_in","title","fields"],"extra_query_vars":[],"query_vars":{"page":"","name":"la-fipf"},"query_string":"name=la-fipf","request":"la-fipf","matched_rule":"([^\/]+)(?:\/([0-9]+))?\/?$","matched_query":"name=la-fipf&page=","did_permalink":true} wp->request: "la-fipf" url: "https:\/\/local-cipf-plugin.com\/la-fipf" current_url: "https:\/\/local-cipf-plugin.com\/?p=40772" current_post->post_name: "la-fipf" get_page_uri: "la-fipf" _SERVER: {"SERVER_SOFTWARE":"nginx\/1.20.2","REQUEST_URI":"\/la-fipf","USER":"www-data","HOME":"\/home\/www-data","HTTP_SEC_FETCH_SITE":"cross-site","HTTP_SEC_FETCH_MODE":"navigate","HTTP_SEC_FETCH_DEST":"document","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_351da2be51e3820c1ef099eec9d2e669=La%20FIPF%7C1712428136%7CJuUiFWt1MLm3wKin6FPTbhpC3ivFGEEYerG8UHAQHeR%7Cf4901ba90d872ab24ae82115df09f1a978fc56fc647d40a6422a369eacd3a571; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone","HTTP_CONNECTION":"keep-alive","HTTP_SEC_GPC":"1","HTTP_DNT":"1","HTTP_ACCEPT_ENCODING":"gzip, deflate, br","HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5","HTTP_ACCEPT":"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,*\/*;q=0.8","HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:124.0) Gecko\/20100101 Firefox\/124.0","HTTP_HOST":"local-cipf-plugin.com","REDIRECT_STATUS":"200","SERVER_NAME":"local-cipf-plugin.com","SERVER_PORT":"443","SERVER_ADDR":"172.20.0.4","REMOTE_PORT":"51368","REMOTE_ADDR":"172.20.0.1","GATEWAY_INTERFACE":"CGI\/1.1","HTTPS":"on","REQUEST_SCHEME":"https","SERVER_PROTOCOL":"HTTP\/1.1","DOCUMENT_ROOT":"\/var\/www\/html","DOCUMENT_URI":"\/index.php","SCRIPT_NAME":"\/index.php","CONTENT_LENGTH":"","CONTENT_TYPE":"","REQUEST_METHOD":"GET","QUERY_STRING":"q=\/la-fipf","SCRIPT_FILENAME":"\/var\/www\/html\/index.php","FCGI_ROLE":"RESPONDER","PHP_SELF":"\/index.php","REQUEST_TIME_FLOAT":1712259286.018937,"REQUEST_TIME":1712259286} _SERVER[REQUEST_URI]: "la-fipf" _REQUEST: {"q":"\/la-fipf"} _GET: {"q":"\/la-fipf"} _POST: [] wp: {"public_query_vars":{"0":"m","1":"p","2":"posts","3":"w","4":"cat","5":"withcomments","6":"withoutcomments","7":"s","8":"search","9":"exact","10":"sentence","11":"calendar","12":"page","13":"paged","14":"more","15":"tb","16":"pb","17":"author","18":"order","19":"orderby","20":"year","21":"monthnum","22":"day","23":"hour","24":"minute","25":"second","26":"name","27":"category_name","28":"tag","29":"feed","30":"author_name","31":"pagename","32":"page_id","33":"error","34":"attachment","35":"attachment_id","36":"subpost","37":"subpost_id","38":"preview","39":"robots","40":"favicon","41":"taxonomy","42":"term","43":"cpage","44":"post_type","45":"embed","46":"post_format","50":"test","51":"rest_route","52":"sitemap","53":"sitemap-subtype","54":"sitemap-stylesheet","55":"action","56":"pid","57":"et_code_snippet_type","58":"et_pb_preview"},"private_query_vars":["offset","posts_per_page","posts_per_archive_page","showposts","nopaging","post_type","post_status","category__in","category__not_in","category__and","tag__in","tag__not_in","tag__and","tag_slug__in","tag_slug__and","tag_id","post_mime_type","perm","comments_per_page","post__in","post__not_in","post_parent","post_parent__in","post_parent__not_in","title","fields"],"extra_query_vars":[],"query_vars":{"p":"40772"},"query_string":"p=40772","request":"","matched_rule":"","matched_query":"","did_permalink":false} wp->request: "" url: "https:\/\/local-cipf-plugin.com\/la-fipf" current_url: "https:\/\/local-cipf-plugin.com\/?p=40772" current_post->post_name: "la-fipf" get_page_uri: "la-fipf" _SERVER: {"SERVER_SOFTWARE":"nginx\/1.20.2","REQUEST_URI":"\/?p=40772","USER":"www-data","HOME":"\/home\/www-data","HTTP_SEC_FETCH_USER":"?1","HTTP_SEC_FETCH_SITE":"same-origin","HTTP_SEC_FETCH_MODE":"navigate","HTTP_SEC_FETCH_DEST":"document","HTTP_UPGRADE_INSECURE_REQUESTS":"1","HTTP_COOKIE":"wordpress_test_cookie=WP%20Cookie%20check; wordpress_logged_in_351da2be51e3820c1ef099eec9d2e669=La%20FIPF%7C1712428136%7CJuUiFWt1MLm3wKin6FPTbhpC3ivFGEEYerG8UHAQHeR%7Cf4901ba90d872ab24ae82115df09f1a978fc56fc647d40a6422a369eacd3a571; mjx.menu=renderer%3ANativeMML%26%3Bsemantics%3Atrue%26%3Bcontext%3ABrowser%26%3Bzoom%3ANone","HTTP_CONNECTION":"keep-alive","HTTP_SEC_GPC":"1","HTTP_DNT":"1","HTTP_REFERER":"https:\/\/local-cipf-plugin.com\/la-fipf","HTTP_ACCEPT_ENCODING":"gzip, deflate, br","HTTP_ACCEPT_LANGUAGE":"en-US,en;q=0.5","HTTP_ACCEPT":"text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/avif,image\/webp,*\/*;q=0.8","HTTP_USER_AGENT":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:124.0) Gecko\/20100101 Firefox\/124.0","HTTP_HOST":"local-cipf-plugin.com","REDIRECT_STATUS":"200","SERVER_NAME":"local-cipf-plugin.com","SERVER_PORT":"443","SERVER_ADDR":"172.20.0.4","REMOTE_PORT":"51368","REMOTE_ADDR":"172.20.0.1","GATEWAY_INTERFACE":"CGI\/1.1","HTTPS":"on","REQUEST_SCHEME":"https","SERVER_PROTOCOL":"HTTP\/1.1","DOCUMENT_ROOT":"\/var\/www\/html","DOCUMENT_URI":"\/index.php","SCRIPT_NAME":"\/index.php","CONTENT_LENGTH":"","CONTENT_TYPE":"","REQUEST_METHOD":"GET","QUERY_STRING":"p=40772","SCRIPT_FILENAME":"\/var\/www\/html\/index.php","FCGI_ROLE":"RESPONDER","PHP_SELF":"\/index.php","REQUEST_TIME_FLOAT":1712259296.724377,"REQUEST_TIME":1712259296} _SERVER[REQUEST_URI]: "?p=40772" _REQUEST: {"p":"40772"} _GET: {"p":"40772"} _POST: [] */ /* * early checks on partner page * */ function page_partner_check_CIPF() { Plgntls::debug_infos(2); // is partner own page if (!is_own_partner_CIPF()) { 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); ?>