| 1 |
<?php |
| 2 |
namespace ABlocks; |
| 3 |
|
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; // Exit if accessed directly. |
| 6 |
} |
| 7 |
|
| 8 |
class Admin { |
| 9 |
public static function init() { |
| 10 |
$self = new self(); |
| 11 |
$self->dispatch_hooks(); |
| 12 |
} |
| 13 |
|
| 14 |
public function dispatch_hooks() { |
| 15 |
Admin\Menu::init(); |
| 16 |
\ABlocks\CreatePage\page\ShowPageState::init(); |
| 17 |
Admin\Export::init(); |
| 18 |
add_filter( 'allowed_redirect_hosts', array( $this, 'add_white_listed_redirect_hosts' ) ); |
| 19 |
add_action( 'current_screen', array( $this, 'conditional_loaded' ) ); |
| 20 |
add_filter( 'plugin_action_links_' . ABLOCKS_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); |
| 21 |
add_filter( 'plugin_row_meta', array( $this, 'add_plugin_links' ), 10, 2 ); |
| 22 |
add_action( 'admin_init', array( $this, 'dispatch_activation_redirect' ), 99 ); |
| 23 |
} |
| 24 |
public function add_white_listed_redirect_hosts( $hosts ) { |
| 25 |
$hosts[] = 'ablocks.pro'; |
| 26 |
return $hosts; |
| 27 |
} |
| 28 |
public function conditional_loaded() { |
| 29 |
$screen = get_current_screen(); |
| 30 |
|
| 31 |
if ( ! $screen ) { |
| 32 |
return; |
| 33 |
} |
| 34 |
|
| 35 |
switch ( $screen->id ) { |
| 36 |
case 'ablocks_page_ablocks-get-pro': |
| 37 |
wp_safe_redirect( 'https://ablocks.pro/pricing/' ); |
| 38 |
exit; |
| 39 |
} |
| 40 |
} |
| 41 |
public function add_plugin_links( $links, $file ) { |
| 42 |
if ( ABLOCKS_PLUGIN_BASENAME !== $file ) { |
| 43 |
return $links; |
| 44 |
} |
| 45 |
|
| 46 |
$map_block_links = array( |
| 47 |
'docs' => array( |
| 48 |
'url' => 'https://ablocks.pro/docs/', |
| 49 |
'label' => __( 'Docs', 'ablocks' ), |
| 50 |
'aria-label' => __( 'View Academy documentation', 'ablocks' ), |
| 51 |
), |
| 52 |
'video' => array( |
| 53 |
'url' => 'https://www.youtube.com/@ablocksteam', |
| 54 |
'label' => __( 'Video Tutorials', 'ablocks' ), |
| 55 |
'aria-label' => __( 'See Video Tutorials', 'ablocks' ), |
| 56 |
), |
| 57 |
'support' => array( |
| 58 |
'url' => 'https://wordpress.org/support/plugin/ablocks/', |
| 59 |
'label' => __( 'Community Support', 'ablocks' ), |
| 60 |
'aria-label' => __( 'Visit community forums', 'ablocks' ), |
| 61 |
), |
| 62 |
'review' => array( |
| 63 |
'url' => 'https://wordpress.org/support/plugin/ablocks/reviews/#new-post', |
| 64 |
'label' => __( 'Rate the plugin � |
| 65 |
� |
| 66 |
� |
| 67 |
� |
| 68 |
� |
| 69 |
', 'ablocks' ), |
| 70 |
'aria-label' => __( 'Rate the plugin.', 'ablocks' ), |
| 71 |
), |
| 72 |
); |
| 73 |
|
| 74 |
foreach ( $map_block_links as $key => $link ) { |
| 75 |
$links[ $key ] = sprintf( |
| 76 |
'<a target="_blank" href="%s" aria-label="%s">%s</a>', |
| 77 |
esc_url( $link['url'] ), |
| 78 |
esc_attr( $link['aria-label'] ), |
| 79 |
esc_html( $link['label'] ) |
| 80 |
); |
| 81 |
} |
| 82 |
|
| 83 |
return $links; |
| 84 |
} |
| 85 |
public function plugin_action_links( $links ) { |
| 86 |
$settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=ablocks' ), esc_html__( 'Settings', 'ablocks' ) ); |
| 87 |
|
| 88 |
array_unshift( $links, $settings_link ); |
| 89 |
|
| 90 |
if ( ! defined( 'ABLOCKS_PRO_VERSION' ) ) { |
| 91 |
$links['go_pro'] = sprintf( '<a href="%1$s" target="_blank" class="academy-plugins-gopro" style="color: #7b68ee; font-weight: bold;">%2$s</a>', 'https://ablocks.pro/pricing/', esc_html__( 'Get aBlocks Pro', 'ablocks' ) ); |
| 92 |
} |
| 93 |
return $links; |
| 94 |
} |
| 95 |
public function dispatch_activation_redirect() { |
| 96 |
if ( get_option( 'ablocks_need_activation_redirect', false ) ) { |
| 97 |
delete_option( 'ablocks_need_activation_redirect' ); |
| 98 |
wp_safe_redirect( admin_url( 'admin.php?page=ablocks' ) ); |
| 99 |
exit; |
| 100 |
} |
| 101 |
} |
| 102 |
} |
| 103 |
|