'POST', 'callback' => static function () { update_option( self::DISMISSED, 1, false ); return rest_ensure_response( array( 'dismissed' => true ) ); }, 'permission_callback' => array( Routes::class, 'can_admin' ), ) ); } /** * Checklist steps. * * @return array[] id, label, done, url. */ public static function steps() { $counts = wp_count_posts( PostTypes::ARTICLE ); $defaults = Settings::defaults(); $branded = Settings::get( 'docs_logo' ) || Settings::get( 'primary_color' ) !== $defaults['primary_color'] || get_option( 'kdocs_brand_done' ); $steps = array( array( 'id' => 'permalinks', 'label' => __( 'Use pretty permalinks', 'karma-docs' ), 'done' => Rewrites::pretty(), 'url' => admin_url( 'options-permalink.php' ), ), array( 'id' => 'kb', 'label' => __( 'Create your first knowledge base', 'karma-docs' ), 'done' => count( Taxonomies::get_kbs() ) > 0, 'url' => Admin\Admin::url( 'kbs' ), ), array( 'id' => 'brand', 'label' => __( 'Add your logo or brand color', 'karma-docs' ), 'done' => (bool) $branded, 'url' => Admin\Admin::url( 'design' ), ), array( 'id' => 'articles', 'label' => __( 'Publish 5 articles', 'karma-docs' ), 'done' => (int) ( $counts->publish ?? 0 ) >= 5, 'url' => Admin\Admin::url( 'builder' ), ), array( 'id' => 'search', 'label' => __( 'Try the search on your docs', 'karma-docs' ), 'done' => (bool) get_option( self::SEARCHED ), 'url' => get_post_type_archive_link( PostTypes::ARTICLE ), ), ); if ( Features::is_pro() ) { $steps[] = array( 'id' => 'widget', 'label' => __( 'Turn on the help widget', 'karma-docs' ), 'done' => (bool) Settings::get( 'widget_enabled' ), 'url' => Admin\Admin::url( 'settings', array( 'tab' => 'widget' ) ), ); } return $steps; } /** * Adds the checklist to the dashboard data while it is not dismissed. * * @param array $data Dashboard data. * @return array */ public function dashboard( $data ) { $steps = self::steps(); $data['onboarding'] = get_option( self::DISMISSED ) || ! current_user_can( \KarmaDocs\Capabilities::SETTINGS ) ? null : array( 'steps' => $steps, 'done' => count( array_filter( wp_list_pluck( $steps, 'done' ) ) ), ); $data['activity'] = Activity::feed( 8 ); return $data; } }