Skip to content

Commit

Permalink
added advanced gallery template settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bradvin committed Sep 11, 2018
1 parent b5341ac commit 32eaac0
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pro/foogallery-pro.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require_once( FOOGALLERY_PATH . 'pro/includes/class-foogallery-pro-gallery-override.php' );
require_once( FOOGALLERY_PATH . 'pro/includes/class-foogallery-pro-filtering.php' );
require_once( FOOGALLERY_PATH . 'pro/includes/class-foogallery-pro-attachment-taxonomies.php' );
require_once( FOOGALLERY_PATH . 'pro/includes/class-foogallery-pro-advanced-gallery-settings.php' );

/**
* FooGallery PRO Main Class
Expand All @@ -29,6 +30,7 @@ function __construct() {
new FooGallery_Pro_Gallery_Shortcode_Override();
new FooGallery_Pro_Attachment_Taxonomies();
new FooGallery_Pro_Filtering();
new FooGallery_Pro_Advanced_Gallery_Settings();
}
}
}
93 changes: 93 additions & 0 deletions pro/includes/class-foogallery-pro-advanced-gallery-settings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php
/**
* Class for adding advanced settings to all gallery templates
* Date: 11/09/2018
*/
if ( ! class_exists( 'FooGallery_Pro_Advanced_Gallery_Settings' ) ) {

class FooGallery_Pro_Advanced_Gallery_Settings {

function __construct() {
//add fields to all templates
add_filter( 'foogallery_override_gallery_template_fields', array( $this, 'add_advanced_fields' ), 10, 2 );

//add data options
add_filter( 'foogallery_build_container_data_options', array( $this, 'add_data_options' ), 10, 3 );
}

/**
* Add fields to the gallery template
*
* @param $fields
* @param $template
*
* @return array
*/
function add_advanced_fields( $fields, $template ) {
$fields[] = array(
'id' => 'state',
'title' => __( 'State', 'foogallery' ),
'desc' => __( 'Allow the gallery to keep state for both paging and filtering. When enabled, changing the page or filter will alter the URL.', 'foogallery' ),
'section' => __( 'Advanced', 'foogallery' ),
'type' => 'radio',
'default' => 'no',
'spacer' => '<span class="spacer"></span>',
'choices' => array(
'no' => __( 'Disabled', 'foogallery' ),
'yes' => __( 'Enabled', 'foogallery' ),
),
// 'row_data' => array(
// 'data-foogallery-change-selector' => 'input:radio',
// 'data-foogallery-value-selector' => 'input:checked',
// 'data-foogallery-preview' => 'class'
// )
);

$fields[] = array(
'id' => 'custom_settings',
'title' => __( 'Custom Settings', 'foogallery' ),
'desc' => __( 'Add any custom settings to the gallery which will be merged with existing settings.', 'foogallery' ),
'section' => __( 'Advanced', 'foogallery' ),
'type' => 'textarea',
'default' => '',
// 'row_data' => array(
// 'data-foogallery-change-selector' => 'input:radio',
// 'data-foogallery-value-selector' => 'input:checked',
// 'data-foogallery-preview' => 'class'
// )
);

return $fields;
}

/**
* Add the required data options
*
* @param $options
* @param $gallery FooGallery
*
* @param $attributes array
*
* @return array
*/
function add_data_options($options, $gallery, $attributes) {
$enable_state = foogallery_gallery_template_setting( 'state', 'no' );

if ( 'yes' === $enable_state ) {
$options['state']['enabled'] = true;
}

$custom_settings = foogallery_gallery_template_setting( 'custom_settings', '' );

if ( !empty( $custom_settings ) ) {
$settings_array = @json_decode($custom_settings, true);

if ( isset( $settings_array ) ) {
$options = array_merge_recursive( $options, $settings_array );
}
}

return $options;
}
}
}

0 comments on commit 32eaac0

Please sign in to comment.