Files
2024_WEBSITE_fipf/plugins/cipf_plugin/php/paypal/payment_page.php

162 lines
2.6 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!');
}
/*
* action to be done at the init state of the page
*
*/
function prof_payment_page_init_CIPF() {
Plgntls::debug_infos(2);
if (!is_prof_CIPF()) {
return;
}
Plgntls::debug_infos();
// https://developer.wordpress.org/reference/functions/get_query_var/#more-information
global $wp;
$wp->add_query_var('prof_card_change');
}
add_action('init','prof_payment_page_init_CIPF');
/*
* early checks on payment page
*
*/
function payment_page_checks_CIPF() {
Plgntls::debug_infos(2);
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
// check the slug
if (!is_page($slug_paypal_page)) {
return;
}
Plgntls::debug_infos();
// get the user id
$user_id = get_current_user_id();
// also reset change card for 5€
reset_acf_prof_change_card_CIPF();
}
add_action('wp', 'payment_page_checks_CIPF');
/*
* check on fabrication page to check card change
*
*/
function fabrication_page_checks_CIPF() {
Plgntls::debug_infos(2);
$slug_paypal_fabrication = Cipf::SLUG_PAYPAL_FABRICATION;
// check the slug
if (!is_page($slug_paypal_fabrication)) {
return;
}
Plgntls::debug_infos();
// get the user id
$user_id = get_current_user_id();
/*
* check for query card change
* and modify acf field accordingly
*
*/
$is_card_change = get_query_var('prof_card_change', false);
if ($is_card_change == true) {
set_acf_prof_change_card_CIPF();
}
else {
reset_acf_prof_change_card_CIPF();
}
}
add_action('wp', 'fabrication_page_checks_CIPF');
/*
* only profs can access this page
*
*/
function payment_page_redirects_CIPF() {
Plgntls::debug_infos(2);
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
$role_prof = Cipf::ROLE_PROF;
// don't redirect if it is the divi builder mode
if (et_fb_is_enabled()) {
return;
}
// check the slug
if (!is_page($slug_paypal_page)) {
return;
}
Plgntls::debug_infos();
/*
* if prof, don't redirect
* for everyone else, redirect
*
*/
if (current_user_can($role_prof)) {
return;
}
redirect_home_CIPF();
}
add_action('template_redirect', 'payment_page_redirects_CIPF');
/*
* time to upload some scripts and styles on prof profil page
*
*/
function payment_page_scripts_CIPF() {
Plgntls::debug_infos(2);
$slug_paypal_page = Cipf::SLUG_PAYPAL_PAGE;
// check the slug
if (!is_page($slug_paypal_page)) {
return;
}
Plgntls::debug_infos();
// get the user id
$user_id = get_current_user_id();
// enqueue files here
display_states_css_CIPF($user_id);
}
add_action('wp_enqueue_scripts', 'payment_page_scripts_CIPF');
?>