1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
<?php
namespace SIW\Page_Builder;
class Visibility {
public static function init() {
if ( ! class_exists( '\SiteOrigin_Panels' ) ) {
return;
}
$self = new self();
add_filter( 'siteorigin_panels_widget_style_groups', [ $self, 'add_style_group'] );
add_filter( 'siteorigin_panels_cell_style_groups', [ $self, 'add_style_group'] );
add_filter( 'siteorigin_panels_row_style_groups', [ $self, 'add_style_group'] );
add_filter( 'siteorigin_panels_widget_style_fields', [ $self, 'add_style_fields'] );
add_filter( 'siteorigin_panels_cell_style_fields', [ $self, 'add_style_fields'] );
add_filter( 'siteorigin_panels_row_style_fields', [ $self, 'add_style_fields'] );
add_filter( 'siteorigin_panels_widget_style_attributes', [ $self, 'add_style_attributes'], 10, 2 );
add_filter( 'siteorigin_panels_cell_style_attributes', [ $self, 'add_style_attributes'], 10, 2 );
add_filter( 'siteorigin_panels_row_style_attributes', [ $self, 'add_style_attributes'], 10, 2 );
}
public function add_style_group( array $groups ) {
$groups['siw-visibility'] = [
'name' => __( 'Zichtbaarheid', 'siw' ),
'priority' => 99,
];
return $groups;
}
public function add_style_fields( array $fields ) {
$fields['hide_on_mobile'] = [
'name' => '<span class="dashicons dashicons-smartphone"></span>' . __( 'Mobiel', 'siw'),
'label' => __( 'Verbergen', 'siw'),
'group' => 'siw-visibility',
'type' => 'checkbox',
'priority' => 10,
];
$fields['hide_on_desktop'] = [
'name' => '<span class="dashicons dashicons-desktop"></span>' . __( 'Desktop', 'siw'),
'label' => __( 'Verbergen', 'siw'),
'group' => 'siw-visibility',
'type' => 'checkbox',
'priority' => 20,
];
return $fields;
}
public function add_style_attributes( array $style_attributes, array $style_args ) {
if ( isset( $style_args['hide_on_mobile'] ) && 1 == $style_args['hide_on_mobile'] ) {
$style_attributes['class'][] = 'hidden-xs';
}
if ( isset( $style_args['hide_on_desktop'] ) && 1 == $style_args['hide_on_desktop'] ) {
$style_attributes['class'][] = 'hidden-sm';
$style_attributes['class'][] = 'hidden-md';
$style_attributes['class'][] = 'hidden-lg';
}
return $style_attributes;
}
}