' . '' . '' . ''; } /** * The top-level admin-menu icon as a data URI. * * WordPress renders a `data:image/svg+xml;base64,` icon as an image and * its svg-painter recolours every `fill` to the active admin colour * scheme, which is why the paths are filled rather than stroked. * * @since 1.21.6 * * @return string Value for the `$icon_url` argument of add_menu_page(). */ public static function menu_icon(): string { $svg = '' . '' . '' . ''; return 'data:image/svg+xml;base64,' . base64_encode( $svg ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode -- Menu icon data URI, the documented WordPress mechanism. } /** * URL of a page in the public documentation. * * @since 1.21.6 * * @param string $slug Page slug, e.g. `page-caching`; empty for the index. * A `#fragment` suffix is kept as-is. * @return string Absolute URL. */ public static function docs_url( string $slug = '' ): string { /** * Filters the base URL of the public documentation. * * @since 1.21.6 * * @param string $base Base URL, with a trailing slash. */ $base = (string) apply_filters( 'cachingout_docs_url', self::DOCS_URL ); $base = trailingslashit( $base ); $slug = trim( $slug, '/' ); if ( '' === $slug ) { return $base; } $fragment = ''; $hash = strpos( $slug, '#' ); if ( false !== $hash ) { $fragment = substr( $slug, $hash ); $slug = rtrim( substr( $slug, 0, $hash ), '/' ); } return $base . $slug . '/' . $fragment; } /** * URL of the page where a licence is bought or renewed. * * @since 1.21.9 * * @return string Absolute URL, with a trailing slash. */ public static function pricing_url(): string { /** * Filters the URL of the pricing / renewal page. * * @since 1.21.9 * * @param string $url Absolute URL. */ $url = (string) apply_filters( 'cachingout_pricing_url', self::PRICING_URL ); return '' === trim( $url ) ? self::PRICING_URL : trailingslashit( $url ); } /** * Default name of the query argument that carries a partner code on the * Upgrade link (Partner Engine FR-ATT-07). * * @since 1.21.16 * @var string */ const UPGRADE_REF_PARAM = 'ref'; /** * Name of the query argument that carries a partner code on the Upgrade * link. Anything outside [A-Za-z0-9_-] falls back to the default. * * @since 1.21.16 * * @return string Parameter name. */ public static function upgrade_ref_param(): string { /** * Filters the query-argument name the Upgrade link uses for a partner code. * * @since 1.21.16 * * @param string $param Parameter name. Default 'ref'. */ $param = apply_filters( 'cachingout_upgrade_ref_param', self::UPGRADE_REF_PARAM ); if ( ! is_string( $param ) || 1 !== preg_match( '/^[A-Za-z0-9_-]{1,64}$/', $param ) ) { return self::UPGRADE_REF_PARAM; } return $param; } /** * A partner code as typed or pasted, accepted only when it is 1-64 * characters of [A-Za-z0-9_-] once surrounding whitespace is trimmed. * Anything else answers '' (nothing is sent) rather than an altered code * that could credit someone else. * * @since 1.21.16 * * @param string $code Raw code. * @return string The code, or '' when it is not acceptable. */ public static function sanitize_partner_code( string $code ): string { $code = trim( $code ); return 1 === preg_match( '/^[A-Za-z0-9_-]{1,64}$/', $code ) ? $code : ''; } /** * The Upgrade link: the direct pricing URL, with a partner code added as * a query argument only when one is given and acceptable. No redirect * or intermediary. The Pro screen renders the bare URL and its script * adds the code at click time with the same rules * (admin/assets/js/partner-code.js). * * @since 1.21.16 * * @param string $partner_code Optional partner code, as typed. * @return string Absolute URL. */ public static function upgrade_url( string $partner_code = '' ): string { $url = trailingslashit( self::pricing_url() ); $code = self::sanitize_partner_code( $partner_code ); if ( '' === $code ) { return $url; } return add_query_arg( self::upgrade_ref_param(), $code, $url ); } }