function load() { // vars $this->view = array('json' => array()); // load json $request = wp_remote_post('http://assets.advancedcustomfields.com/add-ons/add-ons.json'); // validate if (is_wp_error($request) || wp_remote_retrieve_response_code($request) != 200) { acf_add_admin_notice(__('<b>Error</b>. Could not load add-ons list', 'acf'), 'error'); } else { $this->view['json'] = json_decode($request['body'], true); } }
function generate() { // vars $json = $this->get_json(); // validate if ($json === false) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // update view $this->view = 'settings-tools-export'; $this->data['field_groups'] = $json; }
function check_sync() { // message if ($ids = acf_maybe_get($_GET, 'acfsynccomplete')) { // explode $ids = explode(',', $ids); $total = count($ids); if ($total == 1) { acf_add_admin_notice(sprintf(__('Field group synchronised. %s', 'acf'), '<a href="' . get_edit_post_link($ids[0]) . '">' . get_the_title($ids[0]) . '</a>')); } else { acf_add_admin_notice(sprintf(_n('%s field group synchronised.', '%s field groups synchronised.', $total, 'acf'), $total)); } } // vars $groups = acf_get_field_groups(); // bail early if no field groups if (empty($groups)) { return; } // find JSON field groups which have not yet been imported foreach ($groups as $group) { // vars $local = acf_maybe_get($group, 'local', false); $modified = acf_maybe_get($group, 'modified', 0); $private = acf_maybe_get($group, 'private', false); // ignore DB / PHP / private field groups if ($local !== 'json' || $private) { // do nothing } elseif (!$group['ID']) { $this->sync[$group['key']] = $group; } elseif ($modified && $modified > get_post_modified_time('U', true, $group['ID'], true)) { $this->sync[$group['key']] = $group; } } // bail if no sync needed if (empty($this->sync)) { return; } // import field group if ($key = acf_maybe_get($_GET, 'acfsync')) { // disable JSON // - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance acf_update_setting('json', false); // validate check_admin_referer('bulk-posts'); // append fields if (acf_have_local_fields($key)) { $this->sync[$key]['fields'] = acf_get_local_fields($key); } // import $field_group = acf_import_field_group($this->sync[$key]); // redirect wp_redirect(admin_url($this->url . '&acfsynccomplete=' . $field_group['ID'])); exit; } elseif (acf_maybe_get($_GET, 'action2') === 'acfsync') { // validate check_admin_referer('bulk-posts'); // get ids $keys = acf_maybe_get($_GET, 'post'); if (!empty($keys)) { // disable JSON // - this prevents a new JSON file being created and causing a 'change' to theme files - solves git anoyance acf_update_setting('json', false); // vars $new_ids = array(); foreach ($keys as $key) { // append fields if (acf_have_local_fields($key)) { $this->sync[$key]['fields'] = acf_get_local_fields($key); } // import $field_group = acf_import_field_group($this->sync[$key]); // append $new_ids[] = $field_group['ID']; } // redirect wp_redirect(admin_url($this->url . '&acfsynccomplete=' . implode(',', $new_ids))); exit; } } // filters add_filter('views_edit-acf-field-group', array($this, 'list_table_views')); }
function deactivate_pro_licence() { // validate if (!acf_pro_is_license_active()) { return; } // connect $args = array('_nonce' => wp_create_nonce('deactivate_pro_licence'), 'acf_license' => acf_pro_get_license(), 'wp_url' => home_url()); // connect $response = acf_pro_get_remote_response('deactivate-license', $args); // validate if (empty($response)) { acf_add_admin_notice(__('<b>Connection Error</b>. Sorry, please try again', 'acf'), 'error'); return; } // vars $response = json_decode($response, true); $class = ''; // allways clear DB acf_pro_update_license(''); // action if ($response['status'] == 1) { } else { $class = 'error'; } // show message if ($response['message']) { acf_add_admin_notice($response['message'], $class); } }
function admin_head() { // get field groups $field_groups = acf_get_field_groups(array('options_page' => $this->view['slug'])); // notices if (!empty($_GET['message']) && $_GET['message'] == '1') { acf_add_admin_notice(__("Options Updated", 'acf')); } if (empty($field_groups)) { $this->view['have_fields'] = 0; acf_add_admin_notice(__("No Custom Field Groups found for this options page", 'acf') . '. <a href="' . admin_url() . 'post-new.php?post_type=acf-field-group">' . __("Create a Custom Field Group", 'acf') . '</a>', 'error'); } else { foreach ($field_groups as $i => $field_group) { // vars $id = "acf-{$field_group['key']}"; $title = $field_group['title']; $context = $field_group['position']; $priority = 'high'; $args = array('field_group' => $field_group); // tweaks to vars if ($context == 'acf_after_title') { $context = 'normal'; } elseif ($context == 'side') { $priority = 'core'; } // filter for 3rd party customization $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group); // add meta box add_meta_box($id, $title, array($this, 'render_meta_box'), 'acf_options_page', $context, $priority, $args); } // foreach } // if }
function check_duplicate() { // message if (!empty($_GET['duplicate_complete'])) { // vars $id = filter_var($_GET['duplicate_complete'], FILTER_SANITIZE_NUMBER_INT); $message = __('Field group duplicated! Edit the new "%s" field group.', 'acf'); $message = sprintf($message, '<a href="' . get_edit_post_link($id) . '">' . get_the_title($id) . '</a>'); // message acf_add_admin_notice($message); } // duplicate if (!empty($_GET['duplicate'])) { // vars $id = filter_var($_GET['duplicate'], FILTER_SANITIZE_NUMBER_INT); // duplciate $field_group = acf_duplicate_field_group($id); // redirect so the $_GET param is not visible to user wp_redirect(admin_url("edit.php?post_type=acf-field-group&duplicate_complete={$field_group['ID']}")); exit; } }
/** * An altered version of acf/admin/settings-tool.php::import() * * ACF's import function takes care of most things, but this * function makes up for what it lacks: * * - Removes fields that are in the DB, but not in the import file * - Removes field groups that are in the DB, but not in the import file * - Updates fields that have changed * - Displays command-line messages * * @return null */ protected function importFields() { // validate if (empty($_FILES['acf_import_file'])) { acf_add_admin_notice(__("No file selected", 'acf'), 'error'); return; } // vars $file = $_FILES['acf_import_file']; // validate error if ($file['error']) { acf_add_admin_notice(__('Error uploading file. Please try again', 'acf'), 'error'); return; } // validate type if (pathinfo($file['name'], PATHINFO_EXTENSION) !== 'json') { acf_add_admin_notice(__('Incorrect file type', 'acf'), 'error'); return; } // read file $json = file_get_contents($file['tmp_name']); // decode json $json = json_decode($json, true); // validate json if (empty($json)) { acf_add_admin_notice(__('Import file empty', 'acf'), 'error'); return; } // if importing an auto-json, wrap field group in array if (isset($json['key'])) { $json = array($json); } // vars $added = array(); $deletedgroups = array(); $deletedfields = array(); $ref = array(); $order = array(); $allgroups = $this->getFieldGroups(); $allfields = $this->getFields(); foreach ($json as $field_group) { $update = false; // check if field group exists if ($post = acf_get_field_group($field_group['key'], true)) { // \WP_CLI::log($field_group['title'] . " group already exists. Updating."); // add ID to trigger update instead of insert $field_group["ID"] = $post["ID"]; $update = true; // } else { // \WP_CLI::log($field_group['title'] . " group is new. Adding."); } // remove fields $fields = acf_extract_var($field_group, 'fields'); // format fields $fields = acf_prepare_fields_for_import($fields); // save field group $field_group = acf_update_field_group($field_group); // remove group from $allgroups array if (isset($allgroups[$field_group['ID']])) { unset($allgroups[$field_group['ID']]); } // add to ref $ref[$field_group['key']] = $field_group['ID']; // add to order $order[$field_group['ID']] = 0; // add fields foreach ($fields as $field) { // add parent if (empty($field['parent'])) { $field['parent'] = $field_group['ID']; } elseif (isset($ref[$field['parent']])) { $field['parent'] = $ref[$field['parent']]; } // add field menu_order if (!isset($order[$field['parent']])) { $order[$field['parent']] = 0; } $field['menu_order'] = $order[$field['parent']]; $order[$field['parent']]++; // add ID if the field already exists if ($post = acf_get_field($field['key'], true)) { // add ID to trigger update instead of insert $field["ID"] = $post["ID"]; // \WP_CLI::log($field_group['title'] . "->" . $field['label'] . " field already exists. Updating."); // } else { // \WP_CLI::log($field_group['title'] . "->" . $field['label'] . " field is new. Adding."); } // save field $field = acf_update_field($field); // remove field from allfields array if (isset($allfields[$field['ID']])) { unset($allfields[$field['ID']]); } // add to ref $ref[$field['key']] = $field['ID']; } if ($update) { \WP_CLI::success($field_group['title'] . " field group updated."); } else { \WP_CLI::success($field_group['title'] . " field group added."); } } if (!empty($allgroups)) { foreach ($allgroups as $post) { \WP_CLI::success($post->post_title . " field group deleted."); wp_delete_post($post->ID); } } if (!empty($allfields)) { foreach ($allfields as $post) { \WP_CLI::success($post->post_title . " field deleted."); wp_delete_post($post->ID); } } }
function generate() { // prevent default translation and fake __() within string acf_update_setting('l10n_var_export', true); // vars $json = $this->get_json(); // validate if ($json === false) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // update view $this->view = 'settings-tools-export'; $this->data['field_groups'] = $json; }
static function html($args) { //print_r($_POST); if (isset($_POST) && !empty($_POST)) { return; } if (!function_exists('acf_get_field_groups')) { echo 'You need ACF activated to use this screen'; exit; } /* Todo intercept and update the special key here */ //print_r($json); exit; ?> <div class="wrap acf-settings-wrap"> <h2><?php _e('Import / Export', 'acf'); ?> </h2> <div class="acf-box"> <div class="title"> <h3><?php _e('Generate Your Template Output', 'inboundnow'); ?> </h3> </div> <div class="inner"> <script type="text/javascript"> function replaceUrlParam(url, paramName, paramValue){ var pattern = new RegExp('('+paramName+'=).*?(&|$)') var newUrl=url if(url.search(pattern)>=0){ newUrl = url.replace(pattern,'$1' + paramValue + '$2'); } else{ newUrl = newUrl + (newUrl.indexOf('?')>0 ? '&' : '?') + paramName + '=' + paramValue } return newUrl } jQuery(document).ready(function($) { // put all your jQuery goodness in here. jQuery("#generate_template").on('change', function () { var val = jQuery(this).val(); var newUrl = replaceUrlParam(window.location.href, 'generate-template-id', val); window.location.href = newUrl; }); }); </script> <div id="options-available"> <?php $choices = array('none' => "Choose template"); $field_groups_ids = acf_get_field_groups(); // populate choices if (!empty($field_groups_ids)) { foreach ($field_groups_ids as $field_group) { //print_r($field_group); $choices[$field_group['key']] = $field_group['title']; } } echo "<label>Select the ACF options you wish to generate markup for</label>"; // render field $acf_id = isset($_GET['generate-template-id']) ? $_GET['generate-template-id'] : false; $template_name = isset($_GET['template-name']) ? $_GET['template-name'] : ''; acf_render_field(array('type' => 'select', 'name' => 'generate_template', 'prefix' => false, 'value' => $acf_id, 'toggle' => true, 'choices' => $choices)); acf_render_field(array('type' => 'text', 'name' => 'template_name', 'prefix' => false, 'value' => $template_name, 'placeholder' => "Template Name")); ?> </div> <p>This page is for helping developing templating super simple.</p> <p>This is generated output from your landing page options to copy/paste into your index.php</p> <?php /** * Generate the template here */ /* get the data */ $json = self::get_json(); //print_r($json); // validate if ($json === false || empty($json)) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); exit; } // vars $field_groups = $json; ?> <textarea style="width:100%; height:500px;" class="pre" readonly="true"> <?php echo "<?php\n/**\n* Template Name: __TEMPLATE_NAME__\n* @package WordPress Landing Pages\n* @author Inbound Template Generator\n*/\n\n/* Declare Template Key */\n\$key = basename(dirname(__FILE__));\n\n/* discover the absolute path of where this template is located. Core templates are loacted in /wp-content/plugins/landing-pages/templates/ while custom templates belong in /wp-content/uploads/landing-pages/tempaltes/ */\n\$path = (preg_match(\"/uploads/\", dirname(__FILE__))) ? LANDINGPAGES_UPLOADS_PATH . \$key .'/' : LANDINGPAGES_PATH.'templates/'.\$key.'/';\n\n\$urlpath = (preg_match(\"/uploads/\", dirname(__FILE__))) ? LANDINGPAGES_UPLOADS_URLPATH . \$key .'/' : LANDINGPAGES_URLPATH.'templates/'.\$key.'/';\n\n/* Include ACF Field Definitions */\ninclude_once(\$path .'config.php');\n\n/* Define Landing Pages's custom pre-load hook for 3rd party plugin integration */\ndo_action('wp_head');\n\$post_id = get_the_ID(); "; ?> ?> <?php echo '<!DOCTYPE html> <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]--> <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]--> <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]--> <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]--> <head> <!-- Define page title --> <title><?php wp_title(); ?></title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- include your assets --> <!-- <link rel="stylesheet" href="<?php echo $urlpath; ?>css/css_file_name.css"> --> <!-- <script src="<?php echo $urlpath; ?>js/js_file_name.js"></script> --> <!-- Load Normal WordPress wp_head() function --> <?php wp_head(); ?> <!-- Load Landing Pages\'s custom pre-load hook for 3rd party plugin integration --> <?php do_action("lp_head"); ?> </head>' . "\r\n\r\n" . '<body>' . "\r\n\r\n"; //print_r($field_groups); exit; if (isset($field_groups)) { echo "<?php " . "\r\n\r\n"; foreach ($field_groups as $field_group) { foreach ($field_group['fields'] as $field) { if ($field['type'] === "repeater") { $repeater = self::inbound_repeater_output($field); echo $repeater; } else { if ($field['type'] === "flexible_content") { echo "/* Start " . $field['name'] . " Flexible Content Area Output */" . "\r\n"; echo "\tif(function_exists('have_rows')) :" . "\r\n"; echo "\t\tif(have_rows('" . $field['name'] . "')) :" . "\r\n"; echo "\t\t\t while(have_rows('" . $field['name'] . "')) : the_row();" . "\r\n"; echo "\t\t\t\t switch(get_sub_field('acf_fc_layout')) :" . "\r\n"; foreach ($field['layouts'] as $layout) { //print_r($layout); echo "\t\t\t\t/* start layout " . $layout['name'] . " */" . "\r\n"; echo "\t\t\t\t case '" . $layout['name'] . "' : " . "\r\n"; foreach ($layout['sub_fields'] as $layout_subfield) { if ($layout_subfield['type'] === 'repeater') { $test = self::inbound_repeater_output($layout_subfield, 4, false); echo $test; } else { echo "\t\t\t\t\t\$" . $layout_subfield['name'] . " = " . "get_sub_field(\"" . $layout_subfield['name'] . "\");" . "\r\n"; } } echo "\t\t\t?>" . "\r\n\r\n"; echo "\t\t\t<!-- your markup here -->" . "\r\n\r\n"; echo "\t\t\t<?php break;" . "\r\n"; //echo "\t\t\t\t/* end layout ".$layout['name']." */"."\r\n"; } echo "\t\t\t\tendswitch; /* end switch statement */ " . "\r\n"; echo "\t\t\tendwhile; /* end while statement */" . "\r\n"; echo "\t\t endif; /* end have_rows */" . "\r\n"; echo "\tendif; /* end function_exists */" . "\r\n"; echo "/* End " . $field['name'] . " Flexible Content Area Output */" . "\r\n\r\n"; } else { if ($field['name']) { echo "\t\$" . $field['name'] . " = " . "get_field(\"" . $field['name'] . "\", \$post_id);" . "\r\n"; } } } } } echo "?>" . "\r\n\r\n"; /* break; endwhile; endif; */ echo "<?php " . "\r\n"; echo "do_action('lp_footer');" . "\r\n"; echo "do_action('wp_footer');" . "\r\n"; echo "?>" . "\r\n"; echo "</body>" . "\r\n"; echo "</html>" . "\r\n"; } ?> </textarea> <p>This is the config.php file</p> <?php /* TODO: add config begging output */ ?> <textarea class="pre" readonly="true"><?php echo "if( function_exists('acf_add_local_field_group') ):" . "\r\n" . "\r\n"; foreach ($field_groups as $field_group) { // code $code = var_export($field_group, true); // change double spaces to tabs $code = str_replace(" ", "\t", $code); // correctly formats "=> array(" $code = preg_replace('/([\\t\\r\\n]+?)array/', 'array', $code); // Remove number keys from array $code = preg_replace('/[0-9]+ => array/', 'array', $code); // echo echo "acf_add_local_field_group({$code});" . "\r\n" . "\r\n"; } echo "endif;"; ?> </textarea> </div> </div> </div> <div class="acf-hidden"> <style type="text/css"> textarea.pre { width: 100%; padding: 15px; font-size: 14px; line-height: 1.5em; resize: none; } </style> <script type="text/javascript"> (function($){ var i = 0; $(document).on('click', 'textarea.pre', function(){ if( i == 0 ) { i++; $(this).focus().select(); return false; } }); $(document).on('keyup', 'textarea.pre', function(){ $(this).height( 0 ); $(this).height( this.scrollHeight ); }); $(document).ready(function(){ $('textarea.pre').trigger('keyup'); }); })(jQuery); </script> </div> <?php }
function generate() { // translate if (acf_get_setting('l10n_textdomain')) { // prevent default translation acf_update_setting('l10n_var_export', true); // filters add_filter('acf/prepare_field_group_for_export', array($this, '_translate_field_group')); add_filter('acf/prepare_field_for_export', array($this, '_translate_field')); } // vars $json = $this->get_json(); // validate if ($json === false) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // update view $this->view = 'settings-tools-export'; $this->data['field_groups'] = $json; }
function acf_pro_is_license_active() { // vars $license = acf_pro_get_license(); $url = home_url(); // bail early if empty if (!$license) { return false; } // bail early if no key if (!$license['key']) { return false; } // bail early if url does not match if ($license['url'] !== $url) { // add notice (only once) if (!acf_has_done('acf_pro_is_license_active_notice')) { acf_add_admin_notice(__('Error validating ACF PRO license URL (website does not match). Please re-activate your license', 'acf'), 'error'); } return false; } // return return true; }
function admin_head() { // get field groups $field_groups = acf_get_field_groups(array('options_page' => $this->page['menu_slug'])); // notices if (!empty($_GET['message']) && $_GET['message'] == '1') { acf_add_admin_notice(__("Options Updated", 'acf')); } // add submit div add_meta_box('submitdiv', __('Publish', 'acf'), array($this, 'postbox_submitdiv'), 'acf_options_page', 'side', 'high'); if (empty($field_groups)) { acf_add_admin_notice(sprintf(__('No Custom Field Groups found for this options page. <a href="%s">Create a Custom Field Group</a>', 'acf'), admin_url() . 'post-new.php?post_type=acf-field-group'), 'error'); } else { foreach ($field_groups as $i => $field_group) { // vars $id = "acf-{$field_group['key']}"; $title = $field_group['title']; $context = $field_group['position']; $priority = 'high'; $args = array('field_group' => $field_group); // tweaks to vars if ($context == 'acf_after_title') { $context = 'normal'; } elseif ($context == 'side') { $priority = 'core'; } // filter for 3rd party customization $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group); // add meta box add_meta_box($id, $title, array($this, 'postbox_acf'), 'acf_options_page', $context, $priority, $args); } // foreach } // if }
function generate() { // validate if (empty($_POST['acf_export_keys'])) { acf_add_admin_notice(__("No field groups selected", 'acf'), 'error'); return; } // vars $id_ref = array(); $json = array(); // construct JSON foreach ($_POST['acf_export_keys'] as $key) { // load field group $field_group = acf_get_field_group($key); // validate field group if (empty($field_group)) { continue; } // load fields $fields = acf_get_fields($field_group); // prepare fields $fields = acf_prepare_fields_for_export($fields); // add to field group $field_group['fields'] = $fields; // extract field group ID $id = acf_extract_var($field_group, 'ID'); // add to json array $json[] = $field_group; } // end foreach // update view $this->view = 'settings-export-generate'; $this->data['field_groups'] = $json; }