p@p@p@p@p@p@@P@@@0@0@@@p@p@p@p@p@p@p@p@p@p@p@p@p@p@p@p@@@p@О@@@Р@Р@@@@@P@p@@@@@@P@0@p@@@P@p@@@@@@P@0@@@@@@p@@@P@p@@@@@@P@0@p@@@P@p@@@@@@P@0@@@@@@@p@@P@@0@@@@@p@p@@@0@@@p@@@p@Р@@P@P@P@P@P@0@@@@@P@0@0@p@@P@@p@P@@p@@@@P@@@0@@P@@@P@@@@@P@0@@@@P@@@@@0@Ж@p@И@p@Й@@@0@П@К@P@@@@P@Р@@0@Ж@p@И@p@Й@@p@@@0@Ж@p@И@p@Й@p@Р@О@@@0@Ж@p@И@p@Й@П@@@P@P@@@Р@@0@@@@P@P@@@П@@@p@@@@@@@@p@@@@@@Rp@@P@p@p@@P@@@ * * @since 6.14.0 * * @return bool */ public function is_old_plugin_installed(): bool { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . 'wp-admin/includes/plugin.php'; } $plugins = get_plugins(); return array_key_exists( 'the-events-calendar-category-colors/the-events-calendar-category-colors.php', $plugins ); } /** * Checks if migration has not started. * * @since 6.14.0 * * @return bool */ public function is_migration_not_started(): bool { $migration_status = Status::get_migration_status(); return ( ! isset( $migration_status['status'] ) || $migration_status['status'] === Status::$not_started ); } /** * Checks if the plugin has any category meta values. * * @since 6.14.0 * * @return bool */ public function has_category_meta(): bool { $categories = get_terms( [ 'taxonomy' => Tribe__Events__Main::TAXONOMY, 'hide_empty' => false, 'number' => 1, ] ); if ( empty( $categories ) ) { return false; } // Check for border color meta (primary in new system). return ! empty( get_term_meta( $categories[0]->term_id, Config::META_KEY_PREFIX . Config::META_KEY_MAP['border'], true ) ); } /** * Checks if the plugin has original settings. * * @since 6.14.0 * * @return bool */ public function has_original_settings(): bool { return ! empty( get_option( Config::ORIGINAL_SETTINGS_OPTION ) ); } /** * Deactivates the legacy plugin. * * @since 6.14.0 * * @return void */ public function deactivate_plugin(): void { deactivate_plugins( self::PLUGIN_FILE ); } /** * Handles the migration process when the user clicks the migration button. * * @since 6.14.0 */ public function handle_migration(): void { check_admin_referer( 'tec_start_category_colors_migration' ); if ( ! current_user_can( 'manage_options' ) ) { wp_die( esc_html__( 'You do not have sufficient permissions to perform this action.', 'the-events-calendar' ) ); } $flow = tribe( Migration_Flow::class ); $result = $flow->initialize(); if ( is_wp_error( $result ) ) { // Show error notice. AdminNotices::show( 'tec_category_colors_migration_error', sprintf( '

%s

%s

', __( 'Migration Error', 'the-events-calendar' ), $result->get_error_message() ) ) ->urgency( 'error' ) ->dismissible( true ) ->inline( true ); } else { // Set a one-time user meta flag for the background notice. update_user_meta( get_current_user_id(), '_tec_category_colors_migration_notice', 1 ); } // Redirect back to the same page (no redirect to category page). //phpcs:ignore WordPressVIPMinimum.Security.ExitAfterRedirect.NoExit wp_safe_redirect( wp_get_referer() ?: admin_url() ); tribe_exit(); } /** * Disables the save button for the Category Colors settings tab. * * @since 6.14.0 * * @param array $no_save_tabs The tabs that should not save. * * @return array The tabs that should not save. */ public function disable_save_button_for_category_colors( $no_save_tabs ) { $no_save_tabs[] = 'category-colors'; return $no_save_tabs; } /** * Prevents the legacy plugin from being reactivated. * * @since 6.14.0 * * @param array $actions The list of action links. * * @return array Modified list without 'activate'. */ public function prevent_original_plugin_reactivation( array $actions ): array { unset( $actions['activate'] ); return $actions; } /** * Determines whether the migration controller should be registered. * * This will return true if: * - The legacy Category Colors plugin is installed and active. * - The migration status is either not set or not in the list of statuses * that indicate the migration has already been skipped or completed. * * @since 6.14.0 * * @return bool Whether the migration controller should be initialized. */ public function should_show_migration_controller(): bool { $status = Status::get_migration_status(); $skip_statuses = [ Status::$preprocessing_skipped, Status::$postprocessing_completed, ]; return ( $this->is_old_plugin_installed() && $this->is_old_plugin_active() && ( ! isset( $status['status'] ) || ! in_array( $status['status'], $skip_statuses, true ) ) ); } /** * Checks if the current page is a TEC or Event Tickets admin page. * * @since 6.14.0 * * @return bool True if on a TEC/Event Tickets admin page, false otherwise. */ public function is_tec_admin_page(): bool { $helper = Tribe__Admin__Helpers::instance(); // If we are not on a tec post-type admin screen, bail. if ( ! $helper->is_post_type_screen( TEC::POSTTYPE ) ) { return false; } /** * Filter to determine if we are on a TEC admin page. * Allows other classes to hook in and modify the return value. * * @since 6.14.0 * * @param bool $is_tec_admin_page Whether we are on a TEC admin page. */ return (bool) apply_filters( 'tec_category_colors_is_tec_admin_page', true ); } }