ajax
5 months ago
assets
5 months ago
includes
5 months ago
pages
5 months ago
activation.php
5 months ago
boot.php
5 months ago
index.php
3 years ago
boot.php
357 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Admin boot |
| 4 | * |
| 5 | * @version 1.0 |
| 6 | */ |
| 7 | |
| 8 | // Exit if accessed directly |
| 9 | if ( ! defined( 'ABSPATH' ) ) { |
| 10 | exit; |
| 11 | } |
| 12 | |
| 13 | /** |
| 14 | * Проверяем таблицу в базе данны� |
| 15 | |
| 16 | * |
| 17 | * Если таблица не существует или её структура устарела, то обновляем. |
| 18 | * Проверка проводится при каждой инициализации плагина т.к. структура может измениться |
| 19 | * после очередного обновления плагина. |
| 20 | * |
| 21 | * @return bool |
| 22 | */ |
| 23 | add_action( |
| 24 | 'admin_init', |
| 25 | function () { |
| 26 | RIO_Process_Queue::try_create_plugin_tables(); |
| 27 | } |
| 28 | ); |
| 29 | |
| 30 | /** |
| 31 | * |
| 32 | * @since 1.3.0 |
| 33 | */ |
| 34 | add_filter( |
| 35 | 'wbcr/clearfy/components/items_list', |
| 36 | function ( $components ) { |
| 37 | if ( wrio_is_clearfy_license_activate() ) { |
| 38 | return $components; |
| 39 | } |
| 40 | if ( ! empty( $components ) ) { |
| 41 | foreach ( $components as $key => $component ) { |
| 42 | if ( 'robin_image_optimizer' == $component['name'] ) { |
| 43 | unset( $components[ $key ] ); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return $components; |
| 49 | } |
| 50 | ); |
| 51 | |
| 52 | /** |
| 53 | * Добавляет карточку компонента на страницу компонентов |
| 54 | * |
| 55 | * @since 1.3.0 |
| 56 | */ |
| 57 | add_action( |
| 58 | 'wbcr/clearfy/components/custom_plugins_card', |
| 59 | function () { |
| 60 | if ( ! wrio_is_clearfy_license_activate() ) { |
| 61 | $view = WRIO_Views::get_instance( WRIO_PLUGIN_DIR ); |
| 62 | $view->print_template( 'clearfy-component-card' ); |
| 63 | } |
| 64 | } |
| 65 | ); |
| 66 | |
| 67 | /** |
| 68 | * We asset migration scripts to all admin panel pages |
| 69 | * |
| 70 | * @since 1.3.0 |
| 71 | */ |
| 72 | add_action( |
| 73 | 'admin_enqueue_scripts', |
| 74 | function () { |
| 75 | if ( ! current_user_can( 'update_plugins' ) || ! wbcr_rio_has_meta_to_migrate() ) { |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | wp_enqueue_script( |
| 80 | 'wrio-meta-migrations', |
| 81 | WRIO_PLUGIN_URL . '/admin/assets/js/meta-migrations.js', |
| 82 | [ |
| 83 | 'jquery', |
| 84 | 'wbcr-factory-clearfy-000-global', |
| 85 | ], |
| 86 | WRIO_Plugin::app()->getPluginVersion() |
| 87 | ); |
| 88 | } |
| 89 | ); |
| 90 | |
| 91 | /** |
| 92 | * Plugin was heavy migrated into new architecture. Specifically, post meta was moved to separate table and |
| 93 | * therefore it is required to migrate all of them to new table. |
| 94 | * |
| 95 | * This action prints a notice, which contains clickable link with JS onclick event, which invokes AJAX request |
| 96 | * to migrate these post metas to new table. |
| 97 | * |
| 98 | * Once all post meta migrated, notice would not be shown anymore. |
| 99 | * |
| 100 | * @param $notices |
| 101 | * |
| 102 | * @return array |
| 103 | * @since 1.3.0 |
| 104 | * |
| 105 | * @see wbcr_rio_migrate_postmeta_to_process_queue() for further information about AJAX processing function. |
| 106 | * @see wbcr_rio_has_meta_to_migrate() used to check whether to show notice or not. |
| 107 | * |
| 108 | * @see RIO_Process_Queue for further information about new table. |
| 109 | */ |
| 110 | add_action( |
| 111 | 'wbcr/factory/admin_notices', |
| 112 | function ( $notices ) { |
| 113 | |
| 114 | if ( ! current_user_can( 'update_plugins' ) || ! wbcr_rio_has_meta_to_migrate() ) { |
| 115 | return $notices; |
| 116 | } |
| 117 | |
| 118 | $notices[] = [ |
| 119 | 'id' => WRIO_Plugin::app()->getPrefix() . 'meta_to_migration', |
| 120 | 'type' => 'warning', |
| 121 | 'dismissible' => false, |
| 122 | 'dismiss_expires' => 0, |
| 123 | 'text' => '<p><b>' . WRIO_Plugin::app()->getPluginTitle() . ':</b> ' . wrio_get_meta_migration_notice_text() . '</p>', |
| 124 | ]; |
| 125 | |
| 126 | return $notices; |
| 127 | } |
| 128 | ); |
| 129 | |
| 130 | /** |
| 131 | * Plugin was heavy migrated into new architecture. Specifically, post meta was moved to separate table and |
| 132 | * therefore it is required to migrate all of them to new table. |
| 133 | * |
| 134 | * This action prints a notice, which contains clickable link with JS onclick event, which invokes AJAX request |
| 135 | * to migrate these post metas to new table. |
| 136 | * |
| 137 | * Once all post meta migrated, notice would not be shown anymore. |
| 138 | * |
| 139 | * @param Wbcr_Factory480_Plugin $plugin |
| 140 | * @param Wbcr_FactoryPages480_ImpressiveThemplate $obj |
| 141 | * |
| 142 | * @since 1.3.0 |
| 143 | * |
| 144 | * @see wbcr_rio_migrate_postmeta_to_process_queue() for further information about AJAX processing function. |
| 145 | * @see wbcr_rio_has_meta_to_migrate() used to check whether to show notice or not. |
| 146 | * |
| 147 | * @see RIO_Process_Queue for further information about new table. |
| 148 | */ |
| 149 | add_action( |
| 150 | 'wbcr/factory/pages/impressive/print_all_notices', |
| 151 | function ( $plugin, $obj ) { |
| 152 | if ( ( $plugin->getPluginName() != WRIO_Plugin::app()->getPluginName() ) || ! wbcr_rio_has_meta_to_migrate() ) { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | $obj->printWarningNotice( wrio_get_meta_migration_notice_text() ); |
| 157 | }, |
| 158 | 10, |
| 159 | 2 |
| 160 | ); |
| 161 | |
| 162 | /*** |
| 163 | * Flush configuration after saving the settings |
| 164 | * |
| 165 | * @param WRIO_Plugin $plugin |
| 166 | * @param Wbcr_FactoryPages480_ImpressiveThemplate $obj |
| 167 | * |
| 168 | * @return bool |
| 169 | */ |
| 170 | /* |
| 171 | add_action('wbcr_factory_480_imppage_after_form_save', function ($plugin, $obj) { |
| 172 | $is_rio = WRIO_Plugin::app()->getPluginName() == $plugin->getPluginName(); |
| 173 | |
| 174 | if( $is_rio ) { |
| 175 | WRIO_Cron::check(); |
| 176 | } |
| 177 | }, 10, 2);*/ |
| 178 | |
| 179 | /** |
| 180 | * Виджет отзывов |
| 181 | * |
| 182 | * @param string $page_url |
| 183 | * @param string $plugin_name |
| 184 | * |
| 185 | * @return string |
| 186 | */ |
| 187 | function wio_rating_widget_url( $page_url, $plugin_name ) { |
| 188 | if ( $plugin_name == WRIO_Plugin::app()->getPluginName() ) { |
| 189 | return 'https://wordpress.org/support/plugin/robin-image-optimizer/reviews/#new-post'; |
| 190 | } |
| 191 | |
| 192 | return $page_url; |
| 193 | } |
| 194 | |
| 195 | add_filter( 'wbcr_factory_pages_480_imppage_rating_widget_url', 'wio_rating_widget_url', 10, 2 ); |
| 196 | |
| 197 | /** |
| 198 | * |
| 199 | * @param array $widgets |
| 200 | * @param string $position |
| 201 | * @param Wbcr_Factory480_Plugin $plugin |
| 202 | */ |
| 203 | add_filter( |
| 204 | 'wbcr/factory/pages/impressive/widgets', |
| 205 | function ( $widgets, $position, $plugin ) { |
| 206 | if ( $plugin->getPluginName() == WRIO_Plugin::app()->getPluginName() ) { |
| 207 | require_once WRIO_PLUGIN_DIR . '/admin/includes/sidebar-widgets.php'; |
| 208 | |
| 209 | if ( wrio_is_license_activate() ) { |
| 210 | unset( $widgets['donate_widget'] ); |
| 211 | |
| 212 | if ( $position == 'right' ) { |
| 213 | unset( $widgets['adverts_widget'] ); |
| 214 | unset( $widgets['business_suggetion'] ); |
| 215 | unset( $widgets['rating_widget'] ); |
| 216 | unset( $widgets['info_widget'] ); |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | if ( $position == 'bottom' ) { |
| 221 | $widgets['support'] = wrio_get_sidebar_support_widget(); |
| 222 | }*/ |
| 223 | |
| 224 | return $widgets; |
| 225 | } elseif ( $position == 'right' ) { |
| 226 | unset( $widgets['info_widget'] ); |
| 227 | unset( $widgets['rating_widget'] ); |
| 228 | // $widgets['support'] = wrio_get_sidebar_support_widget(); |
| 229 | |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | return $widgets; |
| 234 | }, |
| 235 | 20, |
| 236 | 3 |
| 237 | ); |
| 238 | |
| 239 | /** |
| 240 | * Заменяет заголовок в рекламном виджете |
| 241 | * |
| 242 | * @param array $features |
| 243 | * @param string $plugin_name |
| 244 | * @param string $page_id |
| 245 | */ |
| 246 | add_filter( |
| 247 | 'wbcr/clearfy/pages/suggetion_title', |
| 248 | function ( $features, $plugin_name, $page_id ) { |
| 249 | if ( ! empty( $plugin_name ) && ( $plugin_name == WRIO_Plugin::app()->getPluginName() ) ) { |
| 250 | return __( 'ROBIN IMAGE OPTIMIZER PRO', 'robin-image-optimizer' ); |
| 251 | } |
| 252 | |
| 253 | return $features; |
| 254 | }, |
| 255 | 20, |
| 256 | 3 |
| 257 | ); |
| 258 | |
| 259 | /** |
| 260 | * Заменяем премиум возможности в рекламном виджете |
| 261 | * |
| 262 | * @param array $features |
| 263 | * @param string $plugin_name |
| 264 | * @param string $page_id |
| 265 | */ |
| 266 | add_filter( |
| 267 | 'wbcr/clearfy/pages/suggetion_features', |
| 268 | function ( $features, $plugin_name, $page_id ) { |
| 269 | if ( ! empty( $plugin_name ) && ( $plugin_name == WRIO_Plugin::app()->getPluginName() ) ) { |
| 270 | $upgrade_feature = []; |
| 271 | $upgrade_feature[] = __( 'Automatic conversion to WebP', 'robin-image-optimizer' ); |
| 272 | $upgrade_feature[] = __( 'You can optimize custom folders', 'robin-image-optimizer' ); |
| 273 | $upgrade_feature[] = __( 'Supports NextGen gallery', 'robin-image-optimizer' ); |
| 274 | $upgrade_feature[] = __( 'Multisite support', 'robin-image-optimizer' ); |
| 275 | $upgrade_feature[] = __( 'Fast optimization servers', 'robin-image-optimizer' ); |
| 276 | $upgrade_feature[] = __( 'Ad-free experience', 'robin-image-optimizer' ); |
| 277 | $upgrade_feature[] = __( 'Priority support', 'robin-image-optimizer' ); |
| 278 | |
| 279 | return $upgrade_feature; |
| 280 | } |
| 281 | |
| 282 | return $features; |
| 283 | }, |
| 284 | 20, |
| 285 | 3 |
| 286 | ); |
| 287 | |
| 288 | /** |
| 289 | * Заменяем премиум возможности в рекламном виджете |
| 290 | * |
| 291 | * @param array $messages |
| 292 | * @param string $type |
| 293 | * @param string $plugin_name |
| 294 | */ |
| 295 | add_filter( |
| 296 | 'wbcr/factory/premium/notice_text', |
| 297 | function ( $text, $type, $plugin_name ) { |
| 298 | if ( WRIO_Plugin::app()->getPluginName() != $plugin_name ) { |
| 299 | return $text; |
| 300 | } |
| 301 | |
| 302 | $license_page_url = WRIO_Plugin::app()->getPluginPageUrl( 'rio_license' ); |
| 303 | |
| 304 | if ( null === $license_page_url ) { |
| 305 | return $text; |
| 306 | } |
| 307 | |
| 308 | if ( 'need_activate_license' == $type ) { |
| 309 | return sprintf( |
| 310 | // translators: %1$s is opening <a> tag, %2$s is closing </a> tag. |
| 311 | __( '%1$sLicense activation%2$s required. A license is required to get premium plugin updates, as well as to get additional services.', 'robin-image-optimizer' ), |
| 312 | '<a href="' . esc_url( $license_page_url ) . '">', |
| 313 | '</a>' |
| 314 | ); |
| 315 | } elseif ( 'need_renew_license' == $type ) { |
| 316 | return sprintf( |
| 317 | // translators: %1$s is opening <a> tag, %2$s is closing </a> tag. |
| 318 | __( 'Your %1$slicense%2$s has expired. You can no longer get premium plugin updates, premium support and your access to services has been suspended.', 'robin-image-optimizer' ), |
| 319 | '<a href="' . esc_url( $license_page_url ) . '">', |
| 320 | '</a>' |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | return $text; |
| 325 | }, |
| 326 | 10, |
| 327 | 3 |
| 328 | ); |
| 329 | |
| 330 | /** |
| 331 | * Check if the AVIF upsell banner has been dismissed by the current user. |
| 332 | * |
| 333 | * @return bool True if dismissed, false otherwise. |
| 334 | */ |
| 335 | function wrio_is_avif_banner_dismissed() { |
| 336 | return (bool) get_user_meta( get_current_user_id(), 'wrio_avif_banner_dismissed', true ); |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * AJAX handler for dismissing the AVIF upsell banner. |
| 341 | */ |
| 342 | add_action( |
| 343 | 'wp_ajax_wrio_dismiss_avif_banner', |
| 344 | function () { |
| 345 | check_ajax_referer( 'wrio_dismiss_avif_banner', 'nonce' ); |
| 346 | |
| 347 | if ( ! current_user_can( 'manage_options' ) ) { |
| 348 | wp_send_json_error( [ 'message' => __( 'Permission denied.', 'robin-image-optimizer' ) ] ); |
| 349 | } |
| 350 | |
| 351 | // Dismiss permanently. |
| 352 | update_user_meta( get_current_user_id(), 'wrio_avif_banner_dismissed', 1 ); |
| 353 | |
| 354 | wp_send_json_success(); |
| 355 | } |
| 356 | ); |
| 357 |