| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* The dashboard-specific functionality of the plugin. |
| 5 |
* |
| 6 |
* @link https://kaizencoders.com |
| 7 |
* @since 1.2 |
| 8 |
* |
| 9 |
* @package UpdateURLS |
| 10 |
* @subpackage UpdateURLS/admin |
| 11 |
*/ |
| 12 |
|
| 13 |
namespace KaizenCoders\UpdateURLS; |
| 14 |
|
| 15 |
use KaizenCoders\UpdateURLS\Admin\Promotions\PromoBanner; |
| 16 |
|
| 17 |
/** |
| 18 |
* The dashboard-specific functionality of the plugin. |
| 19 |
* |
| 20 |
* Defines the plugin name, version, and two examples hooks for how to |
| 21 |
* enqueue the dashboard-specific stylesheet and JavaScript. |
| 22 |
* |
| 23 |
* @package UpdateURLS |
| 24 |
* @subpackage UpdateURLS/admin |
| 25 |
* @author KaizenCoders <hello@kaizencoders.com> |
| 26 |
*/ |
| 27 |
class Admin { |
| 28 |
|
| 29 |
/** |
| 30 |
* The plugin's instance. |
| 31 |
* |
| 32 |
* @since 1.2 |
| 33 |
* @access private |
| 34 |
* @var Plugin $plugin This plugin's instance. |
| 35 |
*/ |
| 36 |
private $plugin; |
| 37 |
|
| 38 |
/** |
| 39 |
* Initialize the class and set its properties. |
| 40 |
* |
| 41 |
* @param Plugin $plugin This plugin's instance. |
| 42 |
* |
| 43 |
* @since 1.2 |
| 44 |
* |
| 45 |
*/ |
| 46 |
public function __construct( Plugin $plugin ) { |
| 47 |
$this->plugin = $plugin; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Register the stylesheets for the Dashboard. |
| 52 |
* |
| 53 |
* @since 1.2 |
| 54 |
*/ |
| 55 |
public function enqueue_styles() { |
| 56 |
|
| 57 |
/** |
| 58 |
* This function is provided for demonstration purposes only. |
| 59 |
* |
| 60 |
* An instance of this class should be passed to the run() function |
| 61 |
* defined in UpdateURLS_Loader as all of the hooks are defined |
| 62 |
* in that particular class. |
| 63 |
* |
| 64 |
* The UpdateURLS_Loader will then create the relationship |
| 65 |
* between the defined hooks and the functions defined in this |
| 66 |
* class. |
| 67 |
*/ |
| 68 |
|
| 69 |
if ( Helper::is_plugin_admin_screen() ) { |
| 70 |
|
| 71 |
\wp_enqueue_style( |
| 72 |
'update-urls-main', |
| 73 |
\plugin_dir_url( dirname( __FILE__ ) ) . 'dist/styles/app.css', |
| 74 |
array(), |
| 75 |
$this->plugin->get_version(), |
| 76 |
'all' ); |
| 77 |
\wp_enqueue_style( |
| 78 |
$this->plugin->get_plugin_name(), |
| 79 |
\plugin_dir_url( dirname( __FILE__ ) ) . 'dist/styles/update-urls-admin.css', |
| 80 |
array(), |
| 81 |
$this->plugin->get_version(), |
| 82 |
'all' ); |
| 83 |
} |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
/** |
| 88 |
* Register the JavaScript for the dashboard. |
| 89 |
* |
| 90 |
* @since 1.2 |
| 91 |
*/ |
| 92 |
public function enqueue_scripts() { |
| 93 |
|
| 94 |
/** |
| 95 |
* This function is provided for demonstration purposes only. |
| 96 |
* |
| 97 |
* An instance of this class should be passed to the run() function |
| 98 |
* defined in UpdateURLS_Loader as all of the hooks are defined |
| 99 |
* in that particular class. |
| 100 |
* |
| 101 |
* The UpdateURLS_Loader will then create the relationship |
| 102 |
* between the defined hooks and the functions defined in this |
| 103 |
* class. |
| 104 |
*/ |
| 105 |
|
| 106 |
if ( Helper::is_plugin_admin_screen() ) { |
| 107 |
|
| 108 |
\wp_enqueue_script( |
| 109 |
'uu-app', |
| 110 |
\plugin_dir_url( dirname( __FILE__ ) ) . 'dist/scripts/app.js', |
| 111 |
array( 'jquery' ), |
| 112 |
$this->plugin->get_version(), |
| 113 |
true ); |
| 114 |
|
| 115 |
\wp_enqueue_script( |
| 116 |
'update-urls-admin', |
| 117 |
\plugin_dir_url( dirname( __FILE__ ) ) . 'dist/scripts/update-urls-admin.js', |
| 118 |
array( 'jquery' ), |
| 119 |
$this->plugin->get_version(), |
| 120 |
true ); |
| 121 |
} |
| 122 |
|
| 123 |
wp_localize_script( |
| 124 |
'update-urls-admin', |
| 125 |
'uuParams', |
| 126 |
array( |
| 127 |
'ajaxurl' => admin_url( 'admin-ajax.php' ) |
| 128 |
) |
| 129 |
); |
| 130 |
|
| 131 |
} |
| 132 |
|
| 133 |
/** |
| 134 |
* Add admin menu |
| 135 |
* |
| 136 |
* @since 1.0.0 |
| 137 |
*/ |
| 138 |
public function add_admin_menu() { |
| 139 |
add_menu_page( __( 'Update URLS', 'url-shortify' ), __( 'Update URLS', 'update-urls' ), 'manage_options', |
| 140 |
'update-urls', [ |
| 141 |
$this, |
| 142 |
'render_search_and_replace_page', |
| 143 |
], 'dashicons-update', 30 ); |
| 144 |
|
| 145 |
add_submenu_page( |
| 146 |
'update-urls', |
| 147 |
__( 'Search & Replace', 'update-urls' ), |
| 148 |
__( 'Search & Replace', 'update-urls' ), |
| 149 |
'manage_options', |
| 150 |
'update-urls', |
| 151 |
[ $this, 'render_search_and_replace_page' ], |
| 152 |
2 |
| 153 |
); |
| 154 |
|
| 155 |
add_submenu_page( |
| 156 |
'update-urls', |
| 157 |
__( 'History', 'update-urls' ), |
| 158 |
__( 'History', 'update-urls' ), |
| 159 |
'manage_options', |
| 160 |
'update-urls-history', |
| 161 |
[ $this, 'render_history_page' ], |
| 162 |
2 |
| 163 |
); |
| 164 |
|
| 165 |
add_submenu_page( |
| 166 |
'update-urls', |
| 167 |
__( 'Tools', 'update-urls' ), |
| 168 |
__( 'Tools', 'update-urls' ), |
| 169 |
'manage_options', |
| 170 |
'update-urls-tools', |
| 171 |
[ $this, 'render_tools_page' ], |
| 172 |
5 |
| 173 |
); |
| 174 |
|
| 175 |
add_submenu_page( |
| 176 |
'update-urls', |
| 177 |
__( 'Other Products', 'update-urls' ), |
| 178 |
__( 'Other Products', 'update-urls' ), |
| 179 |
'manage_options', |
| 180 |
'update-urls-other-products', |
| 181 |
[ $this, 'render_other_products_page' ], |
| 182 |
9 |
| 183 |
); |
| 184 |
|
| 185 |
new \KaizenCoders\UpdateURLS\Admin\Settings(); |
| 186 |
} |
| 187 |
|
| 188 |
public function render_history_page() { |
| 189 |
include_once KC_UU_ADMIN_TEMPLATES_DIR . '/history.php'; |
| 190 |
} |
| 191 |
|
| 192 |
public function render_tools_page() { |
| 193 |
include_once KC_UU_ADMIN_TEMPLATES_DIR . '/tools.php'; |
| 194 |
} |
| 195 |
|
| 196 |
public function render_other_products_page() { |
| 197 |
include_once KC_UU_ADMIN_TEMPLATES_DIR . '/other-products.php'; |
| 198 |
} |
| 199 |
|
| 200 |
function render_search_and_replace_page() { |
| 201 |
include KC_UU_ADMIN_TEMPLATES_DIR . '/update-urls.php'; |
| 202 |
} |
| 203 |
|
| 204 |
/** |
| 205 |
* Remove all admin notices |
| 206 |
* |
| 207 |
* @since 1.2 |
| 208 |
*/ |
| 209 |
public function handle_admin_notices() { |
| 210 |
global $wp_filter; |
| 211 |
|
| 212 |
if ( ! Helper::is_plugin_admin_screen() ) { |
| 213 |
return; |
| 214 |
} |
| 215 |
|
| 216 |
$allow_display_notices = array( |
| 217 |
'show_review_notice', |
| 218 |
'kc_uu_fail_php_version_notice', |
| 219 |
'kc_uu_show_admin_notice', |
| 220 |
'show_custom_notices', |
| 221 |
'handle_promotions', |
| 222 |
'_admin_notices_hook', |
| 223 |
PromoBanner::RENDER_CALLBACK, |
| 224 |
); |
| 225 |
|
| 226 |
$filters = array( |
| 227 |
'admin_notices', |
| 228 |
'user_admin_notices', |
| 229 |
'all_admin_notices' |
| 230 |
); |
| 231 |
|
| 232 |
foreach ( $filters as $filter ) { |
| 233 |
|
| 234 |
if ( ! empty( $wp_filter[ $filter ]->callbacks ) && is_array( $wp_filter[ $filter ]->callbacks ) ) { |
| 235 |
|
| 236 |
foreach ( $wp_filter[ $filter ]->callbacks as $priority => $callbacks ) { |
| 237 |
|
| 238 |
foreach ( $callbacks as $name => $details ) { |
| 239 |
|
| 240 |
if ( is_object( $details['function'] ) && $details['function'] instanceof \Closure ) { |
| 241 |
unset( $wp_filter[ $filter ]->callbacks[ $priority ][ $name ] ); |
| 242 |
continue; |
| 243 |
} |
| 244 |
|
| 245 |
if ( ! empty( $details['function'][0] ) && is_object( $details['function'][0] ) && count( $details['function'] ) == 2 ) { |
| 246 |
$notice_callback_name = $details['function'][1]; |
| 247 |
if ( ! in_array( $notice_callback_name, $allow_display_notices ) ) { |
| 248 |
unset( $wp_filter[ $filter ]->callbacks[ $priority ][ $name ] ); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
if ( ! empty( $details['function'] ) && is_string( $details['function'] ) ) { |
| 253 |
if ( ! in_array( $details['function'], $allow_display_notices ) ) { |
| 254 |
unset( $wp_filter[ $filter ]->callbacks[ $priority ][ $name ] ); |
| 255 |
} |
| 256 |
} |
| 257 |
} |
| 258 |
} |
| 259 |
} |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
/** |
| 265 |
* Update plugin notice |
| 266 |
* |
| 267 |
* @param $data |
| 268 |
* @param $response |
| 269 |
* |
| 270 |
* @since 1.2 |
| 271 |
*/ |
| 272 |
public function in_plugin_update_message( $data, $response ) { |
| 273 |
|
| 274 |
if ( isset( $data['upgrade_notice'] ) ) { |
| 275 |
printf( |
| 276 |
'<div class="update-message">%s</div>', |
| 277 |
wpautop( $data['upgrade_notice'] ) |
| 278 |
); |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
} |
| 284 |
|