PluginProbe ʕ •ᴥ•ʔ
Gallery : FooGallery / 3.3.3
Gallery : FooGallery v3.3.3
3.3.2 3.3.3 3.3.0 3.1.31 3.1.32 3.1.34 3.1.36 3.2.0 3.2.6 trunk 1.10.3 2.0.24 2.1.34 2.2.44 2.3.3 2.4.32 3.0.6 3.1.11 3.1.12 3.1.13 3.1.20 3.1.25 3.1.26 3.1.26.1 3.1.26.2
foogallery / includes / admin / class-gallery-metabox-template.php
foogallery / includes / admin Last commit date
class-admin-notice-custom-css.php 1 day ago class-admin-notices.php 1 day ago class-admin.php 1 day ago class-attachment-fields.php 1 day ago class-columns.php 1 day ago class-demo-content.php 1 day ago class-extensions.php 1 day ago class-gallery-attachment-modal.php 1 day ago class-gallery-datasources.php 1 day ago class-gallery-editor.php 1 day ago class-gallery-metabox-fields.php 1 day ago class-gallery-metabox-items.php 1 day ago class-gallery-metabox-settings-helper.php 1 day ago class-gallery-metabox-settings.php 1 day ago class-gallery-metabox-template.php 1 day ago class-gallery-metaboxes.php 1 day ago class-menu.php 1 day ago class-pro-promotion.php 1 day ago class-settings.php 1 day ago class-silent-installer-skin.php 1 day ago class-trial-mode.php 1 day ago demo-content-galleries.php 1 day ago demo-content-images.php 1 day ago index.php 1 day ago pro-features.php 1 day ago view-features.php 1 day ago view-help-demos.php 1 day ago view-help-getting-started.php 1 day ago view-help-pro.php 1 day ago view-help.php 1 day ago view-system-info.php 1 day ago
class-gallery-metabox-template.php
139 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * Class to handle adding the Template metabox to a gallery
9 */
10
11 // TODO : remove phpcs:disable comment and work through plugin check warnings.
12
13
14 if ( ! class_exists( 'FooGallery_Admin_Gallery_MetaBox_Template' ) ) {
15
16 class FooGallery_Admin_Gallery_MetaBox_Template {
17
18 /**
19 * FooGallery_Admin_Gallery_MetaBox_Template constructor.
20 */
21 function __construct() {
22 add_action( 'add_meta_boxes_' . FOOGALLERY_CPT_GALLERY, array( $this, 'add_template_metabox' ), 6 );
23
24 //enqueue assets for the new settings tabs
25 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ) );
26 }
27
28 public function add_template_metabox( $post ) {
29 add_meta_box(
30 'foogallery_template',
31 __( 'Gallery Layout', 'foogallery' ),
32 array( $this, 'render_gallery_template_metabox' ),
33 FOOGALLERY_CPT_GALLERY,
34 'normal',
35 'high'
36 );
37 }
38
39 /**
40 * Render the template metabox
41 */
42 public function render_gallery_template_metabox( $post ) {
43 $gallery = foogallery_admin_get_current_gallery( $post );
44
45 $gallery_templates = foogallery_gallery_templates();
46 $current_gallery_template = foogallery_default_gallery_template();
47 if ( ! empty( $gallery->gallery_template ) ) {
48 $current_gallery_template = $gallery->gallery_template;
49 }
50
51 $message = __( 'Once you are happy with your selected layout, you can minimize this section to save space', 'foogallery' );
52 $hide_help = 'on' == foogallery_get_setting( 'hide_gallery_template_help' );
53 if ( $hide_help ) {
54 $message = '';
55 }
56
57 // Allow SVG tags for icons (wp_kses_post doesn't support SVG)
58 $svg_allowed = array(
59 'svg' => array(
60 'viewbox' => true,
61 'viewBox' => true,
62 'xmlns' => true,
63 'width' => true,
64 'height' => true,
65 'class' => true,
66 ),
67 'g' => array(
68 'transform' => true,
69 'class' => true,
70 ),
71 'rect' => array(
72 'x' => true,
73 'y' => true,
74 'width' => true,
75 'height' => true,
76 'class' => true,
77 ),
78 'polygon' => array(
79 'points' => true,
80 'class' => true,
81 ),
82 'circle' => array(
83 'cx' => true,
84 'cy' => true,
85 'r' => true,
86 'class' => true,
87 ),
88 'path' => array(
89 'd' => true,
90 'class' => true,
91 ),
92 'polyline' => array(
93 'points' => true,
94 'class' => true,
95 ),
96 );
97
98 ?>
99 <div class="foogallery-template-card-selector" data-metabox-message="<?php echo esc_attr( $message ); ?>">
100 <div class="foogallery-template-cards-container">
101 <?php foreach ( $gallery_templates as $template ) {
102 $selected_class = ( $current_gallery_template === $template['slug'] ) ? 'selected' : '';
103 $extra_class = $template['class'] ?? '';
104 $extra_html = $template['html'] ?? '';
105 ?>
106 <div class="foogallery-template-card <?php echo esc_attr( $selected_class ); ?> <?php echo esc_attr( $extra_class ); ?>"
107 data-template="<?php echo esc_attr( $template['slug'] ); ?>">
108 <?php echo wp_kses( $template['icon'], $svg_allowed ); ?>
109 <h4><?php echo esc_html( $template['name'] ); ?></h4>
110 <?php echo wp_kses_post( $extra_html ); ?>
111 </div>
112 <?php } ?>
113 </div>
114
115 <!-- Keep the hidden select for form submission -->
116 <input type="hidden" id="FooGallerySettings_GalleryTemplate" name="<?php echo esc_attr( FOOGALLERY_META_TEMPLATE ); ?>" value="<?php echo esc_attr( $current_gallery_template ); ?>" />
117 </div>
118 <?php
119 }
120
121 /***
122 * Enqueue the assets needed by the template metabox
123 * @param $hook_suffix
124 */
125 function enqueue_assets( $hook_suffix ){
126 if( in_array( $hook_suffix, array( 'post.php', 'post-new.php' ) ) ) {
127 $screen = get_current_screen();
128
129 if ( is_object( $screen ) && FOOGALLERY_CPT_GALLERY === $screen->post_type ){
130
131 // Register, enqueue scripts and styles here
132 wp_enqueue_script( 'foogallery-admin-template', FOOGALLERY_URL . 'js/foogallery.admin.template.js', array('jquery'), FOOGALLERY_VERSION );
133 wp_enqueue_style( 'foogallery-admin-template', FOOGALLERY_URL . 'css/foogallery.admin.template.css', array(), FOOGALLERY_VERSION );
134 }
135 }
136 }
137 }
138 }
139