class-pages-edit-admin-bar.php
1 month ago
class-pages-edit-redirects.php
6 months ago
class-pages-notices.php
7 months ago
class-pages-settings.php
1 year ago
index.php
3 years ago
class-pages-edit-admin-bar.php
149 lines
| 1 | <?php |
| 2 | |
| 3 | // Exit if accessed directly |
| 4 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | exit; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Страница общи� |
| 10 | настроек для этого плагина. |
| 11 | * |
| 12 | * Не поддерживает режим работы с мультисаймами. |
| 13 | * |
| 14 | * @author Alexander Kovalev <alex.kovalevv@gmail.com>, Github: https://github.com/alexkovalevv |
| 15 | * @copyright (c) 2019 Webraftic Ltd |
| 16 | * @version 1.0 |
| 17 | */ |
| 18 | class WDAN_Edit_Admin_Bar extends WDN_Page { |
| 19 | |
| 20 | /** |
| 21 | * {@inheritDoc} |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | public $id = "wdanp-edit-admin-bar"; |
| 26 | |
| 27 | /** |
| 28 | * {@inheritDoc} |
| 29 | * |
| 30 | * @var string |
| 31 | */ |
| 32 | public $type = "page"; |
| 33 | |
| 34 | /** |
| 35 | * {@inheritDoc} |
| 36 | * |
| 37 | * @var string |
| 38 | */ |
| 39 | public $page_menu_dashicon = 'dashicons-menu'; |
| 40 | |
| 41 | /** |
| 42 | * {@inheritDoc} |
| 43 | * |
| 44 | * @since 2.0.5 - добавлен |
| 45 | * @var bool |
| 46 | */ |
| 47 | public $show_right_sidebar_in_options = false; |
| 48 | |
| 49 | |
| 50 | /** |
| 51 | * @param WDN_Plugin $plugin |
| 52 | */ |
| 53 | public function __construct( $plugin ) { |
| 54 | $this->menu_title = __( 'Hide admin bar items', 'disable-admin-notices' ); |
| 55 | $this->page_menu_short_description = __( 'Hide selected admin bar menu items', 'disable-admin-notices' ); |
| 56 | |
| 57 | parent::__construct( $plugin ); |
| 58 | |
| 59 | $this->plugin = $plugin; |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * Requests assets (js and css) for the page. |
| 64 | * |
| 65 | * @param Wbcr_Factory480_ScriptList $scripts |
| 66 | * @param Wbcr_Factory480_StyleList $styles |
| 67 | * |
| 68 | * @return void |
| 69 | * @see Wbcr_FactoryPages000_AdminPage |
| 70 | * |
| 71 | */ |
| 72 | public function assets( $scripts, $styles ) { |
| 73 | parent::assets( $scripts, $styles ); |
| 74 | |
| 75 | $this->styles->add( WDN_PLUGIN_URL . '/admin/assets/css/settings.css' ); |
| 76 | $this->scripts->add( WDN_PLUGIN_URL . '/admin/assets/js/settings.js', [ |
| 77 | 'jquery' |
| 78 | ] ); |
| 79 | } |
| 80 | |
| 81 | public function disableAdminbarItemAction() { |
| 82 | $item_ID = $this->request()->get( 'id', null, 'sanitize_key' ); |
| 83 | check_admin_referer( 'disable_adminbar_item_' . $item_ID ); |
| 84 | |
| 85 | $items = $this->plugin->getPopulateOption( 'hidden_adminbar_items', [] ); |
| 86 | |
| 87 | if ( ! isset( $items[ $item_ID ] ) ) { |
| 88 | $items[ $item_ID ] = true; |
| 89 | $this->plugin->updatePopulateOption( 'hidden_adminbar_items', $items ); |
| 90 | } |
| 91 | |
| 92 | $this->redirectToAction( 'index' ); |
| 93 | } |
| 94 | |
| 95 | public function enableAdminbarItemAction() { |
| 96 | $item_ID = $this->request()->get( 'id', null, 'sanitize_key' ); |
| 97 | check_admin_referer( 'enable_adminbar_item_' . $item_ID ); |
| 98 | |
| 99 | $items = $this->plugin->getPopulateOption( 'hidden_adminbar_items', [] ); |
| 100 | |
| 101 | if ( isset( $items[ $item_ID ] ) ) { |
| 102 | unset( $items[ $item_ID ] ); |
| 103 | $this->plugin->updatePopulateOption( 'hidden_adminbar_items', $items ); |
| 104 | } |
| 105 | |
| 106 | $this->redirectToAction( 'index' ); |
| 107 | } |
| 108 | |
| 109 | public function showPageContent() { |
| 110 | $all_items = $this->plugin->getPopulateOption( 'adminbar_items', [] ); |
| 111 | $hidden_items = $this->plugin->getPopulateOption( 'hidden_adminbar_items', [] ); |
| 112 | |
| 113 | ?> |
| 114 | |
| 115 | <div style="padding:15px;"> |
| 116 | <h4><?php esc_html_e( 'Disable admin bar items', 'disable-admin-notices' ); ?></h4> |
| 117 | <table class="wp-list-table widefat fixed striped"> |
| 118 | <tr> |
| 119 | <th><strong><?php esc_html_e( 'Menu title', 'disable-admin-notices' ); ?></strong></th> |
| 120 | <th style="width:150px;"><strong><?php esc_html_e( 'Action', 'disable-admin-notices' ); ?></strong></th> |
| 121 | </tr> |
| 122 | <?php |
| 123 | foreach ( (array) $all_items as $ID => $title ): |
| 124 | $is_item_hidden = isset( $hidden_items[ $ID ] ) && true === $hidden_items[ $ID ]; |
| 125 | ?> |
| 126 | |
| 127 | <tr> |
| 128 | <td><?php echo esc_html( $title ); ?></td> |
| 129 | <td> |
| 130 | <div data-nonce="<?php echo esc_attr( wp_create_nonce( 'enable_adminbar_item_' . $ID ) ) ?>" data-menu-id="<?php echo esc_attr( $ID ); ?>" class="wdan-checkbox adminbar-items factory-checkbox factory-from-control-checkbox factory-buttons-way btn-group"> |
| 131 | <button type="button" class="btn btn-default btn-small btn-sm factory-on<?php echo esc_attr( ! $is_item_hidden ? ' active' : '' ); ?>"> |
| 132 | <?php esc_html_e( 'On ', 'disable-admin-notices' ); ?> |
| 133 | </button> |
| 134 | <button type="button" class="btn btn-default btn-small btn-sm factory-off<?php echo esc_attr( ! $is_item_hidden ? ' active' : '' ); ?>" data-value="0"> |
| 135 | <?php esc_html_e( 'Off', 'disable-admin-notices' ); ?> |
| 136 | </button> |
| 137 | <input type="checkbox" style="display: none" class="factory-result" value="<?php echo esc_attr( ! $is_item_hidden ? '1' : '0' ); ?>" checked="<?php echo esc_attr( ! $is_item_hidden ? 'checked' : '' ); ?>"> |
| 138 | </div> |
| 139 | </td> |
| 140 | </tr> |
| 141 | <?php endforeach; ?> |
| 142 | </table> |
| 143 | </div> |
| 144 | |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | } |
| 149 |