| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPCoder\Admin; |
| 4 |
|
| 5 |
defined( 'ABSPATH' ) || exit; |
| 6 |
|
| 7 |
// Exit if accessed directly. |
| 8 |
use WPCoder\WOW_Plugin; |
| 9 |
|
| 10 |
class AdminInitializer { |
| 11 |
|
| 12 |
public static function init(): void { |
| 13 |
add_filter( 'plugin_action_links', [ __CLASS__, 'settings_link' ], 10, 2 ); |
| 14 |
add_filter( 'admin_footer_text', [ __CLASS__, 'footer_text' ] ); |
| 15 |
add_action( 'admin_menu', [ __CLASS__, 'add_admin_page' ] ); |
| 16 |
add_action( 'admin_enqueue_scripts', [ __CLASS__, 'admin_scripts' ] ); |
| 17 |
new AdminNotices; |
| 18 |
new AdminActions; |
| 19 |
} |
| 20 |
|
| 21 |
public static function settings_link( $links, $file ) { |
| 22 |
if ( false === strpos( $file, WOW_Plugin::basename() ) ) { |
| 23 |
return $links; |
| 24 |
} |
| 25 |
$link = admin_url( 'admin.php?page=' . WOW_Plugin::SLUG ); |
| 26 |
$text = esc_attr__( 'Settings', 'wpcoder' ); |
| 27 |
$settings_link = '<a href="' . esc_url( $link ) . '">' . esc_attr( $text ) . '</a>'; |
| 28 |
array_unshift( $links, $settings_link ); |
| 29 |
|
| 30 |
return $links; |
| 31 |
} |
| 32 |
|
| 33 |
public static function footer_text( $footer_text ) { |
| 34 |
global $pagenow; |
| 35 |
|
| 36 |
if ( $pagenow === 'admin.php' && ( isset( $_GET['page'] ) && $_GET['page'] === WOW_Plugin::SLUG ) ) { |
| 37 |
$text = sprintf( |
| 38 |
__( 'Thank you for using <b>%2$s</b>! Please <a href="%1$s" target="_blank">rate us</a>', 'wpcoder' ), |
| 39 |
esc_url( WOW_Plugin::PluginURL ), |
| 40 |
esc_attr( WOW_Plugin::NAME ) |
| 41 |
); |
| 42 |
|
| 43 |
return str_replace( '</span>', '', $footer_text ) . ' | ' . $text . '</span>'; |
| 44 |
} |
| 45 |
|
| 46 |
return $footer_text; |
| 47 |
} |
| 48 |
|
| 49 |
public static function add_admin_page(): void { |
| 50 |
$parent = 'wow-company'; |
| 51 |
$title = WOW_Plugin::NAME . ' version ' . WOW_Plugin::VERSION; |
| 52 |
$menu_title = WOW_Plugin::NAME; |
| 53 |
$capability = 'unfiltered_html'; |
| 54 |
$slug = WOW_Plugin::SLUG; |
| 55 |
add_submenu_page( $parent, $title, $menu_title, $capability, $slug, [ __CLASS__, 'plugin_page' ] ); |
| 56 |
} |
| 57 |
|
| 58 |
public static function plugin_page(): void { |
| 59 |
do_action( WOW_Plugin::PREFIX . '_admin_page' ); |
| 60 |
} |
| 61 |
|
| 62 |
public static function admin_scripts( $hook ): void { |
| 63 |
$page = 'wow-plugins_page_' . WOW_Plugin::SLUG; |
| 64 |
|
| 65 |
if ( $page !== $hook ) { |
| 66 |
return; |
| 67 |
} |
| 68 |
|
| 69 |
do_action( WOW_Plugin::PREFIX . '_admin_load_styles_scripts' ); |
| 70 |
} |
| 71 |
|
| 72 |
} |