added css and functions to make some acf fields read-only

This commit is contained in:
asus
2024-04-17 16:47:14 +02:00
parent 62dcaa7672
commit 3a1f0b07ee
7 changed files with 138 additions and 7 deletions

View File

@@ -0,0 +1,80 @@
<?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!');
}
/*
* checks if the acf field contains the class 'read_only_cipf'
*
*/
function is_acf_field_disabled($field) {
Plgntls::debug_infos();
if (!isset($field['wrapper'])) {
return false;
}
if (!isset($field['wrapper']['class'])) {
return false;
}
$class = $field['wrapper']['class'];
if (!str_contains($class, 'read_only_cipf')) {
return false;
}
return true;
}
/*
* if acf field has class to be disabled
* -> add the 'disabled' value to object after it is loaded
*
*/
function disable_acf_field_CIPF($field) {
Plgntls::debug_infos();
if (!is_acf_field_disabled($field)) {
return $field;
}
$field['disabled'] = 1;
//$field['readonly'] = 1;
return $field;
}
add_filter('acf/load_field', 'disable_acf_field_CIPF');
/*
* if acf field has class to be disabled
* -> dont update the values
* -> should work for all acf fields
* 200 : ../../../wordpress_docker/volumes/wp_volume/wp-content/plugins/advanced-custom-fields/includes/acf-value-functions.php
*
*/
function disable_all_acf_field_CIPF($null, $value, $post_id, $field) {
Plgntls::debug_infos();
if (!isset($_POST['acf'])) {
return $null;
}
if (!is_acf_field_disabled($field)) {
return $null;
}
return false;
}
add_filter('acf/pre_update_value', 'disable_all_acf_field_CIPF', 10, 4);
?>

View File

@@ -120,4 +120,6 @@ function display_states_css_CIPF($user_id = null) {
?>

View File

@@ -0,0 +1,30 @@
<?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!');
}
/*
* load css for user profil admin page
* if fipf is weing user profil in admin, hide some fields
* 278 : ../../../wordpress_docker/volumes/wp_volume/wp-admin/user-edit.php
*
*/
function admin_partner_page_css_CIPF() {
Plgntls::debug_infos();
Plgntls::add_to_front(array('css/acf_fields.css'));
}
add_action('admin_enqueue_scripts', 'admin_partner_page_css_CIPF');
?>

View File

@@ -12,10 +12,9 @@ if (!defined('ABSPATH')) {
/*
* load css for when fipf is weing user profil in admin
* load css for user profil admin page
* if fipf is weing user profil in admin, hide some fields
* 278 : ../../../wordpress_docker/volumes/wp_volume/wp-admin/user-edit.php
*
*/
@@ -27,7 +26,7 @@ function admin_user_profil_css_CIPF() {
* for everyone viewing user profil
*
*/
Plgntls::add_to_front(array('css/user_profile.css'));
Plgntls::add_to_front(array('css/user_profile.css', 'css/acf_fields.css'));
if (!current_user_can($role_fipf)) {
return;