some more little codes for restrictions and registrations
This commit is contained in:
@@ -24,71 +24,29 @@ include_once( plugin_dir_path(__FILE__) . '/utils/plgntls_class.php');
|
||||
PLGNTLS_class::set_root_dir( plugin_dir_path(__FILE__), plugin_dir_url(__FILE__) );
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* general inclusions
|
||||
*/
|
||||
include_once(PLGNTLS_class::get_path() . '/utils/globals.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/utils/console_log.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'php/utils/globals.php');
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/paypal.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'utils/console_log.php');
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/register/partenaires.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'php/admin_menu/example_menu.php');
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . 'php/paypal/paypal.php');
|
||||
|
||||
|
||||
/*
|
||||
* test the class PLGNTLS
|
||||
*/
|
||||
add_shortcode('fipfcard_plugin', 'fipfcard_test_class_tools');
|
||||
//include_once(PLGNTLS_class::get_path() . '/php/user_infos.php');
|
||||
//include_once(PLGNTLS_class::get_path() . '/php/hide_admin.php');
|
||||
//include_once(PLGNTLS_class::get_path() . '/php/menus.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'php/register_partenaires.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'php/redirections.php');
|
||||
include_once(PLGNTLS_class::get_path() . 'php/author_restriction.php');
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
function custom_frontend_posting_form() {
|
||||
$my_image = the_field('image_ratio');
|
||||
error_log("my_image");
|
||||
error_log(json_encode($my_image));
|
||||
return $my_image;
|
||||
}
|
||||
add_shortcode('custom_frontend_posting_form', 'custom_frontend_posting_form');
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* menu plugin
|
||||
*/
|
||||
include_once(PLGNTLS_class::get_path() . '/php/menu/example_menu.php');
|
||||
function fipfcard_plugin_menu()
|
||||
{
|
||||
add_menu_page
|
||||
(
|
||||
'fipf_card', // webpage title
|
||||
'fipf_card', // menu title
|
||||
'manage_options', // capability
|
||||
'fipfcard-plugin', // menu_slug
|
||||
'fipfcard_plugin_content' // callback function to display page content
|
||||
);
|
||||
}
|
||||
add_action('admin_menu', 'fipfcard_plugin_menu');
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,33 @@
|
||||
<?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 plugin
|
||||
*/
|
||||
function fipfcard_plugin_menu()
|
||||
{
|
||||
add_menu_page
|
||||
(
|
||||
'fipf_card', // webpage title
|
||||
'fipf_card', // menu title
|
||||
'manage_options', // capability
|
||||
'fipfcard-plugin', // menu_slug
|
||||
'fipfcard_plugin_content' // callback function to display page content
|
||||
);
|
||||
}
|
||||
add_action('admin_menu', 'fipfcard_plugin_menu');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
22
plugins/fipfcard_plugin/php/author_restriction.php
Normal file
22
plugins/fipfcard_plugin/php/author_restriction.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
|
||||
|
||||
function restrict_author_page_CIPF() {
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
global $post;
|
||||
$author_id = get_the_author_meta( 'ID' );
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($current_user_id != $author_id) {
|
||||
wp_redirect(home_url());
|
||||
exit;
|
||||
}
|
||||
}
|
||||
add_action('template_redirect', 'restrict_author_page_CIPF');
|
||||
|
||||
|
||||
|
||||
?>
|
||||
25
plugins/fipfcard_plugin/php/hide_admin.php
Normal file
25
plugins/fipfcard_plugin/php/hide_admin.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* hide admin bar if access a front page and is not an admin
|
||||
*/
|
||||
function hide_admin_bar() {
|
||||
if (!current_user_can('administrator') && !is_admin()) {
|
||||
show_admin_bar(false);
|
||||
}
|
||||
}
|
||||
add_action('after_setup_theme', 'hide_admin_bar');
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,3 +1,14 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php acf_form_head(); ?>
|
||||
<?php get_header(); ?>
|
||||
|
||||
|
||||
43
plugins/fipfcard_plugin/php/menus.php
Normal file
43
plugins/fipfcard_plugin/php/menus.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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($items){
|
||||
$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');
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
|
||||
/**
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
@@ -11,6 +8,9 @@ if (!defined('ABSPATH')) {
|
||||
}
|
||||
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
|
||||
|
||||
/**
|
||||
* @see https://developer.paypal.com/docs/checkout/standard/integrate/#link-integratebackend
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
<?php
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
|
||||
/**
|
||||
* it means someone outside wp is accessing the file, in this case kill it.
|
||||
*/
|
||||
@@ -10,6 +7,10 @@ if (!defined('ABSPATH')) {
|
||||
die('You can not access this file!');
|
||||
}
|
||||
|
||||
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/route_api_utils.php');
|
||||
include_once(PLGNTLS_class::get_path() . '/php/paypal/update_user_payment.php');
|
||||
|
||||
function fipf_handle_orders_capture_request($request) {
|
||||
$order_id = $request['orderID'];
|
||||
|
||||
|
||||
43
plugins/fipfcard_plugin/php/redirections.php
Normal file
43
plugins/fipfcard_plugin/php/redirections.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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 redirection_page_CIPF(){
|
||||
if (!is_page('redirection_cipf'))
|
||||
return;
|
||||
|
||||
$base_url = home_url();
|
||||
$current_user_id = get_current_user_id();
|
||||
if (!is_user_logged_in()) {
|
||||
wp_redirect($base_url, 301);
|
||||
}
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
wp_redirect($user_page, 301);
|
||||
}
|
||||
else if (current_user_can('partenaire')) {
|
||||
$args = array(
|
||||
'post_type' => 'project',
|
||||
'author' => $current_user_id,
|
||||
'posts_per_page' => 1,
|
||||
);
|
||||
$query = reset(get_posts($args));
|
||||
$post_id = $query->ID;
|
||||
$redirect_url = get_permalink($query->ID);
|
||||
wp_redirect($redirect_url, 301);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
add_action('template_redirect', 'redirection_page_CIPF');
|
||||
|
||||
|
||||
|
||||
?>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
function add_partenaires_PLGNTLS($customer_data){
|
||||
$current_url = $_SERVER['HTTP_REFERER'];
|
||||
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
||||
$path = trim($path_brut, '/');
|
||||
if ($path === 'creation-du-compte-partenaire')
|
||||
$customer_data['role'] = 'partenaire';
|
||||
return $customer_data;
|
||||
}
|
||||
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_PLGNTLS', 10, 1 );
|
||||
|
||||
|
||||
?>
|
||||
29
plugins/fipfcard_plugin/php/register_partenaires.php
Normal file
29
plugins/fipfcard_plugin/php/register_partenaires.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* at registration, add role 'partenaire' when page url has path 'creation-du-compte-partenaire'
|
||||
*/
|
||||
function add_partenaires_PLGNTLS($customer_data){
|
||||
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
||||
error_log("---");
|
||||
error_log("uri:");
|
||||
error_log($_SERVER['REQUEST_URI']);
|
||||
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
||||
$path = trim($path_brut, '/');
|
||||
if ($path === 'creation-du-compte-partenaire')
|
||||
$customer_data['role'] = 'partenaire';
|
||||
return $customer_data;
|
||||
}
|
||||
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_PLGNTLS', 10, 1 );
|
||||
|
||||
|
||||
?>
|
||||
29
plugins/fipfcard_plugin/php/user_infos.php
Normal file
29
plugins/fipfcard_plugin/php/user_infos.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* shortcode to write email of the logged in user
|
||||
*/
|
||||
function current_user_email_shortcode() {
|
||||
$text_not_logged_in = "you are not logged in";
|
||||
if (is_user_logged_in()) {
|
||||
$current_user = wp_get_current_user();
|
||||
return $current_user->user_email;
|
||||
}
|
||||
else {
|
||||
return $text_not_logged_in;
|
||||
}
|
||||
}
|
||||
add_shortcode('cipf_user_email', 'current_user_email_shortcode');
|
||||
|
||||
|
||||
?>
|
||||
54
plugins/fipfcard_plugin/php/utils/globals.php
Normal file
54
plugins/fipfcard_plugin/php/utils/globals.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
/*
|
||||
* globals variables
|
||||
* const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
|
||||
*/
|
||||
|
||||
/* switch console_log
|
||||
const CONSOLE_OFF = true;
|
||||
*/
|
||||
const FIPFCARD_CONSOLE_OFF = false;
|
||||
|
||||
/*
|
||||
* a variable that will contain the name of the first script enqueued
|
||||
*/
|
||||
$fipfcard_first_script = null;
|
||||
|
||||
|
||||
/*
|
||||
* path to ajax.js file, from root of js dir
|
||||
*/
|
||||
$fipfcard_ajax_file = "utils/ajax.js";
|
||||
|
||||
|
||||
/*
|
||||
* paypal credentials
|
||||
*
|
||||
* LIVE :
|
||||
*
|
||||
* const PAYPAL_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
|
||||
* const PAYPAL_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
|
||||
*
|
||||
* SANBOX :
|
||||
*
|
||||
* const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
* const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||
*
|
||||
*/
|
||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||
|
||||
/*
|
||||
* paypal api base url
|
||||
*/
|
||||
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||
|
||||
?>
|
||||
@@ -1,55 +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!');
|
||||
}
|
||||
|
||||
/*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
globals variables
|
||||
const vs define : https://stackoverflow.com/questions/2447791/php-define-vs-const
|
||||
*/
|
||||
|
||||
/* switch console_log
|
||||
const CONSOLE_OFF = true;
|
||||
*/
|
||||
const FIPFCARD_CONSOLE_OFF = false;
|
||||
|
||||
/**
|
||||
* a variable that will contain the name of the first script enqueued
|
||||
*/
|
||||
$fipfcard_first_script = null;
|
||||
|
||||
|
||||
/**
|
||||
* path to ajax.js file, from root of js dir
|
||||
*/
|
||||
$fipfcard_ajax_file = "utils/ajax.js";
|
||||
|
||||
|
||||
/**
|
||||
* paypal credentials
|
||||
*
|
||||
* LIVE :
|
||||
*
|
||||
* const PAYPAL_CLIENT_ID = "Aedn5e8z__hPBvKirqw5bwlhI9ChG8_N6c1xbgybYyBr4B4oP8uVzmVdH1QVKdPQKf6bWg7orPV4PDrO";
|
||||
* const PAYPAL_CLIENT_SECRET = "EGeGwfHGxHxsjnC-tH8W0IL4nN3_xlc3sXFRPCQOw5uUoWae3eOgghuDKMnZc5DVGTbP6yIjVJ1BaAra";
|
||||
*
|
||||
* SANBOX :
|
||||
*
|
||||
* const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
* const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||
*
|
||||
*/
|
||||
const PAYPAL_CLIENT_ID = "AfcmwxIXlG2ZxaMdjazX57I70BXz__aEqNWaTnqfSCI34a0V7nMbytswx7EViUjlpHs7opyrRwaH9YLl";
|
||||
const PAYPAL_CLIENT_SECRET = "EGunIhGRjPvn0Z8wXO0JsdhET30OStTAH_IyRsmhimEN23_qiRSFD-ql4tvnulKJw6TitZ-vU-ytc4A-";
|
||||
|
||||
/**
|
||||
* paypal api base url
|
||||
*/
|
||||
const PAYPAL_API_BASE_URL = "https://api-m.sandbox.paypal.com";
|
||||
|
||||
?>
|
||||
@@ -1,5 +1,13 @@
|
||||
<?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!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* include those two lines at the top of the main plugin file
|
||||
*
|
||||
|
||||
2
private
2
private
Submodule private updated: 8b8c17b979...9eb05bf82c
Reference in New Issue
Block a user