-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added advanced gallery template settings
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
pro/includes/class-foogallery-pro-advanced-gallery-settings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |