changed all role occurences by a const
This commit is contained in:
@@ -12,21 +12,32 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
function restrict_author_page_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
if (!is_author())
|
||||
return;
|
||||
|
||||
$can_access = false;
|
||||
if (current_user_can('administrator')) {
|
||||
$can_access = true;
|
||||
}
|
||||
else if (current_user_can('editor')) {
|
||||
$can_access = true;
|
||||
}
|
||||
$current_user = wp_get_current_user();
|
||||
|
||||
if ($can_access === true)
|
||||
/*
|
||||
* check multiple user roles
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
* if user->role is found in array of allowed role, no redirection needed
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array($role_admin, $role_fipf);
|
||||
if (array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
/*
|
||||
* get_queried_object_id() would work too
|
||||
* here get_the_author_meta works and is more explicit
|
||||
*
|
||||
$author_id = get_queried_object_id();
|
||||
*/
|
||||
$author_id = get_the_author_meta( 'ID' );
|
||||
|
||||
$current_user_id = get_current_user_id();
|
||||
|
||||
if ($current_user_id != $author_id) {
|
||||
|
||||
@@ -80,7 +80,7 @@ function filter_email_fb_CIPF($reply_body, $post_array) {
|
||||
return $new_body;
|
||||
}
|
||||
add_filter('df_confirmation_body', 'filter_email_fb_CIPF', 10, 2); // the receive an email
|
||||
add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the administrator receive a notification
|
||||
add_filter('df_notification_body', 'filter_email_fb_CIPF', 10, 2); // the admin receive a notification
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,9 @@ if (!defined('ABSPATH')) {
|
||||
*/
|
||||
function hide_admin_bar_CIPF() {
|
||||
PLGNTLS_class::debug_infos();
|
||||
if (!current_user_can('administrator') && !is_admin()) {
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
if (!current_user_can($role_admin) && !is_admin()) {
|
||||
show_admin_bar(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,34 +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!');
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<?php acf_form_head(); ?>
|
||||
<?php get_header(); ?>
|
||||
|
||||
<div id="primary">
|
||||
<div id="content" role="main">
|
||||
|
||||
<?php /* The loop */ ?>
|
||||
<?php while ( have_posts() ) : the_post(); ?>
|
||||
|
||||
<h1><?php the_title(); ?></h1>
|
||||
|
||||
<?php the_content(); ?>
|
||||
|
||||
<p>My custom field: <?php the_field('my_custom_field'); ?></p>
|
||||
|
||||
<?php acf_form(); ?>
|
||||
|
||||
<?php endwhile; ?>
|
||||
|
||||
</div><!-- #content -->
|
||||
</div><!-- #primary -->
|
||||
|
||||
<?php get_footer(); ?>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,89 +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!');
|
||||
}
|
||||
|
||||
/*
|
||||
function cipfcard_image_editor()
|
||||
{
|
||||
// ob_start();
|
||||
// wp_image_editor('33545');
|
||||
// return ob_get_clean();
|
||||
$cipfcard_image_editor = new PLGNTLS_class();
|
||||
return $cipfcard_image_editor->add_to_front(
|
||||
array(
|
||||
"js/image_editor.js",
|
||||
"html/image_editor.html",
|
||||
)
|
||||
);
|
||||
// if ( ! has_action( "wp_ajax_{$action}" ) ) {
|
||||
// it returns error 400
|
||||
|
||||
}
|
||||
add_shortcode('cipfcard_image_editor', 'cipfcard_image_editor');
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Handles image editing via AJAX.
|
||||
* from wp-admin/includes/ajax-action.php
|
||||
*/
|
||||
/*
|
||||
function wp_ajax_image_editor() {
|
||||
$attachment_id = (int) $_POST['postid'];
|
||||
// $attachment_id = 33555;
|
||||
|
||||
// if ( empty( $attachment_id ) || ! current_user_can( 'edit_post', $attachment_id ) ) {
|
||||
// wp_die( -1 );
|
||||
// }
|
||||
|
||||
// check_ajax_referer( "image_editor-$attachment_id" );
|
||||
// require_once ABSPATH . 'wp-admin/includes/image-edit.php';
|
||||
|
||||
$msg = false;
|
||||
|
||||
switch ( $_POST['do'] ) {
|
||||
case 'save':
|
||||
$msg = wp_save_image( $attachment_id );
|
||||
if ( ! empty( $msg->error ) ) {
|
||||
wp_send_json_error( $msg );
|
||||
}
|
||||
|
||||
wp_send_json_success( $msg );
|
||||
break;
|
||||
case 'scale':
|
||||
$msg = wp_save_image( $attachment_id );
|
||||
break;
|
||||
case 'restore':
|
||||
$msg = wp_restore_image( $attachment_id );
|
||||
break;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
wp_image_editor( $attachment_id, $msg );
|
||||
$html = ob_get_clean();
|
||||
|
||||
if ( ! empty( $msg->error ) ) {
|
||||
wp_send_json_error(
|
||||
array(
|
||||
'message' => $msg,
|
||||
'html' => $html,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
wp_send_json_success(
|
||||
array(
|
||||
'message' => $msg,
|
||||
'html' => $html,
|
||||
)
|
||||
);
|
||||
}
|
||||
add_action( 'wp_ajax_image_editor', 'wp_ajax_image_editor' );
|
||||
*/
|
||||
|
||||
?>
|
||||
@@ -17,6 +17,8 @@ if (!defined('ABSPATH')) {
|
||||
function redirection_page_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
||||
|
||||
if (!is_page($slug_page_redirection))
|
||||
return;
|
||||
@@ -26,11 +28,11 @@ function redirection_page_CIPF(){
|
||||
if (!is_user_logged_in()) {
|
||||
wp_redirect($base_url, 301);
|
||||
}
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
if (current_user_can($role_prof)) {
|
||||
$user_page = get_author_posts_url($current_user_id);
|
||||
wp_redirect($user_page, 301);
|
||||
}
|
||||
else if (current_user_can('partenaire')) {
|
||||
else if (current_user_can($role_partner)) {
|
||||
$args = array(
|
||||
'post_type' => 'post',
|
||||
'author' => $current_user_id,
|
||||
|
||||
@@ -15,11 +15,13 @@ if (!defined('ABSPATH')) {
|
||||
*/
|
||||
function add_partenaires_PLGNTLS($customer_data){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$role_partner = PLGNTLS_class::ROLE_PARTNER;
|
||||
|
||||
$current_url = $_SERVER['HTTP_REFERER']; // not reliable to use referer, TODO: find another solution
|
||||
$path_brut = parse_url($current_url, PHP_URL_PATH);
|
||||
$path = trim($path_brut, '/');
|
||||
if ($path === 'creation-du-compte-partenaire')
|
||||
$customer_data['role'] = 'partenaire';
|
||||
$customer_data['role'] = $role_partner;
|
||||
return $customer_data;
|
||||
}
|
||||
add_filter( 'xoo_el_register_new_customer_data', 'add_partenaires_PLGNTLS', 10, 1 );
|
||||
|
||||
@@ -52,7 +52,9 @@ function renew_page_restrictions_CIPF(){
|
||||
PLGNTLS_class::debug_infos();
|
||||
$slug_renew_card = PLGNTLS_class::SLUG_RENEW_CARD;
|
||||
$slug_page_redirection = PLGNTLS_class::SLUG_PAGE_REDIRECTION;
|
||||
// $acf_prof_can_renew = PLGNTLS_class::ACF_PROF_CAN_RENEW;
|
||||
$role_prof = PLGNTLS_class::ROLE_PROF;
|
||||
$role_fipf = PLGNTLS_class::ROLE_FIPF;
|
||||
$role_admin = PLGNTLS_class::ROLE_ADMIN;
|
||||
|
||||
if (!is_page($slug_renew_card))
|
||||
return;
|
||||
@@ -72,7 +74,7 @@ function renew_page_restrictions_CIPF(){
|
||||
* https://developer.wordpress.org/reference/functions/current_user_can/#div-comment-4083
|
||||
*
|
||||
*/
|
||||
$allowed_roles = array('administrator', 'editor', 'professeur__professeure');
|
||||
$allowed_roles = array($role_admin, $role_fipf, $role_prof);
|
||||
if (!array_intersect($allowed_roles, $current_user->roles))
|
||||
return;
|
||||
|
||||
@@ -80,7 +82,7 @@ function renew_page_restrictions_CIPF(){
|
||||
* if prof, check card state
|
||||
* if cannot renew, redirect
|
||||
*
|
||||
if (current_user_can('professeur__professeure')) {
|
||||
if (current_user_can($role_prof)) {
|
||||
$can_renew = get_field($acf_prof_can_renew['_name'], $acf_id);
|
||||
if ($can_renew === false) {
|
||||
$redirect_url = home_url() . '/' . $slug_page_redirection;
|
||||
|
||||
Reference in New Issue
Block a user