| 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 |
add_filter( 'upload_mimes', [ $self, 'allow_lottie_json_uploads' ] ); |
| 14 |
add_filter( 'wp_check_filetype_and_ext', function ( $data, $file, $filename ) { |
| 15 |
$ext = pathinfo( $filename, PATHINFO_EXTENSION ); |
| 16 |
|
| 17 |
if ( 'json' === $ext ) { |
| 18 |
$data['ext'] = 'json'; |
| 19 |
$data['type'] = 'application/json'; |
| 20 |
} |
| 21 |
|
| 22 |
return $data; |
| 23 |
}, 10, 3 ); |
| 24 |
} |
| 25 |
|
| 26 |
function allow_lottie_json_uploads( $mimes ) { |
| 27 |
$mimes['json'] = 'application/json'; |
| 28 |
$mimes['lottie'] = 'application/json'; |
| 29 |
return $mimes; |
| 30 |
} |
| 31 |
|
| 32 |
public function dispatch_hooks() { |
| 33 |
Admin\Menu::init(); |
| 34 |
\ABlocks\CreatePage\page\ShowPageState::init(); |
| 35 |
Admin\Export::init(); |
| 36 |
Admin\Notice::init(); |
| 37 |
add_filter( 'allowed_redirect_hosts', array( $this, 'add_white_listed_redirect_hosts' ) ); |
| 38 |
add_action( 'current_screen', array( $this, 'conditional_loaded' ) ); |
| 39 |
add_filter( 'plugin_action_links_' . ABLOCKS_PLUGIN_BASENAME, array( $this, 'plugin_action_links' ) ); |
| 40 |
add_filter( 'plugin_row_meta', array( $this, 'add_plugin_links' ), 10, 2 ); |
| 41 |
add_action( 'admin_init', array( $this, 'dispatch_activation_redirect' ), 99 ); |
| 42 |
$this->dispatch_insights(); |
| 43 |
} |
| 44 |
public function add_white_listed_redirect_hosts( $hosts ) { |
| 45 |
$hosts[] = 'ablocks.pro'; |
| 46 |
return $hosts; |
| 47 |
} |
| 48 |
public function conditional_loaded() { |
| 49 |
$screen = get_current_screen(); |
| 50 |
|
| 51 |
if ( ! $screen ) { |
| 52 |
return; |
| 53 |
} |
| 54 |
|
| 55 |
switch ( $screen->id ) { |
| 56 |
case 'ablocks_page_ablocks-get-pro': |
| 57 |
wp_safe_redirect( 'https://ablocks.pro/pricing/' ); |
| 58 |
exit; |
| 59 |
} |
| 60 |
} |
| 61 |
public function add_plugin_links( $links, $file ) { |
| 62 |
if ( ABLOCKS_PLUGIN_BASENAME !== $file ) { |
| 63 |
return $links; |
| 64 |
} |
| 65 |
|
| 66 |
$map_block_links = array( |
| 67 |
'docs' => array( |
| 68 |
'url' => 'https://ablocks.pro/docs/', |
| 69 |
'label' => __( 'Docs', 'ablocks' ), |
| 70 |
'aria-label' => __( 'View aBlocks documentation', 'ablocks' ), |
| 71 |
), |
| 72 |
'video' => array( |
| 73 |
'url' => 'https://www.youtube.com/@ablocksteam', |
| 74 |
'label' => __( 'Video Tutorials', 'ablocks' ), |
| 75 |
'aria-label' => __( 'See Video Tutorials', 'ablocks' ), |
| 76 |
), |
| 77 |
'support' => array( |
| 78 |
'url' => 'https://wordpress.org/support/plugin/ablocks/', |
| 79 |
'label' => __( 'Community Support', 'ablocks' ), |
| 80 |
'aria-label' => __( 'Visit community forums', 'ablocks' ), |
| 81 |
), |
| 82 |
'review' => array( |
| 83 |
'url' => 'https://wordpress.org/support/plugin/ablocks/reviews/#new-post', |
| 84 |
'label' => __( 'Rate the plugin � |
| 85 |
� |
| 86 |
� |
| 87 |
� |
| 88 |
� |
| 89 |
', 'ablocks' ), |
| 90 |
'aria-label' => __( 'Rate the plugin.', 'ablocks' ), |
| 91 |
), |
| 92 |
); |
| 93 |
|
| 94 |
foreach ( $map_block_links as $key => $link ) { |
| 95 |
$links[ $key ] = sprintf( |
| 96 |
'<a target="_blank" href="%s" aria-label="%s">%s</a>', |
| 97 |
esc_url( $link['url'] ), |
| 98 |
esc_attr( $link['aria-label'] ), |
| 99 |
esc_html( $link['label'] ) |
| 100 |
); |
| 101 |
} |
| 102 |
|
| 103 |
return $links; |
| 104 |
} |
| 105 |
public function plugin_action_links( $links ) { |
| 106 |
$settings_link = sprintf( '<a href="%1$s">%2$s</a>', admin_url( 'admin.php?page=ablocks' ), esc_html__( 'Settings', 'ablocks' ) ); |
| 107 |
|
| 108 |
array_unshift( $links, $settings_link ); |
| 109 |
|
| 110 |
if ( ! defined( 'ABLOCKS_PRO_VERSION' ) ) { |
| 111 |
$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' ) ); |
| 112 |
} |
| 113 |
return $links; |
| 114 |
} |
| 115 |
public function dispatch_activation_redirect() { |
| 116 |
if ( get_option( 'ablocks_need_activation_redirect', false ) ) { |
| 117 |
delete_option( 'ablocks_need_activation_redirect' ); |
| 118 |
wp_safe_redirect( admin_url( 'admin.php?page=ablocks' ) ); |
| 119 |
exit; |
| 120 |
} |
| 121 |
} |
| 122 |
public function dispatch_insights() { |
| 123 |
Admin\Insights::init( |
| 124 |
'https://kodezen.com', |
| 125 |
ABLOCKS_PLUGIN_SLUG, |
| 126 |
'plugin', |
| 127 |
ABLOCKS_VERSION, |
| 128 |
[ |
| 129 |
'logo' => ABLOCKS_ASSETS_URL . 'images/logo-shape.svg', // default logo URL |
| 130 |
'optin_message' => 'Help improve aBlocks LMS! Allow anonymous usage tracking?', |
| 131 |
'deactivation_message' => 'If you have a moment, please share why you are deactivating aBlocks:', |
| 132 |
'deactivation_reasons' => [ |
| 133 |
'no_longer_needed' => [ |
| 134 |
'label' => 'I no longer need the plugin', |
| 135 |
], |
| 136 |
'found_a_better_plugin' => [ |
| 137 |
'label' => 'I found a better plugin', |
| 138 |
'has_custom_reason' => true, |
| 139 |
'custom_reason_placeholder' => 'Please share which plugin', |
| 140 |
], |
| 141 |
'couldnt_get_the_plugin_to_work' => [ |
| 142 |
'label' => 'I couldn\'t get the plugin to work', |
| 143 |
], |
| 144 |
'temporary_deactivation' => [ |
| 145 |
'label' => 'It\'s a temporary deactivation', |
| 146 |
], |
| 147 |
'have_academy_pro' => [ |
| 148 |
'label' => 'I have aBlocks Pro', |
| 149 |
'toggle_text' => 'Wait! Don\'t deactivate aBlocks. You have to activate both aBlocks and aBlocks Pro in order for the plugin to work.', |
| 150 |
], |
| 151 |
'other' => [ |
| 152 |
'label' => 'Other', |
| 153 |
'has_custom_reason' => true, |
| 154 |
'custom_reason_placeholder' => 'Please share the reason', |
| 155 |
], |
| 156 |
], |
| 157 |
] |
| 158 |
); |
| 159 |
} |
| 160 |
} |
| 161 |
|