Plugin Directory

Changeset 1082735


Ignore:
Timestamp:
02/05/2015 01:51:30 AM (11 years ago)
Author:
ecommnet
Message:

bug fixes

Location:
quick-toolbar/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • quick-toolbar/trunk/ecm-quick-toolbar.php

    r1081423 r1082735  
    44 * Plugin URI: http://www.ecommnet.uk
    55 * Description: Add frequently used menu links and custom links to the Admin Toolbar.
    6  * Version: 0.1
     6 * Version: 0.2
    77 * Author: Ecommnet
    88 * Author URI: http://www.ecommnet.uk
     
    1919         * @var string
    2020         */
    21         public $version = '0.1';
     21        public $version = '0.2';
    2222
    2323        /**
     
    6666
    6767        public function enqueue_styles() {
    68             wp_register_style( 'ecm_wp_admin_css', plugin_dir_url( __FILE__ ) . '/css/admin-styles.css', false, $version );
    69             wp_enqueue_style( 'ecm_wp_admin_css' );
    70             wp_enqueue_script( 'ecmqt_scripts', plugin_dir_url( __FILE__ ) . '/js/ecmqt-scripts.js', array(), $version, true );
    71 
     68            wp_enqueue_style( 'dashicons' );
     69            wp_register_style( 'ecmqt_wp_admin_css', plugin_dir_url( __FILE__ ) . '/css/ecmqt-admin-styles.css', false, $this->version );
     70            wp_enqueue_style( 'ecmqt_wp_admin_css' );
     71            wp_enqueue_script( 'ecmqt_scripts', plugin_dir_url( __FILE__ ) . '/js/ecmqt-scripts.js', array(), $this->version, true );
    7272        }
    7373
     
    7878
    7979        public function add_admin_menu() {
    80             add_menu_page( 'Quick Toolbar Links', 'Quick Toolbar', 'manage_options', 'ecm-quick-toolbar', array($this, 'admin_page'), 'dashicons-admin-links' );
     80            add_menu_page( 'Quick Toolbar Links', 'Quick Toolbar', 'manage_options', 'ecm-quick-toolbar', array($this, 'admin_page'), 'dashicons-admin-links', 100 );
    8181            add_submenu_page( 'ecm-quick-toolbar', 'Custom Quick Links', 'Edit Custom Links', 'manage_options', 'ecm-custom-quick-toolbar', array($this, 'admin_custom_page') );
    8282        }
     
    9393                    $decoded = unserialize(base64_decode($option));
    9494                    if (isset($decoded[2]) && !empty($decoded[2])) {
     95                        if (0 === strpos($decoded[2][3], 'http')) {
     96                            $title = '<img src="'. $decoded[2][3] . '"/>' . $decoded[2][1];
     97                        } else {
     98                            $title = '<span class="wp-menu-image dashicons-before ' . $decoded[2][3] . '"></span>' . $decoded[2][1];
     99                        }
    95100                        $allowed = user_can( $user_ID, $decoded[3] );
    96101                        if ($allowed == true) {
    97102                            $admin_bar->add_menu( array(
    98103                                'id'    => 'ecmqt_'.date("Y-m-d-his").$decoded[2][0],
    99                                 'title' => $decoded[2][1],
     104                                'title' => __($title),
    100105                                'href'  => $decoded[2][2],
    101106                                'meta'  => array('class' => 'ecmqt-menu-item ecmqt-has-submenu')
     
    103108                        }
    104109                    } else {
     110                        if (0 === strpos($decoded[4], 'http')) {
     111                            $title = '<img src="'. $decoded[4] . '"/>' . $decoded[0];
     112                        } else {
     113                            $title = '<span class="wp-menu-image dashicons-before ' . $decoded[4] . '"></span>' . $decoded[0];
     114                        }
    105115                        $allowed = user_can( $user_ID, $decoded[3] );
    106116                        if ($allowed == true) {
    107117                            $admin_bar->add_menu( array(
    108118                                'id'    => 'ecmqt_'.date("Y-m-d-his").$j,
    109                                 'title' => $decoded[0],
     119                                'title' => __($title),
    110120                                'href'  => $decoded[1],
    111121                                'meta'  => array('class' => 'ecmqt-menu-item')
     
    141151                $co = 3000;
    142152                foreach ($custom_options as $key => $custom_option) {
    143                     if (isset($custom_options[$key][4]) && !empty($custom_options[$key][4])) {
     153                    if (empty($custom_options[$key][4]) || !isset($custom_options[$key][4])) {
     154                        $title = $custom_options[$key][0];
     155                    } else {
     156                        $title = '<img src="'. $custom_options[$key][4] . '" />' . $custom_options[$key][0];
     157                    }
     158
     159                    if (isset($custom_options[$key][5]) && !empty($custom_options[$key][5])) {
    144160                        if (isset($custom_options[$key][2]) && !empty($custom_options[$key][2]) && $custom_options[$key][2] == true) {
    145161                            $meta = array('class' => 'ecmqt-menu-item ecmqt-has-submenu', 'target' => '_blank');
     
    150166                        $admin_bar->add_menu( array(
    151167                            'id'    => 'ecmqt_'.date("Y-m-d-his").$key,
    152                             'title' => $custom_options[$key][0],
     168                            'title' => $title,
    153169                            'href'  => $custom_options[$key][1],
    154170                            'meta'  => $meta
     
    162178                        $admin_bar->add_menu( array(
    163179                            'id'    => 'ecmqt_'.date("Y-m-d-his").$co,
    164                             'title' => $custom_options[$key][0],
     180                            'title' => $title,
    165181                            'href'  => $custom_options[$key][1],
    166182                            'meta'  => $meta
     
    172188                $cos = 4000;
    173189                foreach($custom_options as $custom_option) {
    174                     if (isset($custom_option[4]) && !empty($custom_option[4])) {
    175                         foreach ($custom_option[4] as $custom_menu_item) {
     190                    if (isset($custom_option[5]) && !empty($custom_option[5])) {
     191                        foreach ($custom_option[5] as $custom_menu_item) {
    176192                            if (isset($custom_menu_item[2]) && !empty($custom_menu_item[2]) && $custom_menu_item[2] == true) {
    177193                                $meta = array('class' => 'ecmqt-submenu-item', 'target' => '_blank');
     
    200216            if (isset($items) && !empty($items)) { ?>
    201217                <div class="wrap">
    202                 <h2>Quick Toolbar Links <a href="<?php echo get_admin_url() . 'admin.php?page=ecm-custom-quick-toolbar';?>" class="add-new-h2">Edit Custom Toolbar Links</a></h2>
     218                <h2>Quick Toolbar Links <a href="<?php echo get_admin_url() . 'admin.php?page=ecm-custom-quick-toolbar';?>" class="add-new-h2 ecmqt-h2"">Edit Custom Toolbar Links</a></h2>
    203219                <br/>
    204220                <form method="post" action="options.php" id="_ecmqt_quicklinks_options">
     
    234250                                echo '';
    235251                            } else {
    236                                 echo '<input id="check_menu_'. $x .'" type="checkbox"' . ' name="_ecmqt_items[]" value="' . base64_encode(serialize(array( $ecm_menu_item['name'] ,  $ecm_menu_item['link'], '', $ecm_menu_item['permissions']))) . '"' . $checked . '/>';
     252                                echo '<input id="check_menu_'. $x .'" type="checkbox"' . ' name="_ecmqt_items[]" value="' . base64_encode(serialize(array( $ecm_menu_item['name'] ,  $ecm_menu_item['link'], '', $ecm_menu_item['permissions'], $ecm_menu_item['dashicon']))) . '"' . $checked . '/>';
    237253                            }
    238254                            echo '</td>' . "\n";
     
    272288                                    echo '<tr' . $ecm_class . '>' . "\n";
    273289                                    echo '<td> &mdash; ' . $ecm_submenu_item['name'] . '</td>' . "\n";
    274                                     echo '<td><input id="check_menu_'.$x .'" type="checkbox" name="_ecmqt_items[]" value="' . base64_encode(serialize(array( $ecm_submenu_item['name'],  $ecm_submenu_item['link'], array($ecm_submenu_item['parent']['id'], $ecm_submenu_item['parent']['name'], $ecm_submenu_item['parent']['link']), $ecm_submenu_item['permissions']))) . '"' . $sub_checked . '/></td>' . "\n";
     290                                    echo '<td><input id="check_menu_'.$x .'" type="checkbox" name="_ecmqt_items[]" value="' . base64_encode(serialize(array( $ecm_submenu_item['name'],  $ecm_submenu_item['link'], array($ecm_submenu_item['parent']['id'], $ecm_submenu_item['parent']['name'], $ecm_submenu_item['parent']['link'], $ecm_submenu_item['parent']['dashicon']), $ecm_submenu_item['permissions']))) . '"' . $sub_checked . '/></td>' . "\n";
    275291                                    echo '</tr>' . "\n";
    276292                                    $x++;
     
    306322                    unset($custom_options[$key]);
    307323                }
    308                 if (isset($custom_options[$key][4]) && !empty($custom_options[$key][4])) {
    309                     foreach ($custom_options[$key][4] as $sub_key => $sub_option) {
    310                         $sub_option_id = $custom_options[$key][4][$sub_key][3];
     324                if (isset($custom_options[$key][5]) && !empty($custom_options[$key][5])) {
     325                    foreach ($custom_options[$key][5] as $sub_key => $sub_option) {
     326                        $sub_option_id = $custom_options[$key][5][$sub_key][3];
    311327                        if ($sub_option_id == $custom_link) {
    312                             unset($custom_options[$key][4][$sub_key]);
     328                            unset($custom_options[$key][5][$sub_key]);
    313329                        }
    314330                    }
     
    327343                    $target = $_POST["_ecmqt_custom_items_target"];
    328344                    $parent = $_POST["_ecmqt_custom_items_parent"];
     345                    $icon = $_POST["_ecmqt_upload_image"];
    329346
    330347                    if ($target == true) {
     
    337354                    $unique = date('dmyHis');
    338355                    if ($parent == 'no-parent' || $parent == '') {
    339                         $custom_options[] = array($title, $link, $new_window, $unique);
     356                        $custom_options[] = array($title, $link, $new_window, $unique, $icon);
    340357                    } else {
    341358                        foreach ($custom_options as $key => $value) {
    342359                            $option_key = '_ecmqt_parent_' . $key;
    343360                            if ($option_key == $parent) {
    344                                 $custom_options[$key][4][] = array($title, $link, $new_window, $unique, $key);
     361                                $custom_options[$key][5][] = array($title, $link, $new_window, $unique, $key, $icon);
    345362                            }
    346363                        }
     
    355372        }
    356373
    357         public function custom_form() { ?>
     374        public function custom_form() {
     375            global $pagenow;
     376            if ($pagenow == 'admin.php' && $_GET['page'] == 'ecm-custom-quick-toolbar') {
     377            wp_enqueue_media();
     378            } ?>
    358379            <div class="wrap">
    359                 <h2>Custom Quick Toolbar Links <a href="<?php echo get_admin_url() . 'admin.php?page=ecm-quick-toolbar';?>" class="add-new-h2">Edit Quick Toolbar Links</a></h2>
    360                 <form id="_ecmqt_custom_quicklinks_options" name="_ecmqt_custom_quicklinks_options" method="post" action="">
     380                <h2>Custom Quick Toolbar Links <a href="<?php echo get_admin_url() . 'admin.php?page=ecm-quick-toolbar';?>" class="add-new-h2 ecmqt-h2">Edit Quick Toolbar Links</a></h2>
     381                <form id="_ecmqt_custom_quicklinks_options" name="_ecmqt_custom_quicklinks_options" method="post" action="" enctype="multipart/form-data">
    361382                    <label for="_ecmqt_custom_items_title">Link Title *</label><br/>
    362383                    <input type="text" name="_ecmqt_custom_items_title" id="_ecmqt_custom_items_title" maxlength="50" size="40" required><br/><br/>
     
    374395                        </select><br/><br/>
    375396                    <?php } ?>
     397                    <input id="_ecmqt_upload_image_button" class="button" type="button" value="Choose Icon Image" />
     398                    <input id="_ecmqt_upload_image_label" type="text" size="36" name="_ecmqt_upload_image_label" disabled /><br/>
     399                    <p class="description">Icons will only be displayed for top level menu items.</p><br/>
    376400                    <input name="submit" type="submit" value="Add Custom Quick Link &raquo;" class="button button-primary">
    377401                    <input type="hidden" name="_ecmqt_custom_quicklinks_options" value="_ecmqt_custom_quicklinks_options">
     402                    <input id="_ecmqt_upload_image" type="hidden" size="36" name="_ecmqt_upload_image" />
    378403                </form><br/><br/>
    379404
     
    407432                    echo '</tr>';
    408433                    $x++;
    409                     if (isset($custom_option[4]) && !empty($custom_option[4])) {
    410                         foreach ($custom_option[4] as $co_submenu) {
     434                    if (isset($custom_option[5]) && !empty($custom_option[5])) {
     435                        foreach ($custom_option[5] as $co_submenu) {
    411436                            $ecm_class = ( ' class="alternate"' == $ecm_class ) ? '' : ' class="alternate"';
    412437                            echo '<tr ' . $ecm_class . '>';
     
    503528                            'name' => $item[0],
    504529                            'link' => get_admin_url() . "admin.php?page={$submenu_items[0][2]}",
    505                             'permissions' => $item[1]
     530                            'permissions' => $item[1],
     531                            'dashicon' => $item[6]
    506532                        );
    507533
     
    510536                            'name' => $item[0],
    511537                            'link' => get_admin_url() . $submenu_items[0][2],
    512                             'permissions' => $item[1]
     538                            'permissions' => $item[1],
     539                            'dashicon' => $item[6]
    513540                        );
    514541                    }
     
    524551                            'name' => $item[0],
    525552                            'link' => get_admin_url() . "admin.php?page={$item[2]}",
    526                             'permissions' => $item[1]
     553                            'permissions' => $item[1],
     554                            'dashicon' => $item[6]
    527555                        );
    528556
     
    531559                            'name' => $item[0],
    532560                            'link' => get_admin_url() . $item[2],
    533                             'permissions' => $item[1]
     561                            'permissions' => $item[1],
     562                            'dashicon' => $item[6]
    534563                        );
    535564                    }
     
    587616                                'name' => $sub_item[0],
    588617                                'link' => get_admin_url() . $sub_item_url,
    589                                 'parent' => array('id' => $key, 'name' => $items[$key]['name'], 'link' => $items[$key]['link']),
     618                                'parent' => array('id' => $key, 'name' => $items[$key]['name'], 'link' => $items[$key]['link'], 'dashicon' => $items[$key]['dashicon']),
    590619                                'permissions' => $sub_item[1]
    591620                            );
     
    595624                                'name' => $sub_item[0],
    596625                                'link' => get_admin_url() . $sub_item[2],
    597                                 'parent' => array('id' => $key, 'name' => $items[$key]['name'], 'link' => $items[$key]['link']),
     626                                'parent' => array('id' => $key, 'name' => $items[$key]['name'], 'link' => $items[$key]['link'], 'dashicon' => $items[$key]['dashicon']),
    598627                                'permissions' => $sub_item[1]
    599628
  • quick-toolbar/trunk/js/ecmqt-scripts.js

    r1081423 r1082735  
    1717    }
    1818}
     19
     20
     21jQuery(document).ready(function($){
     22
     23    var custom_uploader;
     24
     25    $('#_ecmqt_upload_image_button').click(function(e) {
     26        e.preventDefault();
     27
     28        //If the uploader object has already been created, reopen the dialog
     29        if (custom_uploader) {
     30            custom_uploader.open();
     31            return;
     32        }
     33
     34        //Extend the wp.media object
     35        custom_uploader = wp.media.frames.file_frame = wp.media({
     36            title: 'Choose Image',
     37            button: {
     38                text: 'Choose Image'
     39            },
     40            multiple: false
     41        });
     42
     43        //When a file is selected, grab the URL and set it as the text field's value
     44        custom_uploader.on('select', function() {
     45            attachment = custom_uploader.state().get('selection').first().toJSON();
     46            $('#_ecmqt_upload_image').val(attachment.url);
     47            $('#_ecmqt_upload_image_label').val(attachment.url);
     48        });
     49
     50        //Open the uploader dialog
     51        custom_uploader.open();
     52    });
     53});
  • quick-toolbar/trunk/readme.txt

    r1081423 r1082735  
    44Requires at least: 3.3
    55Tested up to: 4.1
    6 Stable tag: 0.1
     6Stable tag: 0.2
    77License: GPLv2 or later
    88License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    5050= 0.1 =
    5151* First version of the plugin
     52
     53= 0.2 =
     54* Adding Icons to the Quick Toolbar links
     55* Prefixing stylesheet to avoid conflict
Note: See TracChangeset for help on using the changeset viewer.