File "form-user.php"
Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/forms/form-user.php
File
size: 4.66 B
MIME-type: text/x-php
Charset: utf-8
Download Open Edit Advanced Editor Back
<?php
if (!defined('ABSPATH')) {
exit;
}
if (!class_exists('ACF_Form_User')) {
class ACF_Form_User
{
var $view = '';
function __construct()
{
add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
add_action('login_form_register', array($this, 'login_form_register'));
add_action('show_user_profile', array($this, 'render_edit'));
add_action('edit_user_profile', array($this, 'render_edit'));
add_action('user_new_form', array($this, 'render_new'));
add_action('register_form', array($this, 'render_register'));
add_action('user_register', array($this, 'save_user'));
add_action('profile_update', array($this, 'save_user'));
add_filter('registration_errors', array($this, 'filter_registration_errors'), 10, 3);
}
function admin_enqueue_scripts()
{
if (!acf_is_screen(array('profile', 'user', 'user-edit'))) {
return;
}
acf_enqueue_scripts();
}
function login_form_register()
{
acf_enqueue_scripts(array('context' => 'login'));
}
function render_register()
{
$this->render(array('user_id' => 0, 'view' => 'register', 'el' => 'div'));
}
function render_edit($user)
{
if (!is_admin()) {
acf_enqueue_scripts();
}
$this->render(array('user_id' => $user->ID, 'view' => 'edit', 'el' => 'tr'));
}
function render_new()
{
if (is_multisite()) {
return;
}
$this->render(array('user_id' => 0, 'view' => 'add', 'el' => 'tr'));
}
function render($args = array())
{
if (isset($_POST['acf'])) {
add_filter('acf/pre_load_value', array($this, 'filter_pre_load_value'), 10, 3);
}
$args = wp_parse_args($args, array('user_id' => 0, 'view' => 'edit', 'el' => 'tr'));
$post_id = 'user_' . $args['user_id'];
$field_groups = acf_get_field_groups(array('user_id' => $args['user_id'] ? $args['user_id'] : 'new', 'user_form' => $args['view']));
if (empty($field_groups)) {
return;
}
acf_form_data(array('screen' => 'user', 'post_id' => $post_id, 'validation' => $args['view'] == 'register' ? 0 : 1));
$before = '<table class="form-table"><tbody>';
$after = '</tbody></table>';
if ($args['el'] == 'div') {
$before = '<div class="acf-user-' . $args['view'] . '-fields acf-fields -clear">';
$after = '</div>';
}
foreach ($field_groups as $field_group) {
$fields = acf_get_fields($field_group);
if ($field_group['style'] === 'default') {
echo '<h2>' . $field_group['title'] . '</h2>';
}
echo $before;
acf_render_fields($fields, $post_id, $args['el'], $field_group['instruction_placement']);
echo $after;
}
add_action('acf/input/admin_footer', array($this, 'admin_footer'), 10, 1);
}
function admin_footer()
{
?>
<script type="text/javascript">
(function($) {
// vars
var view = '<?php
echo $this->view;
?>';
// add missing spinners
var $submit = $('input.button-primary');
if( !$submit.next('.spinner').length ) {
$submit.after('<span class="spinner"></span>');
}
})(jQuery);
</script>
<?php
}
function save_user($user_id)
{
if (!acf_verify_nonce('user')) {
return $user_id;
}
if (acf_validate_save_post(true)) {
acf_save_post("user_{$user_id}");
}
}
function filter_registration_errors($errors, $sanitized_user_login, $user_email)
{
if (!acf_validate_save_post()) {
$acf_errors = acf_get_validation_errors();
foreach ($acf_errors as $acf_error) {
$errors->add(acf_idify($acf_error['input']), acf_esc_html(acf_punctify(sprintf(__('<strong>Error</strong>: %s', 'acf'), $acf_error['message']))));
}
}
return $errors;
}
function filter_pre_load_value($null, $post_id, $field)
{
$field_key = $field['key'];
if (isset($_POST['acf'][$field_key])) {
return $_POST['acf'][$field_key];
}
return $null;
}
}
acf_new_instance('ACF_Form_User');
}