' . esc_html__( 'Starter sites', 'objeka-toolkit' ) . '' ); } return $links; } /** * Read the bundled starter manifest; no remote catalogue or account. * * @return array Available single-product starters. */ public static function starters() { $file = OBJEKA_TOOLKIT_DIR . 'data/starters.json'; $data = file_exists( $file ) ? json_decode( file_get_contents( $file ), true ) : array(); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Bundled local manifest. return is_array( $data ) ? $data : array(); } /** * Resolve the exact content requested before any import writes occur. * * @param string $selected Selected starter key. * @param bool $include_companion Whether to include its matching accessory. * @return array|WP_Error Validated selection or a useful error. */ public static function plan( $selected, $include_companion = false ) { $starters = array_column( self::starters(), null, 'key' ); if ( ! isset( $starters[ $selected ] ) ) { return new WP_Error( 'objeka_starter', __( 'Choose an available single-product starter site.', 'objeka-toolkit' ) ); } $starter = $starters[ $selected ]; $keys = array( $selected ); if ( $include_companion && ! empty( $starter['companion'] ) ) { $keys[] = $starter['companion']; } $items = json_decode( file_get_contents( OBJEKA_TOOLKIT_DIR . 'data/products.json' ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Bundled local manifest. $demos = json_decode( file_get_contents( OBJEKA_TOOLKIT_DIR . 'data/demos.json' ), true ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Bundled local manifest. $items = is_array( $items ) ? array_values( array_filter( $items, static fn( $item ) => in_array( $item['key'], $keys, true ) ) ) : array(); $demos = is_array( $demos ) ? array_values( array_filter( $demos, static fn( $demo ) => $selected === $demo[0] ) ) : array(); if ( count( $items ) !== count( $keys ) || 1 !== count( $demos ) ) { return new WP_Error( 'objeka_starter_data', __( 'The selected starter is incomplete. Reinstall the current Objeka packages and try again.', 'objeka-toolkit' ) ); } return array( 'starter' => $starter, 'products' => $items, 'demos' => $demos, ); } /** * Load the library skin only on its own admin page. * * @param string $hook Current admin screen identifier. */ public static function assets( $hook ) { if ( 'tools_page_objeka-demos' === $hook ) { wp_enqueue_style( 'objeka-starter-library', plugins_url( 'assets/css/starter-library-admin.css', OBJEKA_TOOLKIT_FILE ), array(), OBJEKA_TOOLKIT_VERSION ); } } /** Render the complete free library without Pro placeholders or upsells. */ public static function screen() { if ( ! current_user_can( 'manage_options' ) || ! current_user_can( 'manage_woocommerce' ) ) { return; } // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Read-only local catalogue search. $search = isset( $_GET['starter_search'] ) ? sanitize_text_field( wp_unslash( $_GET['starter_search'] ) ) : ''; $starters = self::starters(); $ready = 'objeka' === get_template() && class_exists( 'WooCommerce' ); ?>
post_status ) { return; } wp_safe_redirect( get_permalink( $page ), 301 ); exit; } } }