Example #1
0
 function load()
 {
     // $_POST
     if (acf_verify_nonce('activate_pro_licence')) {
         $this->activate_pro_licence();
     } elseif (acf_verify_nonce('deactivate_pro_licence')) {
         $this->deactivate_pro_licence();
     }
     // view
     $this->view = array('license' => '', 'active' => 0, 'current_version' => acf_get_setting('version'), 'remote_version' => '', 'update_available' => false, 'changelog' => '', 'upgrade_notice' => '');
     // license
     if (acf_pro_is_license_active()) {
         $this->view['license'] = acf_pro_get_license();
         $this->view['active'] = 1;
     }
     // vars
     $info = acf_get_remote_plugin_info();
     // validate
     if (empty($info)) {
         acf_add_admin_notice(__('<b>Error</b>. Could not connect to update server', 'acf'), 'error');
         return;
     }
     // add info to view
     $this->view['remote_version'] = $info['version'];
     // add changelog if the remote version is '>' than the current version
     if (acf_pro_is_update_available()) {
         $this->view['update_available'] = true;
         $this->view['changelog'] = acf_maybe_get($info, 'changelog');
         $this->view['upgrade_notice'] = acf_maybe_get($info, 'upgrade_notice');
     }
 }
Example #2
0
 function load()
 {
     // all export pages should not load local fields
     acf_disable_local();
     // run import / export
     if (acf_verify_nonce('import')) {
         $this->import();
     } elseif (acf_verify_nonce('export')) {
         if (isset($_POST['generate'])) {
             $this->generate();
         } else {
             $this->export();
         }
     }
 }
Example #3
0
 function load()
 {
     // disable filters to ensure ACF loads raw data from DB
     acf_disable_filters();
     // run import / export
     if (acf_verify_nonce('import')) {
         $this->import();
     } elseif (acf_verify_nonce('export')) {
         if (isset($_POST['generate'])) {
             $this->generate();
         } else {
             $this->export();
         }
     }
     // load acf scripts
     acf_enqueue_scripts();
 }
Example #4
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // set currrent
     $this->view['slug'] = $plugin_page;
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id('options');
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(admin_url("admin.php?page={$plugin_page}&message=1"));
             exit;
         }
     }
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
 }
Example #5
0
 function save_comment($comment_id)
 {
     // bail early if not valid nonce
     if (!acf_verify_nonce('comment')) {
         return $comment_id;
     }
     // validate and save
     if (acf_validate_save_post(true)) {
         acf_save_post("comment_{$comment_id}");
     }
 }
Example #6
0
 function save_widget()
 {
     // bail early if no nonce
     if (!acf_verify_nonce('widget')) {
         return;
     }
     // vars
     $id = acf_maybe_get($_POST, 'widget-id');
     // save data
     if ($id && acf_validate_save_post()) {
         acf_save_post("widget_{$id}");
     }
 }
Example #7
0
 function save_widget($instance, $new_instance, $old_instance, $widget)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('widget')) {
         return $instance;
     }
     // save data
     if (acf_validate_save_post()) {
         acf_save_post("widget_{$widget->id}");
     }
     // return
     return $instance;
 }
Example #8
0
function acf_form_head()
{
    // verify nonce
    if (acf_verify_nonce('acf_form')) {
        // validate data
        if (acf_validate_save_post(true)) {
            // form
            $GLOBALS['acf_form'] = acf_extract_var($_POST, '_acf_form');
            $GLOBALS['acf_form'] = @json_decode(base64_decode($GLOBALS['acf_form']), true);
            // validate
            if (empty($GLOBALS['acf_form'])) {
                return;
            }
            // vars
            $post_id = acf_maybe_get($GLOBALS['acf_form'], 'post_id', 0);
            // allow for custom save
            $post_id = apply_filters('acf/pre_save_post', $post_id, $GLOBALS['acf_form']);
            // save
            acf_save_post($post_id);
            // vars
            $return = acf_maybe_get($GLOBALS['acf_form'], 'return', '');
            // redirect
            if ($return) {
                // update %placeholders%
                $return = str_replace('%post_url%', get_permalink($post_id), $return);
                // redirect
                wp_redirect($return);
                exit;
            }
        }
        // if
    }
    // if
    // load acf scripts
    acf_enqueue_scripts();
}
 function load()
 {
     // $_POST
     if (acf_verify_nonce('activate_pro_licence')) {
         $this->activate_pro_licence();
     } elseif (acf_verify_nonce('deactivate_pro_licence')) {
         $this->deactivate_pro_licence();
     }
     // view
     $this->view = array('license' => '', 'active' => 0, 'current_version' => acf_get_setting('version'), 'remote_version' => '', 'update_available' => false, 'changelog' => '', 'upgrade_notice' => '');
     // license
     if (acf_pro_is_license_active()) {
         $this->view['license'] = acf_pro_get_license();
         $this->view['active'] = 1;
     }
     // vars
     $info = acf_pro_get_remote_info();
     // validate
     if (empty($info)) {
         acf_add_admin_notice(__('<b>Error</b>. Could not connect to update server', 'acf'), 'error');
         return;
     }
     // add info to view
     $this->view['remote_version'] = $info['version'];
     // add changelog if the remote version is '>' than the current version
     if (acf_pro_is_update_available()) {
         $this->view['update_available'] = true;
         // changelog
         $changelogs = explode('<h4>', $info['changelog']);
         foreach ($changelogs as $changelog) {
             // validate (first segment is always empty due to explode)
             if (empty($changelog)) {
                 continue;
             }
             // explode
             $changelog = explode('</h4>', $changelog);
             $changelog_version = trim($changelog[0]);
             $changelog_text = trim($changelog[1]);
             $changelog_text = str_replace('<ul>', '<ul class="ul-disc">', $changelog_text);
             if (version_compare($this->view['remote_version'], $changelog_version, '==')) {
                 $this->view['changelog'] = $changelog_text;
                 break;
             }
         }
         // upgrade_notice
         $upgrade_notices = explode('<h4>', $info['upgrade_notice']);
         foreach ($upgrade_notices as $upgrade_notice) {
             // validate (first segment is always empty due to explode)
             if (empty($upgrade_notice)) {
                 continue;
             }
             // explode
             $upgrade_notice = explode('</h4>', $upgrade_notice);
             $upgrade_version = trim($upgrade_notice[0]);
             $upgrade_text = trim($upgrade_notice[1]);
             $upgrade_text = str_replace('<ul>', '<ul class="ul-disc">', $upgrade_text);
             if (version_compare($this->view['current_version'], $upgrade_version, '<')) {
                 $this->view['upgrade_notice'] = $upgrade_text;
                 break;
             }
         }
     }
 }
Example #10
0
 function save_term($term_id, $tt_id, $taxonomy)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('taxonomy')) {
         return $term_id;
     }
     // valied and show errors
     acf_validate_save_post(true);
     // save
     acf_save_post('term_' . $term_id);
 }
Example #11
0
function acf_form_head()
{
    // verify nonce
    if (acf_verify_nonce('acf_form')) {
        // validate data
        if (acf_validate_save_post(true)) {
            // form
            $form = acf_extract_var($_POST, '_acf_form');
            $form = @json_decode(base64_decode($form), true);
            // validate
            if (empty($form)) {
                return;
            }
            // allow for custom save
            $form['post_id'] = apply_filters('acf/pre_save_post', $form['post_id'], $form);
            // save
            acf_save_post($form['post_id']);
            // redirect
            if (!empty($form['return'])) {
                // update %placeholders%
                $form['return'] = str_replace('%post_url%', get_permalink($form['post_id']), $form['return']);
                // redirect
                wp_redirect($form['return']);
                exit;
            }
        }
        // if
    }
    // if
    // load acf scripts
    acf_enqueue_scripts();
}
Example #12
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // vars
     $this->page = acf_get_options_page($plugin_page);
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id($this->page['post_id']);
             // set autoload
             acf_update_setting('autoload', $this->page['autoload']);
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(admin_url("admin.php?page={$plugin_page}&message=1"));
             exit;
         }
     }
     // actions
     add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
 }
Example #13
0
 function widget_update_callback($instance, $new_instance, $old_instance, $widget)
 {
     // bail early if empty
     if (empty($_POST['acf'])) {
         return $instance;
     }
     // bail early if no nonce
     if (!acf_verify_nonce('widget')) {
         return $instance;
     }
     // customizer autosave preview
     if (!empty($_POST['wp_customize'])) {
         return $this->customizer_widget_update_callback($instance, $new_instance, $old_instance, $widget);
     }
     // bail early if not valid
     if (!acf_validate_save_post()) {
         return $instance;
     }
     // save
     acf_save_post("widget_{$widget->id}");
     // return
     return $instance;
 }
Example #14
0
 function save_post($post_id, $post)
 {
     // bail ealry if no allowed to save this post type
     if (!$this->allow_save_post($post)) {
         return $post_id;
     }
     // ensure saving to the correct post
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate for published post (allow draft to save without validation)
     if (get_post_status($post_id) == 'publish') {
         // show errors
         acf_validate_save_post(true);
     }
     // save
     acf_save_post($post_id);
     // return
     return $post_id;
 }
Example #15
0
 function save_post($post_id, $post)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // bail early if not acf-field-group
     if ($post->post_type !== 'acf-field-group') {
         return $post_id;
     }
     // only save once! WordPress save's a revision as well.
     if (wp_is_post_revision($post_id)) {
         return $post_id;
     }
     // verify nonce
     if (!acf_verify_nonce('field_group')) {
         return $post_id;
     }
     // disable filters to ensure ACF loads raw data from DB
     acf_disable_filters();
     // save fields
     if (!empty($_POST['acf_fields'])) {
         foreach ($_POST['acf_fields'] as $field) {
             // vars
             $specific = false;
             $save = acf_extract_var($field, 'save');
             // only saved field if has changed
             if ($save == 'meta') {
                 $specific = array('menu_order', 'post_parent');
             }
             // set field parent
             if (empty($field['parent'])) {
                 $field['parent'] = $post_id;
             }
             // save field
             acf_update_field($field, $specific);
         }
     }
     // delete fields
     if ($_POST['_acf_delete_fields']) {
         // clean
         $ids = explode('|', $_POST['_acf_delete_fields']);
         $ids = array_map('intval', $ids);
         // loop
         foreach ($ids as $id) {
             // bai early if no id
             if (!$id) {
                 continue;
             }
             // delete
             acf_delete_field($id);
         }
     }
     // add args
     $_POST['acf_field_group']['ID'] = $post_id;
     $_POST['acf_field_group']['title'] = $_POST['post_title'];
     // save field group
     acf_update_field_group($_POST['acf_field_group']);
     // return
     return $post_id;
 }
Example #16
0
 function save_post($post_id)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // verify and remove nonce
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate and save
     if (get_post_status($post_id) == 'publish') {
         if (acf_validate_save_post(true)) {
             acf_save_post($post_id);
         }
     } else {
         acf_save_post($post_id);
     }
     // return
     return $post_id;
 }
Example #17
0
 function save_term($term_id, $tt_id, $taxonomy)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('taxonomy')) {
         return $term_id;
     }
     // save data
     if (acf_validate_save_post(true)) {
         acf_save_post("{$taxonomy}_{$term_id}");
     }
 }
Example #18
0
 function save_post($post_id, $post)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // bail early if is acf-field-group or acf-field
     if (in_array($post->post_type, array('acf-field', 'acf-field-group'))) {
         return $post_id;
     }
     // verify and remove nonce
     if (!acf_verify_nonce('post', $post_id)) {
         return $post_id;
     }
     // validate and save
     if (get_post_status($post_id) == 'publish') {
         if (acf_validate_save_post(true)) {
             acf_save_post($post_id);
         }
     } else {
         acf_save_post($post_id);
     }
     // return
     return $post_id;
 }
Example #19
0
 function save_attachment($post, $attachment)
 {
     // bail early if not valid nonce
     if (!acf_verify_nonce('attachment')) {
         return $post;
     }
     // validate and save
     if (acf_validate_save_post(true)) {
         acf_save_post($post['ID']);
     }
     // return
     return $post;
 }
 function load()
 {
     // $_POST
     if (acf_verify_nonce('activate_pro_licence')) {
         $this->activate_pro_licence();
     } elseif (acf_verify_nonce('deactivate_pro_licence')) {
         $this->deactivate_pro_licence();
     }
     // view
     $this->view = array('license' => '', 'active' => 0, 'current_version' => acf_get_setting('version'), 'remote_version' => '', 'update_available' => false, 'changelog' => '', 'upgrade_notice' => '');
     // license
     if (acf_pro_is_license_active()) {
         $this->view['license'] = acf_pro_get_license_key();
         $this->view['active'] = 1;
     }
     // vars
     $info = acf_get_remote_plugin_info();
     // validate
     if (empty($info)) {
         return $this->show_remote_response_error();
     }
     // add info to view
     $this->view['remote_version'] = $info['version'];
     // add changelog if the remote version is '>' than the current version
     if (acf_pro_is_update_available()) {
         $this->view['update_available'] = true;
         $this->view['changelog'] = acf_maybe_get($info, 'changelog');
         $this->view['upgrade_notice'] = acf_maybe_get($info, 'upgrade_notice');
     }
     // update transient
     acf_refresh_plugin_updates_transient();
 }
Example #21
0
 function widget_update_callback($instance, $new_instance, $old_instance, $widget)
 {
     // bail early if no nonce
     if (!acf_verify_nonce('widget')) {
         return $instance;
     }
     // save
     if (acf_validate_save_post()) {
         acf_save_post("widget_{$widget->id}");
     }
     // return
     return $instance;
 }
Example #22
0
 function save_user($user_id)
 {
     // verify and remove nonce
     if (!acf_verify_nonce('user')) {
         return $user_id;
     }
     // save data
     if (acf_validate_save_post(true)) {
         acf_save_post("user_{$user_id}");
     }
 }
Example #23
0
 function save_post($post_id)
 {
     // do not save if this is an auto save routine
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // only save once! WordPress save's a revision as well.
     if (wp_is_post_revision($post_id)) {
         return $post_id;
     }
     // verify nonce
     if (!acf_verify_nonce('field_group')) {
         return $post_id;
     }
     // disable local to avoid conflicts between DB and local
     acf_disable_local();
     // save fields
     unset($_POST['acf_fields']['acfcloneindex']);
     if (!empty($_POST['acf_fields'])) {
         foreach ($_POST['acf_fields'] as $field) {
             // vars
             $specific = false;
             $save = acf_extract_var($field, 'save');
             // only saved field if has changed
             if ($save == 'meta') {
                 $specific = array('menu_order', 'post_parent');
             }
             // set field parent
             if (empty($field['parent'])) {
                 $field['parent'] = $post_id;
             }
             // save field
             acf_update_field($field, $specific);
         }
     }
     // delete fields
     if ($_POST['_acf_delete_fields']) {
         $ids = explode('|', $_POST['_acf_delete_fields']);
         $ids = array_map('intval', $ids);
         foreach ($ids as $id) {
             if ($id != 0) {
                 acf_delete_field($id);
             }
         }
     }
     // add args
     $_POST['acf_field_group']['ID'] = $post_id;
     $_POST['acf_field_group']['title'] = $_POST['post_title'];
     // save field group
     acf_update_field_group($_POST['acf_field_group']);
     // return
     return $post_id;
 }
Example #24
0
 function admin_load()
 {
     // globals
     global $plugin_page;
     // vars
     $this->page = acf_get_options_page($plugin_page);
     // verify and remove nonce
     if (acf_verify_nonce('options')) {
         // save data
         if (acf_validate_save_post(true)) {
             // get post_id (allow lang modification)
             $post_id = acf_get_valid_post_id($this->page['post_id']);
             // set autoload
             acf_update_setting('autoload', $this->page['autoload']);
             // save
             acf_save_post($post_id);
             // redirect
             wp_redirect(add_query_arg(array('message' => '1')));
             exit;
         }
     }
     // load acf scripts
     acf_enqueue_scripts();
     // actions
     add_action('acf/input/admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
     add_action('acf/input/admin_head', array($this, 'admin_head'));
     // add columns support
     add_screen_option('layout_columns', array('max' => 2, 'default' => 2));
 }