' . esc_html__( 'Documentation', 'printblob' ) . ''; $links[] = '' . esc_html__( 'Rate PrintBlob ★★★★★', 'printblob' ) . ''; if ( ! ( $pro_active ?? self::pro_active() ) ) { $links[] = '' . esc_html__( 'PrintBlob Pro add-on: the 3D view and more', 'printblob' ) . ''; } return $links; } public static function add_page( array $pages ): array { require_once __DIR__ . '/class-settings-page.php'; $pages[] = new Settings_Page(); return $pages; } public static function url( string $section = '' ): string { return admin_url( 'admin.php?page=wc-settings&tab=printblob' . ( $section ? '§ion=' . $section : '' ) ); } public static function action_links( array $links ): array { array_unshift( $links, sprintf( '%s', esc_url( self::url() ), esc_html__( 'Settings', 'printblob' ) ) ); return $links; } /** Attribute taxonomy holding the product colours, e.g. "pa_color". */ public static function color_attribute(): string { return self::attribute_option( self::COLOR_ATTRIBUTE, 'pa_color' ); } /** Attribute taxonomy holding the sizes, e.g. "pa_size". Empty when the products have no sizes. */ public static function size_attribute(): string { return self::attribute_option( self::SIZE_ATTRIBUTE, 'pa_size' ); } private static function attribute_option( string $option, string $fallback ): string { $value = sanitize_key( (string) get_option( $option, $fallback ) ); return str_starts_with( $value, 'pa_' ) ? $value : $fallback; } public static function designer_page(): int { return (int) get_option( self::DESIGNER_PAGE ); } /** Whether a screen is PrintBlob's own: its menu's pages, its settings tab, or a mockup screen. */ public static function own_screen( string $screen_id, string $post_type, string $tab ): bool { return Admin_Menu::SCREEN === $screen_id || str_starts_with( $screen_id, Admin_Menu::SCREEN_PREFIX ) || ( 'woocommerce_page_wc-settings' === $screen_id && 'printblob' === $tab ) || Mockups::POST_TYPE === $post_type; } /** Whether the admin screen being shown is one of PrintBlob's own. */ public static function on_own_screen(): bool { $screen = get_current_screen(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Which settings tab is shown. $tab = isset( $_GET['tab'] ) ? sanitize_key( wp_unslash( $_GET['tab'] ) ) : ''; return $screen && self::own_screen( (string) $screen->id, (string) $screen->post_type, $tab ); } /** * Whether PrintBlob Pro's features run on this site: only then does Pro replace the print queue, make print files * and take the place of its controls here. Installed without a licence that allows them, it does none of that. */ public static function pro_active(): bool { /** * Filters whether PrintBlob Pro's features run on this site. PrintBlob Pro answers true where they register. * * @param bool $active Whether they run; false by default, true for a PrintBlob Pro older than 1.4.1 (released_pro_runs()). */ return (bool) apply_filters( 'printblob_pro_active', self::released_pro_runs( defined( 'PRINTBLOB_PRO_VERSION' ) ? (string) PRINTBLOB_PRO_VERSION : null ) ); } /** * Whether a PrintBlob Pro of this version runs without saying so: one released before 1.4.1 never filters * printblob_pro_active, and PrintBlob before 1.4.1 counted it as running while it was installed. A shop whose * PrintBlob updates before its Pro keeps that answer until Pro updates too. * * @param string|null $pro_version PrintBlob Pro's version ("1.4.0", "1.4.0-starter"), or null without Pro. */ public static function released_pro_runs( ?string $pro_version ): bool { return null !== $pro_version && version_compare( (string) strtok( $pro_version, '-' ), '1.4.1', '<' ); } /** Whether PrintBlob Pro is installed (its starter included), whether or not its licence lets its features run. */ public static function pro_installed(): bool { return defined( 'PRINTBLOB_PRO_VERSION' ); } /** * The settings screen's PrintBlob Pro rows while Pro is not active: "Upload your own fonts" switched off in the designer * section, and a panel at the end with what Pro adds and its prices. * * @param bool|null $pro_active Whether Pro is active; self::pro_active() when null. * @return array{fonts:array[], panel:array[]} WooCommerce settings rows, none while Pro is active. */ public static function pro_rows( ?bool $pro_active = null ): array { if ( $pro_active ?? self::pro_active() ) { return array( 'fonts' => array(), 'panel' => array(), ); } return array( 'fonts' => array( array( 'id' => 'printblob_pro_fonts', 'type' => 'printblob_pro_lock', 'title' => __( 'Upload your own fonts', 'printblob' ), 'from' => 'settings-fonts', ), ), 'panel' => array( array( 'id' => 'printblob_pro', 'type' => 'title', 'title' => __( 'PrintBlob Pro', 'printblob' ), 'desc' => sprintf( '

%1$s %2$s %3$s

%5$s %7$s

%8$s

', esc_html( Pro::offer_text() . ':' ), esc_html( Pro::prices_text() . '.' ), esc_html( Pro::refund_text() ), Pro::points_html(), Pro::buttons_html( 'settings-panel' ), esc_url( Pro::compare_url() ), esc_html__( 'Compare free and Pro', 'printblob' ), esc_html( Pro::separate_text() ) ), ), array( 'id' => 'printblob_pro', 'type' => 'sectionend', ), ), ); } /** * A Pro row of the settings screen: its name and the control that opens the upgrade box. * * @param array $field The row: title and from (its placement). */ public static function pro_lock_field( array $field ): void { ?> label, for the settings selects. */ public static function attribute_choices(): array { $choices = array(); foreach ( wc_get_attribute_taxonomies() as $attribute ) { $choices[ wc_attribute_taxonomy_name( $attribute->attribute_name ) ] = $attribute->attribute_label; } return $choices; } }