*/ class Gridable_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $gridable The ID of this plugin. */ private $gridable; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * * @param string $gridable The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $gridable, $version ) { $this->gridable = $gridable; $this->version = $version; } public function add_media_button( $editor_id ) { // Setup the icon - currently using a dashicon $icon = ''; printf( '%s %s', esc_attr( 'gridable-add-row-button-' . $editor_id ), esc_attr( $editor_id ), esc_attr__( 'Add Row', 'gridable' ), wp_kses( $icon, array( 'span' => array( 'class' => true, 'style' => true, ), ) ), esc_html__( 'Add Row', 'gridable' ) ); /** * Enqueue the editor script only when there is an editor on page. * We ditch `admin_enqueue_scripts` intentionally since the editor can appear on non-edit pages like theme options */ wp_register_script( 'select2', plugin_dir_url( __FILE__ ) . 'js/select2.min.js', array( 'jquery' ), $this->version, true ); wp_enqueue_script( 'gridable-add-row-button', plugin_dir_url( __FILE__ ) . 'js/add-row-button.js', array( 'backbone', 'jquery', 'media-editor', 'media-views', 'quicktags', 'shortcode', 'wp-color-picker', 'wp-util', 'select2', ), $this->version, true ); wp_register_style( 'select2', plugin_dir_url( __FILE__ ) . 'css/select2.css', array(), $this->version ); wp_enqueue_style( 'gridable-admin-style', plugin_dir_url( __FILE__ ) . 'css/admin-style.css', array( 'wp-color-picker', 'select2', ), $this->version, false ); wp_localize_script( 'gridable-add-row-button', 'gridable_editor_params', array( 'new_column_content' => esc_html__( 'Content', 'gridable' ), ) ); wp_localize_script( 'gridable-add-row-button', 'gridable_row_options', apply_filters( 'gridable_row_options', array( 'cols_nr' => array( 'default' => 2, ), ) ) ); wp_localize_script( 'gridable-add-row-button', 'gridable_column_options', apply_filters( 'gridable_column_options', array( 'size' => array( 'default' => 6, ), ) ) ); global $editor_styles; if ( ! empty( $editor_styles ) && is_array( $editor_styles ) ) { $editor_styles = array_merge( $editor_styles, array( plugin_dir_url( __FILE__ ) . 'css/editor-style.css', ) ); } else { $editor_styles = array( plugin_dir_url( __FILE__ ) . 'css/editor-style.css', ); } } public function print_tinymce_templates() { $row_classes = array( 'gridable', 'gridable--grid', 'grid', ); $col_classes = array( 'grid__item', ); ?>