register( 'adpresso-migration-root', __( 'Migration', 'adpresso' ), [ 'location' => 'admin_bar', 'context' => null, ] ); $this->register_shortcode_takeover_status(); $this->register_id_map_sizes(); $this->register_last_import(); } /** * Reports whether AdPresso's legacy-shortcode takeover actually owns [the_ad]. * * @return void */ protected function register_shortcode_takeover_status(): void { if ( $this->is_the_ad_shortcode_owned_by_adpresso() ) { $status_text = __( 'active - AdPresso owns [the_ad]', 'adpresso' ); $type = 'success'; } elseif ( shortcode_exists( 'the_ad' ) ) { $status_text = __( 'inactive - [the_ad] already registered by another plugin', 'adpresso' ); $type = 'warning'; } else { $status_text = __( 'inactive - not yet registered', 'adpresso' ); $type = 'info'; } NotificationManager::get()->register( 'adpresso-migration-takeover', __( 'Shortcode Takeover', 'adpresso' ) . ': ' . $status_text, [ 'location' => 'admin_bar', 'context' => 'adpresso-migration-root', 'type' => $type, ] ); } /** * @return bool */ protected function is_the_ad_shortcode_owned_by_adpresso(): bool { global $shortcode_tags; $callback = $shortcode_tags['the_ad'] ?? null; return is_array( $callback ) && ( $callback[0] ?? null ) instanceof A2ShortcodeTakeover; } /** * Reports how many legacy Advanced Ads IDs are currently mapped to an AdPresso entity, per entity type. * * @return void */ protected function register_id_map_sizes(): void { $maps = [ 'adpresso_a2_ad_map' => __( 'Ads', 'adpresso' ), 'adpresso_a2_group_map' => __( 'Groups', 'adpresso' ), 'adpresso_a2_placement_map' => __( 'Placements', 'adpresso' ), ]; foreach ( $maps as $option => $label ) { $count = count( get_option( $option, [] ) ); NotificationManager::get()->register( 'adpresso-migration-map-' . $option, sprintf( '%s: %d %s', $label, $count, __( 'mapped', 'adpresso' ) ), [ 'location' => 'admin_bar', 'context' => 'adpresso-migration-root', 'type' => $count > 0 ? 'success' : 'info', ] ); } } /** * Reports the most recent import session from the import log. * * @return void */ protected function register_last_import(): void { if ( ! class_exists( ImportRollback::class ) ) { return; } $latest = ImportRollback::get_import_history()[0] ?? null; if ( ! $latest ) { NotificationManager::get()->register( 'adpresso-migration-last-import', __( 'Last Import', 'adpresso' ) . ': ' . __( 'none recorded', 'adpresso' ), [ 'location' => 'admin_bar', 'context' => 'adpresso-migration-root', 'type' => 'info', ] ); return; } NotificationManager::get()->register( 'adpresso-migration-last-import', sprintf( '%s: %s (%s) - %s', __( 'Last Import', 'adpresso' ), esc_html( $latest->importer_id ), esc_html( $latest->status ), esc_html( $latest->imported_at ) ), [ 'location' => 'admin_bar', 'context' => 'adpresso-migration-root', 'type' => $latest->status === 'rolled_back' ? 'warning' : 'success', 'link' => admin_url( 'admin.php?page=adpresso-tools&tab=history' ), ] ); } }