PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 18.3
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v18.3
28.5 28.4 28.3 28.2 28.1 28.0 27.9 27.8 27.7 27.6 27.5 trunk 18.0 18.1 18.2 18.3 18.4 18.4.1 18.5 18.5.1 18.6 18.7 18.8 18.9 19.0 All 129 releases
wordpress-seo / admin / class-admin-asset-dev-server-location.php

class-admin-asset-dev-server-location.php in Yoast SEO – Advanced SEO with real-time guidance and built-in AI 18.3, at admin/class-admin-asset-dev-server-location.php

80 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * WPSEO plugin file.
4 *
5 * @package WPSEO\Admin
6 */
7
8 /**
9 * Changes the asset paths to dev server paths.
10 */
11 final class WPSEO_Admin_Asset_Dev_Server_Location implements WPSEO_Admin_Asset_Location {
12
13 /**
14 * Holds the dev server's default URL.
15 *
16 * @var string
17 */
18 const DEFAULT_URL = 'http://localhost:8080';
19
20 /**
21 * Holds the url where the server is located.
22 *
23 * @var string
24 */
25 private $url;
26
27 /**
28 * Class constructor.
29 *
30 * @param string|null $url Where the dev server is located.
31 */
32 public function __construct( $url = null ) {
33 if ( $url === null ) {
34 $url = self::DEFAULT_URL;
35 }
36
37 $this->url = $url;
38 }
39
40 /**
41 * Determines the URL of the asset on the dev server.
42 *
43 * @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
44 * @param string $type The type of asset. Usually JS or CSS.
45 *
46 * @return string The URL of the asset.
47 */
48 public function get_url( WPSEO_Admin_Asset $asset, $type ) {
49 if ( $type === WPSEO_Admin_Asset::TYPE_CSS ) {
50 return $this->get_default_url( $asset, $type );
51 }
52
53 $asset_manager = new WPSEO_Admin_Asset_Manager();
54 $flat_version = $asset_manager->flatten_version( WPSEO_VERSION );
55 $version_less_source = str_replace( '-' . $flat_version, '', $asset->get_src() );
56
57 if ( strpos( $version_less_source, 'select2' ) !== false ) {
58 return $this->get_default_url( $asset, $type );
59 }
60
61 $path = sprintf( 'js/dist/%s%s.js', $asset->get_src(), $asset->get_suffix() );
62
63 return trailingslashit( $this->url ) . $path;
64 }
65
66 /**
67 * Determines the URL of the asset not using the dev server.
68 *
69 * @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
70 * @param string $type The type of asset.
71 *
72 * @return string The URL of the asset file.
73 */
74 public function get_default_url( WPSEO_Admin_Asset $asset, $type ) {
75 $default_location = new WPSEO_Admin_Asset_SEO_Location( WPSEO_FILE );
76
77 return $default_location->get_url( $asset, $type );
78 }
79 }
80