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