__('Additional Actions', 'acfe'),
'name' => 'acfe_flexible_add_actions',
'key' => 'acfe_flexible_add_actions',
'instructions' => '' . __('See documentation', 'acfe') . '',
'type' => 'checkbox',
'default_value' => '',
'layout' => 'horizontal',
'choices' => $choices,
'conditional_logic' => array(
array(
array(
'field' => 'acfe_flexible_advanced',
'operator' => '==',
'value' => '1',
),
)
)
));
acf_render_field_setting($field, array(
'label' => '',
'name' => 'acfe_flexible_close_button_label',
'key' => 'acfe_flexible_close_button_label',
'instructions' => '',
'type' => 'text',
'default_value' => '',
'prepend' => __('Close Label', 'acfe'),
'placeholder' => __('Close', 'acfe'),
'conditional_logic' => array(
array(
array(
'field' => 'acfe_flexible_advanced',
'operator' => '==',
'value' => '1',
),
array(
'field' => 'acfe_flexible_add_actions',
'operator' => '==',
'value' => 'close',
),
)
)
));
}
/**
* wrapper_attributes
*
* acfe/flexible/wrapper_attributes
*
* @param $wrapper
* @param $field
*
* @return mixed
*/
function wrapper_attributes($wrapper, $field){
$actions = $field['acfe_flexible_add_actions'];
// copy/paste
if(in_array('copy', $actions)){
$wrapper['data-acfe-flexible-copy-paste'] = 1;
}
// lock
if(in_array('lock', $actions)){
$lock = true;
$lock = apply_filters("acfe/flexible/lock", $lock, $field);
$lock = apply_filters("acfe/flexible/lock/name={$field['_name']}", $lock, $field);
$lock = apply_filters("acfe/flexible/lock/key={$field['key']}", $lock, $field);
if($lock){
$wrapper['data-acfe-flexible-lock'] = 1;
}
}
// close
if(in_array('close', $actions)){
$wrapper['data-acfe-flexible-close-button'] = 1;
}
return $wrapper;
}
/**
* layout_icons
*
* acfe/flexible/layouts/icons
*
* @param $icons
* @param $layout
* @param $field
*
* @return mixed
*/
function layout_icons($icons, $layout, $field){
$actions = $field['acfe_flexible_add_actions'];
// copy/paste
if(in_array('copy', $actions)){
// default icons
if(acfe_is_acf('6.5')){
// try to insert after 'add' icon
if(isset($icons['add'])){
$icons = acfe_after($icons, 'add', array(
'copy' => ''
));
// otherwise, prepend it at the beginning
}else{
$icons = acfe_prepend($icons, array(
'copy' => '',
));
}
}else{
$icons = acfe_prepend($icons, array(
'copy' => ''
));
}
}
// clone
if(in_array('clone', $actions)){
// pre ACF 5.9
if(!acfe_is_acf('5.9')){
$icons = acfe_append($icons, array(
'clone' => ''
));
}
}
return $icons;
}
/**
* action_buttons
*
* @param $buttons
* @param $field
* @param $position
*
* @return void
*/
function action_buttons($buttons, $field, $position){
// check settings
if(!in_array('copy', $field['acfe_flexible_add_actions'])){
return $buttons;
}
// add button has been removed
if(!isset($buttons['add'])){
return $buttons;
}
// vars
$name = $field['_name'];
$key = $field['key'];
// secondary buttons
$secondary_buttons = $this->get_secondary_buttons($field);
if(empty($secondary_buttons)){
return $buttons;
}
// button
$button = array(
'href' => '#',
'class' => 'acf-button button',
'data-name' => 'acfe-secondary-actions',
);
// hooks
$button = apply_filters("acfe/flexible/action_button_secondary", $button, $field);
$button = apply_filters("acfe/flexible/action_button_secondary/name={$name}", $button, $field);
$button = apply_filters("acfe/flexible/action_button_secondary/key={$key}", $button, $field);
// add button
$buttons['secondary'] = '';
// return
return $buttons;
}
/**
* secondary_actions
*
* acfe/flexible/secondary_actions
*
* @param $actions
* @param $field
*
* @return mixed
*/
function secondary_actions($actions, $field){
if(!in_array('copy', $field['acfe_flexible_add_actions'])){
return $actions;
}
$actions['copy'] = '' . __('Copy layouts', 'acfe') . '';
$actions['paste'] = '' . __('Paste layouts', 'acfe') . '';
return $actions;
}
/**
* render_popup_secondary_actions
*
* @param $field
*
* @return void
*/
function render_popup_secondary_actions($field){
// secondary buttons
$secondary_buttons = $this->get_secondary_buttons($field);
if(empty($secondary_buttons)){
return;
}
echo '';
}
/**
* get_secondary_buttons
*
* @param $field
*
* @return mixed|null
*/
function get_secondary_buttons($field){
// vars
$name = $field['_name'];
$key = $field['key'];
// secondary buttons
$buttons = array();
$buttons = apply_filters("acfe/flexible/secondary_actions", $buttons, $field);
$buttons = apply_filters("acfe/flexible/secondary_actions/name={$name}", $buttons, $field);
$buttons = apply_filters("acfe/flexible/secondary_actions/key={$key}", $buttons, $field);
return $buttons;
}
}
acf_new_instance('acfe_field_flexible_content_actions');
endif;