Hello,
I have some new problems, I hope you can help me to learn how to do that properly.
1. I have registered new fields for rows options, but I’m not sure it’s written properly, because in function I have one big object with $field[‘aos_animation’], and the next fields are located inside this object. It’s working good, but… should this be the case?
function custom_row_style_fields($fields) {
$fields['aos_animation'] = array(
'name' => __('AOS Animation', 'siteorigin-panels'),
'type' => 'select',
'options' => array (
'fade',
'fade-up'
),
'group' => 'design',
'priority' => 11,
$fields['aos_anchor'] = array(
'name' => __('AOS Anchor placement', 'siteorigin-panels'),
'type' => 'select',
'options' => array (
'top-bottom',
'top-center'
),
'group' => 'design',
'priority' => 12,
),
$fields['aos_ease'] = array(
'name' => __('AOS Easing function', 'siteorigin-panels'),
'type' => 'select',
'options' => array (
'linear',
'ease',
),
'group' => 'design',
'priority' => 13,
),
);
return $fields;
}
add_filter( 'siteorigin_panels_row_style_fields', 'custom_row_style_fields' );
add_action('plugins_loaded', 'custom_row_style_fields');2. Second question is simple: can I add new fields (and attributes to its html elements) to the widgets or/and for single cells in rows? How?
3. And the last, and most important problem:
I try to register new data- attributes. When I using example code from docs – its working great. But I need to get value of ‘select’ input, and register new atrribute. I tried to do that with code below:
function custom_row_style_attributes( $attributes, $args ) {
if( !empty( $args['aos_animation'] ) ) {
array_push($attributes['data-aos'] = $args['aos_animation']);
}
return $attributes;
}
add_filter('siteorigin_panels_row_style_attributes', 'custom_row_style_attributes', 10, 2);
add_action('plugins_loaded', 'custom_row_style_attributes');
I think that problems are due to my ignorance about PHP, but I still learning :P
I would be very grateful for your help.
Thank :)
Hi Paweł,
1. I don’t see any issues with the PHP you’re using to add custom row styles. I’m not too sure why you’ve added the following though:
add_action('plugins_loaded', 'custom_row_style_fields');2. You can add additional styles for widgets and styles by using their respective filter – siteorigin_panels_cell_style_fields and siteorigin_panels_widget_style_fields. These filters work in the same manner as siteorigin_panels_row_style_fields.
3. $attributes is an array and each array item is an array key (attribute name) and string (attribute value). You’re using array_push incorrectly and it’s not something I would recommend using in this instance – remove it and just use what you’re trying to push.