File "form-post.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/advanced-custom-fields/includes/forms/form-post.php
File size: 4.63 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_Post')) {
    class ACF_Form_Post
    {
        var $style = '';
        function __construct()
        {
            add_action('load-post.php', array($this, 'initialize'));
            add_action('load-post-new.php', array($this, 'initialize'));
            add_filter('wp_insert_post_empty_content', array($this, 'wp_insert_post_empty_content'), 10, 2);
            add_action('save_post', array($this, 'save_post'), 10, 2);
        }
        function initialize()
        {
            global $typenow;
            $restricted = array('acf-field-group', 'attachment');
            if (in_array($typenow, $restricted)) {
                return;
            }
            acf_enqueue_scripts(array('uploader' => true));
            add_action('add_meta_boxes', array($this, 'add_meta_boxes'), 10, 2);
        }
        function add_meta_boxes($post_type, $post)
        {
            $postboxes = array();
            $field_groups = acf_get_field_groups(array('post_id' => $post->ID, 'post_type' => $post_type));
            if ($field_groups) {
                foreach ($field_groups as $field_group) {
                    $id = "acf-{$field_group['key']}";
                    $title = $field_group['title'];
                    $context = $field_group['position'];
                    $priority = 'high';
                    if ($context == 'side') {
                        $priority = 'core';
                    }
                    $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group);
                    $postboxes[] = array('id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'label' => $field_group['label_placement'], 'edit' => acf_get_field_group_edit_link($field_group['ID']));
                    add_meta_box($id, acf_esc_html($title), array($this, 'render_meta_box'), $post_type, $context, $priority, array('field_group' => $field_group));
                }
                $this->style = acf_get_field_group_style($field_groups[0]);
                acf_localize_data(array('postboxes' => $postboxes));
            }
            if (acf_get_setting('remove_wp_meta_box')) {
                remove_meta_box('postcustom', false, 'normal');
            }
            add_action('edit_form_after_title', array($this, 'edit_form_after_title'));
            do_action('acf/add_meta_boxes', $post_type, $post, $field_groups);
        }
        function edit_form_after_title()
        {
            global $post, $wp_meta_boxes;
            acf_form_data(array('screen' => 'post', 'post_id' => $post->ID));
            do_meta_boxes(get_current_screen(), 'acf_after_title', $post);
            echo '<style type="text/css" id="acf-style">' . $this->style . '</style>';
        }
        function render_meta_box($post, $metabox)
        {
            $id = $metabox['id'];
            $field_group = $metabox['args']['field_group'];
            $fields = acf_get_fields($field_group);
            acf_render_fields($fields, $post->ID, 'div', $field_group['instruction_placement']);
        }
        function wp_insert_post_empty_content($maybe_empty, $postarr)
        {
            if ($maybe_empty && acf_maybe_get_POST('_acf_changed')) {
                return false;
            }
            return $maybe_empty;
        }
        function allow_save_post($post)
        {
            $allow = true;
            $restrict = array('auto-draft', 'revision', 'acf-field', 'acf-field-group');
            if (in_array($post->post_type, $restrict)) {
                $allow = false;
            }
            $form_post_id = (int) acf_maybe_get_POST('post_ID');
            if ($form_post_id && $form_post_id !== $post->ID) {
                $allow = false;
            }
            if ($post->post_type == 'revision') {
                if (acf_maybe_get_POST('wp-preview') == 'dopreview' && $form_post_id === $post->post_parent) {
                    $allow = true;
                }
            }
            return $allow;
        }
        function save_post($post_id, $post)
        {
            if (!$this->allow_save_post($post)) {
                return $post_id;
            }
            if (!acf_verify_nonce('post')) {
                return $post_id;
            }
            if ($post->post_status == 'publish') {
                if (!acf_validate_save_post()) {
                    return;
                }
            }
            acf_save_post($post_id);
            if (post_type_supports($post->post_type, 'revisions')) {
                acf_save_post_revision($post_id);
            }
            return $post_id;
        }
    }
    acf_new_instance('ACF_Form_Post');
}