class-admin-notice-custom-css.php
8 months ago
class-admin-notices.php
8 months ago
class-admin.php
8 months ago
class-attachment-fields.php
8 months ago
class-columns.php
8 months ago
class-demo-content.php
8 months ago
class-extensions.php
8 months ago
class-gallery-attachment-modal.php
8 months ago
class-gallery-datasources.php
8 months ago
class-gallery-editor.php
8 months ago
class-gallery-metabox-fields.php
8 months ago
class-gallery-metabox-items.php
8 months ago
class-gallery-metabox-settings-helper.php
8 months ago
class-gallery-metabox-settings.php
8 months ago
class-gallery-metabox-template.php
8 months ago
class-gallery-metaboxes.php
8 months ago
class-menu.php
8 months ago
class-pro-promotion.php
8 months ago
class-settings.php
8 months ago
class-silent-installer-skin.php
8 months ago
class-trial-mode.php
8 months ago
demo-content-galleries.php
8 months ago
demo-content-images.php
8 months ago
index.php
12 years ago
pro-features.php
8 months ago
view-features.php
8 months ago
view-help-demos.php
8 months ago
view-help-getting-started.php
8 months ago
view-help-pro.php
8 months ago
view-help.php
8 months ago
view-system-info.php
8 months ago
class-gallery-metabox-settings.php
131 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class to handle adding the Settings metabox to a gallery |
| 4 | */ |
| 5 | |
| 6 | |
| 7 | if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Settings' ) ) { |
| 8 | |
| 9 | class FooGallery_Admin_Gallery_MetaBox_Settings { |
| 10 | |
| 11 | /** |
| 12 | * FooGallery_Admin_Gallery_MetaBox_Settings constructor. |
| 13 | */ |
| 14 | function __construct() { |
| 15 | add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_settings_metabox' ), 8 ); |
| 16 | |
| 17 | //enqueue assets for the new settings tabs |
| 18 | add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) ); |
| 19 | |
| 20 | //get the section slug |
| 21 | add_filter( 'foogallery_gallery_settings_metabox_section_slug', array( $this, 'get_section_slug' ) ); |
| 22 | |
| 23 | //set default settings tab icons |
| 24 | add_filter( 'foogallery_gallery_settings_metabox_section_icon', array( $this, 'add_section_icons') ); |
| 25 | } |
| 26 | |
| 27 | public function add_settings_metabox( $post ) { |
| 28 | add_meta_box( |
| 29 | 'foogallery_settings', |
| 30 | __( 'Gallery Settings', 'foogallery' ), |
| 31 | array( $this, 'render_gallery_settings_metabox' ), |
| 32 | FOOGALLERY_CPT_GALLERY, |
| 33 | 'normal', |
| 34 | 'high' |
| 35 | ); |
| 36 | } |
| 37 | |
| 38 | public function render_gallery_settings_metabox( $post ) { |
| 39 | $gallery = foogallery_admin_get_current_gallery( $post ); |
| 40 | |
| 41 | //attempt to load default gallery settings from another gallery, as per FooGallery settings page |
| 42 | $gallery->load_default_settings_if_new(); |
| 43 | |
| 44 | $gallery = apply_filters( 'foogallery_render_gallery_settings_metabox', $gallery ); |
| 45 | |
| 46 | if ( true === apply_filters( 'foogallery_should_render_gallery_settings_metabox', true, $gallery ) ) { |
| 47 | |
| 48 | $settings = new FooGallery_Admin_Gallery_MetaBox_Settings_Helper( $gallery ); |
| 49 | |
| 50 | $settings->render_gallery_settings(); |
| 51 | } |
| 52 | |
| 53 | do_action( 'foogallery_after_render_gallery_settings_metabox', $gallery ); |
| 54 | } |
| 55 | |
| 56 | /*** |
| 57 | * Enqueue the assets needed by the settings |
| 58 | * @param $hook_suffix |
| 59 | */ |
| 60 | function enqueue_assets( $hook_suffix ){ |
| 61 | if( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) { |
| 62 | $screen = get_current_screen(); |
| 63 | |
| 64 | if ( is_object( $screen ) && FOOGALLERY_CPT_GALLERY === $screen->post_type ){ |
| 65 | |
| 66 | //spectrum needed for the colorpicker field |
| 67 | $url = FOOGALLERY_URL . 'lib/spectrum/spectrum.js'; |
| 68 | wp_enqueue_script( 'foogallery-spectrum', $url, array('jquery'), FOOGALLERY_VERSION ); |
| 69 | $url = FOOGALLERY_URL . 'lib/spectrum/spectrum.css'; |
| 70 | wp_enqueue_style( 'foogallery-spectrum', $url, array(), FOOGALLERY_VERSION ); |
| 71 | |
| 72 | // Register, enqueue scripts and styles here |
| 73 | wp_enqueue_script( 'foogallery-admin-settings', FOOGALLERY_URL . 'js/foogallery.admin.min.js', array('jquery'), FOOGALLERY_VERSION ); |
| 74 | wp_enqueue_style( 'foogallery-admin-settings', FOOGALLERY_URL . 'css/foogallery.admin.min.css', array(), FOOGALLERY_VERSION ); |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /** |
| 80 | * Returns the section slug that can be used in the settings tabs |
| 81 | * @param $section |
| 82 | * @return string |
| 83 | */ |
| 84 | function get_section_slug( $section ) { |
| 85 | switch ( $section ) { |
| 86 | case __('General', 'foogallery'): |
| 87 | return 'general'; |
| 88 | case __('Advanced', 'foogallery'): |
| 89 | return 'advanced'; |
| 90 | case __('Appearance', 'foogallery'): |
| 91 | return 'appearance'; |
| 92 | case __('Video', 'foogallery'): |
| 93 | return 'video'; |
| 94 | case __('Hover Effects', 'foogallery'): |
| 95 | return 'hover effects'; |
| 96 | case __('Captions', 'foogallery'): |
| 97 | return 'captions'; |
| 98 | case __('Paging', 'foogallery'): |
| 99 | return 'paging'; |
| 100 | } |
| 101 | return strtolower( $section ); |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Returns the Dashicon that can be used in the settings tabs |
| 106 | * |
| 107 | * @param string $section_slug |
| 108 | * @return string |
| 109 | */ |
| 110 | function add_section_icons( $section_slug ) { |
| 111 | switch ( $section_slug ) { |
| 112 | case 'general': |
| 113 | return 'dashicons-format-gallery'; |
| 114 | case 'advanced': |
| 115 | return 'dashicons-admin-tools'; |
| 116 | case 'appearance': |
| 117 | return 'dashicons-admin-appearance'; |
| 118 | case 'video': |
| 119 | return 'dashicons-video-alt3'; |
| 120 | case 'hover effects': |
| 121 | return 'dashicons-star-filled'; |
| 122 | case 'captions': |
| 123 | return 'dashicons-editor-quote'; |
| 124 | case 'paging': |
| 125 | return 'dashicons-admin-page'; |
| 126 | } |
| 127 | return $section_slug; |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 |