PluginProbe
Gridable / 1.2.9
Gridable v1.2.9
1.2.12 1.2.11 trunk 0.1.0 0.5.0 1.0.0 1.1.0 1.2.0 1.2.1 1.2.10 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9
gridable / admin / class-gridable-admin.php

class-gridable-admin.php in Gridable 1.2.9, at admin/class-gridable-admin.php

169 lines 5.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * The admin-specific functionality of the plugin.
5 *
6 * @link https://pixelgrade.com
7 * @since 1.0.0
8 *
9 * @package Gridable
10 * @subpackage Gridable/admin
11 */
12
13 /**
14 * The admin-specific functionality of the plugin.
15 *
16 * Defines the plugin name, version, and two examples hooks for how to
17 * enqueue the admin-specific stylesheet and JavaScript.
18 *
19 * @package Gridable
20 * @subpackage Gridable/admin
21 * @author Pixelgrade <contact@pixelgrade.com>
22 */
23 class Gridable_Admin {
24
25 /**
26 * The ID of this plugin.
27 *
28 * @since 1.0.0
29 * @access private
30 * @var string $gridable The ID of this plugin.
31 */
32 private $gridable;
33
34 /**
35 * The version of this plugin.
36 *
37 * @since 1.0.0
38 * @access private
39 * @var string $version The current version of this plugin.
40 */
41 private $version;
42
43 /**
44 * Initialize the class and set its properties.
45 *
46 * @since 1.0.0
47 *
48 * @param string $gridable The name of this plugin.
49 * @param string $version The version of this plugin.
50 */
51 public function __construct( $gridable, $version ) {
52 $this->gridable = $gridable;
53 $this->version = $version;
54 }
55
56 public function add_media_button( $editor_id ) {
57 // Setup the icon - currently using a dashicon
58 $icon = '<span class="wp-media-buttons-icon dashicons dashicons-layout" style="font-size:16px;margin-top:-2px;"></span>';
59
60 printf( '<a href="#" class="button gridable-insert-row-button" id="%s" data-editor="%s" title="%s">%s %s</a>',
61 'gridable-add-row-button-' . $editor_id,
62 esc_attr( $editor_id ),
63 esc_attr__( 'Add Row', 'gridable' ),
64 $icon,
65 esc_html__( 'Add Row', 'gridable' )
66 );
67
68 /**
69 * Enqueue the editor script only when there is an editor on page.
70 * We ditch `admin_enqueue_scripts` intentionally since the editor can appear on non-edit pages like theme options
71 */
72 wp_register_script( 'select2', plugin_dir_url( __FILE__ ) . 'js/select2.min.js', array( 'jquery' ), $this->version );
73
74 wp_enqueue_script( 'gridable-add-row-button', plugin_dir_url( __FILE__ ) . 'js/add-row-button.js', array(
75 'jquery',
76 'wp-color-picker',
77 'select2',
78 ), $this->version, true );
79
80 wp_register_style( 'select2', plugin_dir_url( __FILE__ ) . 'css/select2.css', array(), $this->version );
81
82 wp_enqueue_style( 'gridable-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin-style.css', array(
83 'wp-color-picker',
84 'select2',
85 ), $this->version, false );
86
87 wp_localize_script( 'gridable-add-row-button', 'gridable_editor_params', array(
88 'new_column_content' => esc_html__( 'Content', 'gridable' ),
89 ) );
90
91 wp_localize_script( 'gridable-add-row-button', 'gridable_row_options', apply_filters( 'gridable_row_options', array(
92 'cols_nr' => array(
93 'default' => 2,
94 ),
95 ) ) );
96
97 wp_localize_script( 'gridable-add-row-button', 'gridable_column_options', apply_filters( 'gridable_column_options', array(
98 'size' => array(
99 'default' => 6,
100 ),
101 ) ) );
102
103 global $editor_styles;
104 if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) {
105 $editor_styles = array_merge( $editor_styles, array(
106 plugin_dir_url( __FILE__ ) . 'css/editor-style.css',
107 ) );
108 } else {
109 $editor_styles = array(
110 plugin_dir_url( __FILE__ ) . 'css/editor-style.css',
111 );
112 }
113 }
114
115 public function print_tinymce_templates() {
116 $row_classes = array(
117 'gridable',
118 'gridable--grid',
119 'grid'
120 );
121 $col_classes = array(
122 'grid__item'
123 ); ?>
124 <script type="text/html" id="tmpl-gridable-grider-row"><section contenteditable="false" class="{{data.classes}} <?php echo join( ' ', apply_filters( 'gridable_mce_sh_row_classes', $row_classes ) ); ?>" {{{data.atts}}} data-gridable-row="1" data-mce-resize="false" data-mce-placeholder="1">{{{data.content}}}</section></script>
125 <script type="text/html" id="tmpl-gridable-grider-col"><section unselectable="true" contenteditable="true" class="{{data.classes}} <?php echo join( ' ', apply_filters( 'gridable_mce_sh_col_classes', $col_classes ) ); ?>" {{{data.atts}}} data-mce-resize="false" data-mce-placeholder="1">{{{data.content}}}</section></script>
126 <?php
127 do_action( 'gridable_print_row_options_templates' );
128 do_action( 'gridable_print_column_options_templates' );
129 }
130
131 public function add_tinymce_plugin( $plugin_array ) {
132 $plugin_array['gridable'] = plugin_dir_url( __FILE__ ) . 'js/gridable.js';
133
134 return $plugin_array;
135 }
136
137 public function change_tinymce_settings( $settings ) {
138 if ( ! empty( $settings['tinymce'] ) ) {
139 if ( ! is_array( $settings['tinymce'] ) ) {
140 $settings['tinymce'] = array();
141 }
142 // We need to disable keeping the scroll position when switching between Visual and Text mode
143 // due to the fact that this functionality relies on some inline spans that get autop'd
144 // and result in certain cases in &nbsp; characters. Making a solid Regex for this is very tricky.
145 $settings['tinymce']['wp_keep_scroll_position'] = false;
146 }
147
148 return $settings;
149 }
150
151 public function styles_scripts() { ?>
152 <script type="text/javascript">
153 var gridable_params = {
154 l10n: JSON.parse('<?php echo json_encode( apply_filters( 'gridable_editor_l10n_labels', array(
155 'remove_row' => esc_html__( 'Remove Row', 'gridable' ),
156 'remove_column' => esc_html__( 'Remove Column', 'gridable' ),
157 'edit_row' => esc_html__( 'Edit Row Options', 'gridable' ),
158 'edit_column' => esc_html__( 'Edit Column Options', 'gridable' ),
159 'add_column' => esc_html__( 'Add Column', 'gridable' ),
160 'new_column_content' => esc_html__( 'Content', 'gridable' ),
161 'column' => esc_html__( 'Column', 'gridable' ),
162 'row' => esc_html__( 'Row', 'gridable' ),
163 ) ) ) ?>')
164 };
165 </script>
166 <?php
167 }
168 }
169