PluginProbe
Gridable / 1.2.0
Gridable v1.2.0
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.0, at admin/class-gridable-admin.php

152 lines 5.1 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 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 __( '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( 'jquery', 'wp-color-picker', 'select2' ), $this->version, true );
75
76 wp_register_style( 'select2', plugin_dir_url( __FILE__ ) . 'css/select2.css', array(), $this->version );
77
78 wp_enqueue_style( 'gridable-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin-style.css', array( 'wp-color-picker', 'select2' ), $this->version, false );
79
80 wp_localize_script( 'gridable-add-row-button', 'gridable_editor_params', array(
81 'new_column_content' => esc_html__( 'Content', 'gridable' )
82 ) );
83
84 wp_localize_script( 'gridable-add-row-button', 'gridable_row_options', apply_filters('gridable_row_options', array(
85 'cols_nr' => array(
86 'default' => 2
87 )
88 ) ) );
89
90 wp_localize_script( 'gridable-add-row-button', 'gridable_column_options', apply_filters('gridable_column_options', array(
91 'size' => array(
92 'default' => 6
93 )
94 ) ) );
95
96 global $editor_styles;
97 if ( ! empty( $editor_styles ) && is_array($editor_styles) ) {
98 $editor_styles = array_merge( $editor_styles, array(
99 plugin_dir_url( __FILE__ ) . 'css/editor-style.css'
100 ) );
101 } else {
102 $editor_styles = array(
103 plugin_dir_url( __FILE__ ) . 'css/editor-style.css'
104 );
105 }
106 }
107
108 function wp_print_grider_tinymce_templates() {
109 $row_classes = array(
110 'gridable',
111 'gridable--grid',
112 'grid'
113 );
114 $col_classes = array(
115 'grid__item'
116 ); ?>
117 <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>
118 <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>
119 <?php
120 do_action( 'gridable_print_row_options_templates' );
121 do_action( 'gridable_print_column_options_templates' );
122 }
123
124 function add_grider_tinymce_plugin( $plugin_array ) {
125 $plugin_array['gridable'] = plugin_dir_url( __FILE__ ) . 'js/gridable.js';
126
127 return $plugin_array;
128 }
129
130 function my_add_styles_admin() {
131 global $current_screen;
132
133 if ( is_admin() ) { ?>
134 <script type="text/javascript">
135 var gridable_params = {
136 l10n: JSON.parse('<?php echo json_encode( apply_filters( 'gridable_editor_l10n_labels', array(
137 'remove_row' => esc_html__( 'Remove Row', 'gridable' ),
138 'remove_column' => esc_html__( 'Remove Column', 'gridable' ),
139 'edit_row' => esc_html__( 'Edit Row Options', 'gridable' ),
140 'edit_column' => esc_html__( 'Edit Column Options', 'gridable' ),
141 'add_column' => esc_html__( 'Add Column', 'gridable' ),
142 'new_column_content' => esc_html__( 'Content', 'gridable' ),
143 'column' => esc_html__( 'Column', 'gridable' ),
144 'row' => esc_html__( 'Row', 'gridable' ),
145 ) ) ) ?>')
146 };
147 </script>
148 <?php
149 }
150 }
151 }
152