is_active() && $this->get_backup_count() > 0; } /** * The plugin's own admin screen. * * @since 4.10.0 * * @return string */ public function get_setup_url(): string { return admin_url( 'admin.php?page=duplicator' ); } /** * How many backups the user has taken. * * @since 4.10.0 * * @return int */ public function get_backup_count(): int { if ( ! $this->is_loaded() ) { return 0; } global $wpdb; $table = $this->is_pro_active() ? $wpdb->prefix . 'duplicator_backups' : $wpdb->prefix . 'duplicator_packages'; $blog_id = get_current_blog_id(); $table_cache_key = "wpms_dup_table_exists_{$blog_id}"; $count_cache_key = "wpms_dup_package_count_{$blog_id}"; $table_exists = wp_cache_get( $table_cache_key, 'wp-mail-smtp' ); if ( $table_exists === false ) { // Direct query required: no WP API exists for another plugin's custom tables. // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching $table_exists = $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->esc_like( $table ) ) ); wp_cache_set( $table_cache_key, $table_exists, 'wp-mail-smtp', 60 ); } if ( $table_exists !== $table ) { return 0; } $count = wp_cache_get( $count_cache_key, 'wp-mail-smtp' ); if ( $count === false ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared $count = (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$table}" ); wp_cache_set( $count_cache_key, $count, 'wp-mail-smtp', 60 ); } return (int) $count; } /** * How many backup schedules are configured. * * @since 4.10.0 * * @return int */ public function get_schedule_count(): int { $classes = [ '\Duplicator\Addons\ScheduleAddon\Models\ScheduleEntity', '\Duplicator\Models\ScheduleEntity', ]; foreach ( $classes as $class ) { if ( class_exists( $class ) && method_exists( $class, 'count' ) ) { return (int) $class::count(); } } return 0; } /** * Drop the welcome-screen redirect Duplicator arms on activation. * * @since 4.10.0 */ public function after_activation(): void { delete_option( 'duplicator_redirect_to_welcome' ); } }