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-redirects.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_Block_Ad_Redirects extends WDN_Page { |
| 19 | |
| 20 | /** |
| 21 | * {@inheritDoc} |
| 22 | * |
| 23 | * @var string |
| 24 | */ |
| 25 | public $id = "wdanp-edit-redirects"; |
| 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 dashicons-undo'; |
| 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 = __( 'Block ad redirects', 'disable-admin-notices' ); |
| 55 | $this->page_menu_short_description = __( 'Break advertising redirects', 'disable-admin-notices' ); |
| 56 | |
| 57 | parent::__construct( $plugin ); |
| 58 | |
| 59 | $this->plugin = $plugin; |
| 60 | |
| 61 | add_filter( 'wp_redirect', function ( $location ) { |
| 62 | $redirects = $this->getPopulateOption( 'blocked_redirects', [] ); |
| 63 | if ( in_array( $location, $redirects ) ) { |
| 64 | return null; |
| 65 | } |
| 66 | |
| 67 | return $location; |
| 68 | } ); |
| 69 | } |
| 70 | |
| 71 | public function unblockRedirectAction() { |
| 72 | $redirect_ID = $this->request()->get( 'redirect_id', null, 'sanitize_key' ); |
| 73 | check_admin_referer( 'unblock_redirect_' . $redirect_ID ); |
| 74 | |
| 75 | $redirects = $this->getPopulateOption( 'blocked_redirects', [] ); |
| 76 | |
| 77 | if ( isset( $redirects[ $redirect_ID ] ) ) { |
| 78 | unset( $redirects[ $redirect_ID ] ); |
| 79 | $this->updatePopulateOption( 'blocked_redirects', $redirects ); |
| 80 | } |
| 81 | |
| 82 | $this->redirectToAction( 'index' ); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Requests assets (js and css) for the page. |
| 87 | * |
| 88 | * @param Wbcr_Factory480_ScriptList $scripts |
| 89 | * @param Wbcr_Factory480_StyleList $styles |
| 90 | * |
| 91 | * @return void |
| 92 | * @see Wbcr_FactoryPages480_AdminPage |
| 93 | * |
| 94 | */ |
| 95 | public function assets( $scripts, $styles ) { |
| 96 | parent::assets( $scripts, $styles ); |
| 97 | |
| 98 | $this->styles->add( WDN_PLUGIN_URL . '/admin/assets/css/settings.css' ); |
| 99 | } |
| 100 | |
| 101 | public function showPageContent() { |
| 102 | $redirects = $this->getPopulateOption( 'blocked_redirects', [] ); |
| 103 | |
| 104 | if ( isset( $_POST['wdan_add_block'] ) ) { |
| 105 | check_admin_referer( 'wdan_add_block_redirect' ); |
| 106 | $url = $this->request()->post( 'wdan_redirect_url', null, 'sanitize_url' ); |
| 107 | |
| 108 | if ( ! empty( $url ) ) { |
| 109 | if ( ! in_array( $url, $redirects ) ) { |
| 110 | $redirects[ md5( $url ) ] = $url; |
| 111 | $this->updatePopulateOption( 'blocked_redirects', $redirects ); |
| 112 | } |
| 113 | |
| 114 | $this->redirectToAction( 'index' ); |
| 115 | } |
| 116 | } |
| 117 | ?> |
| 118 | <div style="padding:15px;"> |
| 119 | <h4><?php esc_html_e( 'Block ad redirects', 'disable-admin-notices' ); ?></h4> |
| 120 | <form method="post"> |
| 121 | <?php wp_nonce_field( 'wdan_add_block_redirect' ); ?> |
| 122 | <label for="wdan-redirect-url"><?php esc_html_e( 'Enter url for block', 'disable-admin-notices'); ?></label><br> |
| 123 | <input id="wdan-redirect-url" style="width:400px;" type="text" name="wdan_redirect_url"> |
| 124 | <input type="submit" name="wdan_add_block" class="button" value="<?php esc_attr_e( 'Add block', 'disable-admin-notices' ); ?>"> |
| 125 | </form> |
| 126 | <p class="wdan-redirect-url-description"><?php esc_html_e( 'Some plugins open a page automatically after installation or update to show announcements, promotions, or other information. Enter the URLs of those pages here to prevent them from opening automatically.', 'disable-admin-notices' ); ?></p> |
| 127 | <br> |
| 128 | <table class="wp-list-table widefat fixed striped"> |
| 129 | <tr> |
| 130 | <th><?php esc_html( 'Url', 'disable-admin-notices' ); ?></th> |
| 131 | <th style="width:200px;"><?php esc_html_e( 'Action', 'disable-admin-notices' ); ?></th> |
| 132 | </tr> |
| 133 | <?php foreach ( $redirects as $ID => $redirect ): ?> |
| 134 | <tr> |
| 135 | <td> |
| 136 | <?php echo esc_html( $redirect ); ?> |
| 137 | </td> |
| 138 | <td> |
| 139 | <a style="color:#428bca;" href="<?php echo wp_nonce_url( $this->getActionUrl( 'unblock-redirect', [ 'redirect_id' => $ID ] ), 'unblock_redirect_' . $ID ); ?>"><?php esc_html_e( 'Unblock', 'disable-admin-notices' ); ?></a> |
| 140 | </td> |
| 141 | </tr> |
| 142 | <?php endforeach; ?> |
| 143 | </table> |
| 144 | </div> |
| 145 | <?php |
| 146 | } |
| 147 | |
| 148 | } |
| 149 |