本文整理汇总了PHP中acf_add_admin_notice函数的典型用法代码示例。如果您正苦于以下问题:PHP acf_add_admin_notice函数的具体用法?PHP acf_add_admin_notice怎么用?PHP acf_add_admin_notice使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了acf_add_admin_notice函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
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);
}
}
示例2: generate
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;
}
示例3: check_sync
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'));
}
示例4: deactivate_pro_licence
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);
}
}
示例5: admin_head
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
}
示例6: check_duplicate
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;
}
}
示例7: importFields
/**
* 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.");
}
//.........这里部分代码省略.........
示例8: generate
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;
}
示例9: html
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
//.........这里部分代码省略.........
示例10: generate
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;
}
示例11: acf_pro_is_license_active
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;
}
示例12: admin_head
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
}
示例13: generate
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;
}