| 1 |
<?php |
| 2 |
namespace WPMapBlock; |
| 3 |
|
| 4 |
class Admin |
| 5 |
{ |
| 6 |
public static function init(){ |
| 7 |
$self = new self(); |
| 8 |
add_filter( 'plugin_row_meta', array( $self, 'add_plugin_links' ), 10, 2 ); |
| 9 |
add_action( 'admin_notices', array($self, 'ablocks_install_notice') ); |
| 10 |
add_action( 'admin_init', [ $self, 'ablocks_hide_notice' ] ); |
| 11 |
$self->dispatch_insights(); |
| 12 |
} |
| 13 |
|
| 14 |
public function add_plugin_links($links, $file){ |
| 15 |
if ( WPMAPBLOCK_PLUGIN_BASENAME !== $file ) { |
| 16 |
return $links; |
| 17 |
} |
| 18 |
|
| 19 |
$map_block_links = array( |
| 20 |
'docs' => array( |
| 21 |
'url' => 'https://academylms.net/how-to-use-wp-map-block/', |
| 22 |
'label' => __( 'Docs', 'wp-map-block' ), |
| 23 |
'aria-label' => __( 'View WP Map Block documentation', 'wp-map-block' ), |
| 24 |
), |
| 25 |
'support' => array( |
| 26 |
'url' => 'https://wordpress.org/support/plugin/wp-map-block/', |
| 27 |
'label' => __( 'Community Support', 'wp-map-block' ), |
| 28 |
'aria-label' => __( 'Visit community forums', 'wp-map-block' ), |
| 29 |
), |
| 30 |
'review' => array( |
| 31 |
'url' => 'https://wordpress.org/support/plugin/wp-map-block/reviews/#new-post', |
| 32 |
'label' => __( 'Rate the plugin � |
| 33 |
� |
| 34 |
� |
| 35 |
� |
| 36 |
� |
| 37 |
', 'wp-map-block' ), |
| 38 |
'aria-label' => __( 'Rate the plugin.', 'wp-map-block' ), |
| 39 |
), |
| 40 |
); |
| 41 |
|
| 42 |
foreach ( $map_block_links as $key => $link ) { |
| 43 |
$links[ $key ] = sprintf( |
| 44 |
'<a target="_blank" href="%s" aria-label="%s">%s</a>', |
| 45 |
esc_url( $link['url'] ), |
| 46 |
esc_attr( $link['aria-label'] ), |
| 47 |
esc_html( $link['label'] ) |
| 48 |
); |
| 49 |
} |
| 50 |
|
| 51 |
return $links; |
| 52 |
} |
| 53 |
|
| 54 |
function ablocks_install_notice() { |
| 55 |
if(get_option('wpmapblock_ablocks_install_notice_hidden')){ |
| 56 |
return; |
| 57 |
} |
| 58 |
if ( current_user_can( 'install_plugins' ) && ! is_plugin_active( 'ablocks/ablocks.php' ) ) { |
| 59 |
// Generate the installation URL |
| 60 |
$install_url = wp_nonce_url( self_admin_url( 'update.php?action=install-plugin&plugin=ablocks' ), 'install-plugin_ablocks' ); |
| 61 |
$hide_url = esc_url( add_query_arg( 'ablocks-hide-notice-by-wpmapblock', 1 ) ); // URL to hide the notice |
| 62 |
// Create the admin notice |
| 63 |
?> |
| 64 |
<div class="wpmapblock-to-ablocks-notice notice notice-warning"> |
| 65 |
<div class="wpmapblock-to-ablocks-notice__entry-left"> |
| 66 |
<img src="<?php echo esc_url(WPMAPBLOCK_ASSETS_URI . 'images/ablocks-editor.png'); ?>" alt="" style="max-width: 100%; height: auto;" /> |
| 67 |
</div> |
| 68 |
<div class="wpmapblock-to-ablocks-notice__entry-right"> |
| 69 |
<h4><?php esc_html_e('Are you building your site with Gutenberg?', 'wp-map-block'); ?></h4> |
| 70 |
<p> |
| 71 |
<?php esc_html_e( 'aBlocks got you covered. Supercharge your site with aBlocks—the ultimate page builder. With 60+ blocks, you can create stunning websites quickly and effortlessly.', 'wp-map-block' ); ?> |
| 72 |
<?php esc_html_e('Learn More:', 'wp-map-block'); ?> <a href="https://ablocks.pro/">ablocks.pro</a> |
| 73 |
</p> |
| 74 |
<p> |
| 75 |
<a href="<?php echo esc_url( $install_url ); ?>" class="button button-primary"> |
| 76 |
<?php esc_html_e( 'Install aBlocks Now', 'wp-map-block' ); ?> |
| 77 |
</a> |
| 78 |
<a href="<?php echo esc_url( $hide_url ); ?>" class="button button-danger"> |
| 79 |
<?php esc_html_e( 'Hide Notice', 'wp-map-block' ); ?> |
| 80 |
</a> |
| 81 |
</p> |
| 82 |
</div> |
| 83 |
</div> |
| 84 |
<style> |
| 85 |
.wpmapblock-to-ablocks-notice { |
| 86 |
display: flex; |
| 87 |
background: linear-gradient(90deg, #7346FF 0%, #3A5CFF 100%); |
| 88 |
border-left-width: 180px; |
| 89 |
border-left-color: black; |
| 90 |
padding: 16px; |
| 91 |
column-gap: 35px; |
| 92 |
} |
| 93 |
.wpmapblock-to-ablocks-notice__entry-left { |
| 94 |
margin-left: -80px; |
| 95 |
} |
| 96 |
.wpmapblock-to-ablocks-notice__entry-right { |
| 97 |
display: flex; |
| 98 |
flex-direction: column; |
| 99 |
justify-content: center; |
| 100 |
} |
| 101 |
.wpmapblock-to-ablocks-notice__entry-right h4{ |
| 102 |
font-size: 22px; |
| 103 |
font-weight: 600; |
| 104 |
line-height: 36px; |
| 105 |
text-align: left; |
| 106 |
color: #FFFFFF; |
| 107 |
margin-top: 0; |
| 108 |
margin-bottom: 10px; |
| 109 |
} |
| 110 |
.wpmapblock-to-ablocks-notice__entry-right p { |
| 111 |
font-size: 14px; |
| 112 |
font-weight: 400; |
| 113 |
line-height: 18px; |
| 114 |
text-align: left; |
| 115 |
color: #FFFFFF; |
| 116 |
} |
| 117 |
.wpmapblock-to-ablocks-notice__entry-right a { |
| 118 |
font-size: 14px; |
| 119 |
font-weight: 400; |
| 120 |
line-height: 18px; |
| 121 |
text-align: left; |
| 122 |
color: #FEFE3F; |
| 123 |
} |
| 124 |
.wpmapblock-to-ablocks-notice__entry-right .button.button-primary { |
| 125 |
background: #FEFE3F; |
| 126 |
color: #272727; |
| 127 |
padding: 5px 20px; |
| 128 |
font-size: 14px; |
| 129 |
border-radius: 4px; |
| 130 |
} |
| 131 |
.wpmapblock-to-ablocks-notice__entry-right .button.button-danger { |
| 132 |
background: transparent; |
| 133 |
color: white; |
| 134 |
text-decoration: underline; |
| 135 |
padding: 10px 25px; |
| 136 |
font-size: 14px; |
| 137 |
border-radius: 4px; |
| 138 |
border: 0; |
| 139 |
} |
| 140 |
@media all and (max-width: 768px){ |
| 141 |
.wpmapblock-to-ablocks-notice { |
| 142 |
border: 0; |
| 143 |
} |
| 144 |
.wpmapblock-to-ablocks-notice__entry-left { |
| 145 |
display: none; |
| 146 |
} |
| 147 |
} |
| 148 |
</style> |
| 149 |
<?php |
| 150 |
} |
| 151 |
} |
| 152 |
public function ablocks_hide_notice() { |
| 153 |
if ( isset( $_GET['ablocks-hide-notice-by-wpmapblock'] ) ) { |
| 154 |
update_option( 'wpmapblock_ablocks_install_notice_hidden', true, false ); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
public function dispatch_insights() { |
| 159 |
Insights::init( |
| 160 |
'https://kodezen.com', |
| 161 |
WPMAPBLOCK_PLUGIN_SLUG, |
| 162 |
'plugin', |
| 163 |
WPMAPBLOCK_VERSION, |
| 164 |
[ |
| 165 |
'logo' => WPMAPBLOCK_ASSETS_URI . 'images/logo.png', // default logo URL |
| 166 |
'optin_message' => 'Help improve WP Map Block! Allow anonymous usage tracking?', |
| 167 |
'deactivation_message' => 'If you have a moment, please share why you are deactivating WP Map Block:', |
| 168 |
'deactivation_reasons' => [ |
| 169 |
'no_longer_needed' => [ |
| 170 |
'label' => 'I no longer need the plugin', |
| 171 |
], |
| 172 |
'found_a_better_plugin' => [ |
| 173 |
'label' => 'I found a better plugin', |
| 174 |
'has_custom_reason' => true, |
| 175 |
'custom_reason_placeholder' => 'Please share which plugin', |
| 176 |
], |
| 177 |
'couldnt_get_the_plugin_to_work' => [ |
| 178 |
'label' => 'I couldn\'t get the plugin to work', |
| 179 |
], |
| 180 |
'temporary_deactivation' => [ |
| 181 |
'label' => 'It\'s a temporary deactivation', |
| 182 |
], |
| 183 |
'other' => [ |
| 184 |
'label' => 'Other', |
| 185 |
'has_custom_reason' => true, |
| 186 |
'custom_reason_placeholder' => 'Please share the reason', |
| 187 |
], |
| 188 |
], |
| 189 |
] |
| 190 |
); |
| 191 |
} |
| 192 |
} |
| 193 |
|