Plugin Directory

Changeset 2210201


Ignore:
Timestamp:
12/11/2019 03:16:14 PM (6 years ago)
Author:
trubine
Message:

add plugin DB

Location:
easy-tinymce-editor-add-button/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • easy-tinymce-editor-add-button/trunk/easy-tinymce-editor-add-button.php

    r2209319 r2210201  
    33Plugin Name: Easy Tinymce Editor Add Button
    44Description: Simple add button tinyMCE editor
    5 Version: 1.3.2
     5Version: 2.0.1
    66Author: TrubinE
    77Author URI: http://onwp.ru
     
    3939    $namespace = 'EasyTinymceEditorAddButton';
    4040    $plugin_slug = 'easy-tinymce-editor-add-button';
    41     $version = '1.2.0';
     41    $version = '2.0.1';
    4242
    4343    require_once plugin_dir_path(__FILE__) . 'ClassLoader.php';
  • easy-tinymce-editor-add-button/trunk/includes/Admin.php

    r2117715 r2210201  
    77    private $version;
    88    private $plugin_slug;
     9    private $is_install;
    910    private $ns = 'ete-buttons';
    1011    private $options = [
     
    1617        $this->version = $version;
    1718        $this->plugin_slug = $plugin_slug;
     19        $this->is_install = Install::isModuleInstallDB();
     20    }
     21
     22    public function runInstall()
     23    {
     24        Install::runInstall();
     25    }
     26
     27    public function checkInstall($vars)
     28    {
     29        Install::checkInstall();
     30    }
     31
     32    public function noticeInstall()
     33    {
     34        Install::getTemplateInstall();
    1835    }
    1936
     
    3956    public function enqueue_vendor_global()
    4057    {
    41         wp_localize_script('jquery', 'ETE_BUTTONS', get_option('ETE_buttons'));
    42     }
     58        $buttons = false;
    4359
    44     /**
    45      * Register settings
    46      *
    47      */
    48     public function register_settings()
    49     {
    50         foreach ($this->options as $option) {
    51             register_setting($this->ns . '-group', $option, array($this, 'field_validation'));
     60        if ($this->is_install) {
     61            $buttons = Query::getAll();;
    5262        }
     63
     64        wp_localize_script('jquery', 'ETE_BUTTONS', $buttons);
    5365    }
    5466
    5567
    56     /**
    57      * Validation fields "ETE_buttons"
    58      *
    59      * @param $fields
    60      * @return array
    61      */
    62     public function field_validation($fields)
     68    public function updateButtons()
    6369    {
    64         if (is_array($fields)) {
    65             foreach ($fields as $key => $field) {
    66                 $sanitize_title = sanitize_key($fields[$key]['title']);
     70        if ((!empty($_POST['eteab_nonce']) && wp_verify_nonce($_POST['eteab_nonce'], 'eteab_nonce'))
     71            && (!empty($_POST['eteab']) && $_POST['eteab'] === 'update')) {
    6772
    68                 if (empty($sanitize_title)) {
    69                     $sanitize_title = 'button_' . $key;
    70                 }
     73            $buttons = !empty($_POST) ? $_POST['ETE_buttons'] : null;
    7174
    72                 $fields[$key]['title'] = $sanitize_title;
     75            if (!empty($buttons) && is_array($buttons)) {
     76                Install::import($buttons);
     77            }
     78
     79            if (!empty($_POST['page'])) {
     80                wp_redirect('/wp-admin/options-general.php?page=' . $_POST['page']);
     81                die();
    7382            }
    7483        }
    75 
    76         return $fields;
    7784    }
    7885
     
    101108    public function settings_page()
    102109    {
    103         require_once plugin_dir_path(__FILE__) . 'templates/settings.php';
     110        if ($this->is_install) {
     111            require_once plugin_dir_path(__FILE__) . 'templates/settings.php';
     112        } else {
     113            _e('Run install DB from "Easy Tinymce Editor Add Button" for full plugin operation!', 'easy-tinymce-editor-add-button');
     114        }
     115
    104116    }
    105117}
  • easy-tinymce-editor-add-button/trunk/includes/Editor.php

    r2209318 r2210201  
    1313        $this->plugin_slug = $plugin_slug;
    1414        add_action('admin_print_footer_scripts', array($this, 'add_quicktags'));
    15     }
    16 
    17     /**
    18      * Add admin editor css style
    19      *
    20      */
    21     public function enqueue_vendor()
    22     {
    23         wp_enqueue_style(
    24             $this->plugin_slug . '-css',
    25             plugins_url('css/style.css', __FILE__),
    26             array(),
    27             $this->version,
    28             false
    29         );
    3015    }
    3116
     
    4732                                ETE_BUTTONS[i]['title'], // html id for the button
    4833                                ETE_BUTTONS[i]['title'], // html value for the button
    49                                 ETE_BUTTONS[i]['left'], // starting tag
    50                                 ETE_BUTTONS[i]['right'], // ending tag
     34                                ETE_BUTTONS[i]['left_code'], // starting tag
     35                                ETE_BUTTONS[i]['right_code'], // ending tag
    5136                                '', // shortcut access key for the button
    52                                 ETE_BUTTONS[i]['left'] + ' ... ' + ETE_BUTTONS[i]['right'], // html title value for the button
     37                                ETE_BUTTONS[i]['left_code'] + ' ... ' + ETE_BUTTONS[i]['right_code'], // html title value for the button
    5338                                index++ // number representing the desired position of the button in the toolbar. 1 - 9 = first, 11 - 19 = second, 21 - 29 = third
    5439                            );
  • easy-tinymce-editor-add-button/trunk/includes/Manager.php

    r1934790 r2210201  
    3535    {
    3636        $admin = new \EasyTinymceEditorAddButton\includes\Admin($this->version, $this->plugin_slug);
    37         $this->loader->add_action('admin_init', $admin, 'register_settings');
     37        $this->loader->add_action('init', $admin, 'updateButtons');
    3838        $this->loader->add_action('admin_menu', $admin, 'admin_menu');
    3939        $this->loader->add_action('admin_enqueue_scripts', $admin, 'enqueue_vendor');
    4040        $this->loader->add_action('admin_enqueue_scripts', $admin, 'enqueue_vendor_global');
     41        $this->loader->add_action('init', $admin, 'checkInstall');
     42        $this->loader->add_action('init', $admin, 'runInstall');
     43        $this->loader->add_action('admin_menu', $admin, 'noticeInstall');
    4144    }
    4245
     
    4750    private function define_editor_hooks()
    4851    {
    49         $editor = new \EasyTinymceEditorAddButton\includes\Editor($this->version, $this->plugin_slug);
    50         $this->loader->add_action('admin_enqueue_scripts', $editor, 'enqueue_vendor');
     52        (new \EasyTinymceEditorAddButton\includes\Editor($this->version, $this->plugin_slug));
    5153    }
    5254
  • easy-tinymce-editor-add-button/trunk/includes/templates/settings.php

    r2209318 r2210201  
    33?>
    44<h1><?php _e('Easy TinyMCE Editor Add Button', 'easy-tinymce-editor-add-button'); ?></h1>
    5 <form method="post" action="options.php">
    6     <?php
    7     settings_fields('ete-buttons-group');
    8     $buttons = get_option('ETE_buttons');
    9     ?>
     5<form method="post" action="options-general.php">
     6    <?php $buttons = \EasyTinymceEditorAddButton\includes\Query::getAll(); ?>
    107    <div class="ete-buttons-list">
    118        <?php if (!empty($buttons)) {
     
    2320                               type="text"
    2421                               name="ETE_buttons[<?php echo $key; ?>][left]"
    25                                value="<?php echo htmlspecialchars($button['left']); ?>"/>
     22                               value="<?php echo htmlspecialchars($button['left_code']); ?>"/>
    2623                    </label>
    2724                    <label><?php _e('Right code: ', 'easy-tinymce-editor-add-button') ?>
     
    2926                               type="text"
    3027                               name="ETE_buttons[<?php echo $key; ?>][right]"
    31                                value="<?php echo htmlspecialchars($button['right']); ?>"/>
     28                               value="<?php echo htmlspecialchars($button['right_code']); ?>"/>
    3229                    </label>
    3330                    <a href="#" class="ete-buttons-remove"><?php _e('remove', 'easy-tinymce-editor-add-button') ?></a>
     
    6663        <input name="submit" id="submit" class="button button-primary" value="Сохранить изменения" type="submit">
    6764    </p>
     65    <input type="hidden" name="eteab" value="update"/>
     66                <input type="hidden" name="page" value="easy-tinymce-editor-add-button"/>
     67                <input type="hidden" name="eteab_nonce"
     68                       value="<?php echo wp_create_nonce('eteab_nonce'); ?>"/>
    6869</form>
Note: See TracChangeset for help on using the changeset viewer.