Thanks John, the filter acf/load_field
was a better approach. I’m working on the rest of the script.
@hube2 Yes, dividing into more page options would be my solution, but now I choose to use kirki that is a tool more friendly to users, it uses Theme Customizer API for this kind of task.
Thanks for the information guys!
No, this doesn’t work, in my tests some Select fields inside a Repeater changed their settings when updating the group. As a Theme Options page can be very large in options to customize a theme, I will change to another solution more specific for this situation and use ACF to small forms only. Thank you James!
The same field on settings could be done to Synchronized JSON option too. Or maybe join both in a single select option like:
Local JSON:
– Yes and Synchronize (private => false)
– Yes but don’t Synchronize (private => true)
– No (do not export)
One idea to automate, for each layout you can start with a field labeled “Admin Title” and name it as “layout_title”, then you use this function on your theme functions.php
.
function my_layout_title($title, $field, $layout, $i) {
if($value = get_sub_field('layout_title')) {
return $value;
} else {
foreach($layout['sub_fields'] as $sub) {
if($sub['name'] == 'layout_title') {
$key = $sub['key'];
if(array_key_exists($i, $field['value']) && $value = $field['value'][$i][$key])
return $value;
}
}
}
return $title;
}
add_filter('acf/fields/flexible_content/layout_title', 'my_layout_title'), 10, 4);
This hook was added, but I didn’t tested yet.
https://www.advancedcustomfields.com/resources/acf-fields-flexible_content-layout_title/
I built this function to use in my projects. I think it gets a little bit easier to edit without the distraction of many elements opened at the same time. The list is focused in order the elements and the edit button works with the content.
Download the plugin to test, the idea to create the modal is just using CSS, not moving the html content to the modal!
https://wordpress.org/plugins/acf-flexible-content-modal/
Good idea to automate! I just would use “termmeta_” as the prefix, makes it more reliable to avoid mistakes and put the filter after check field name.
function ...( $value, $post_id, $field ) {
if( strpos( $field['name'], 'termmeta_' ) === 0 ) {
$term_id = intval( filter_var( $post_id, FILTER_SANITIZE_NUMBER_INT ) );
if( $term_id > 0 )
[...]
}
return $value;
}
I was looking through the code to implement this and got this idea. The screen has a new button near the name, this button uses the JS prompt()
command to get the name and save this as a hidden field for the element:
<input name="acf[field_55c66a077308e][56b8f273a6d03][acf_fc_layout]" value="colunas" type="hidden">
<input name="acf[field_55c66a077308e][56b8f273a6d03][acf_fc_title]" value="My description" type="hidden">
If the returned text from prompt()
is blank, it will return to the original name. The other good thing to do, could be putting a button on top of the sortable elements to collapse all.
This is difficult because @media works only with screen size and not element size and WordPress interface has columns. I don’t want to use JavaScript to make this much pretty, so I just used the screen size 782px that is the WP mobile setup. And the number of columns will depend in how large the text is on each option too. It’s not perfect but it works in most of my situations.
Maybe Checkbox and Radio Columns could be implemented too :-p
@elliot, thanks for your attention.
I found a bug in my framework. Now it’s working better.
But I have to check something, just tell me if this is expected. I installed ACF and Options Page as a plugin to test and this is in functions.php
theme.
acf_add_options_sub_page(array(
'title' => 'Test',
'slug' => 'acf-options-module-test',
'parent' => 'options-general.php',
'capability' => 'manage_options'
));
register_field_group(array (
'id' => 'acf_module_test_options',
'title' => 'Module Test',
'fields' => array (
array (
'key' => 'field_module_test_value',
'label' => 'Test',
'name' => 'module_test_value',
'type' => 'text',
'default_value' => 'default value',
)
),
'location' => array (
array (
array (
'param' => 'options_page',
'operator' => '==',
'value' => 'acf-options-module-test',
'order_no' => 0,
'group_no' => 0,
),
),
),
'options' => array (
'position' => 'normal',
'layout' => 'no_box',
'hide_on_screen' => array (
),
),
'menu_order' => 0,
));
function get_value() {
var_dump(get_field('module_test_value', 'option'));
}
get_value(); // don't get value
add_action('init', 'get_value'); // get value
function test_init() {
acf_add_options_sub_page(array(
'title' => 'SEO',
'slug' => 'acf-options-module-seo',
'parent' => 'options-general.php',
'capability' => 'manage_options'
));
}
add_action('init', 'test_init');
I’m using this to load the module before ACF and their add-ons has completely loaded.
Forget about the topic, ACF installed into Theme is working fine.
The bug I found here was in the add-on Options Page, it doesn’t show up the title of the page. Looking into the file, at line 275 you have add_submenu_page() and get $page[‘menu’], but at the array, there is no such key.
Founded! No error when insert ACF into theme, it was me, the error is only on Options Page add-on @elliot.
On acf-options-page.php line 275, there is no $page[‘menu’], instead is $page[‘title’].
Maybe a migration tool can be difficult to implement, but looking at ACF, the possible solution to this could be implementing a function just to recheck the fields inside each group and make corrections on metadata. A button on the page that list the groups could start this tool.
Workflow to migrate content could be:
This is my idea, I want to listen your opinion, maybe you already have a simple solution to this.
I see that and you could change the function you use to that one:
load_textdomain('acf', dirname(__FILE__) . '/lang/acf-' . get_locale() . '.mo');
I made a small change on the plugin and sent it to you. Fell free to use if you like.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.