PluginProbe
Yoast SEO – Advanced SEO with real-time guidance and built-in AI / 28.2
Yoast SEO – Advanced SEO with real-time guidance and built-in AI v28.2
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-seo-location.php

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

87 lines 2.1 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 * Determines the location of an asset within the SEO plugin.
10 */
11 final class WPSEO_Admin_Asset_SEO_Location implements WPSEO_Admin_Asset_Location {
12
13 /**
14 * Path to the plugin file.
15 *
16 * @var string
17 */
18 protected $plugin_file;
19
20 /**
21 * Whether or not to add the file suffix to the asset.
22 *
23 * @var bool
24 */
25 protected $add_suffix = true;
26
27 /**
28 * The plugin file to base the asset location upon.
29 *
30 * @param string $plugin_file The plugin file string.
31 * @param bool $add_suffix Optional. Whether or not a file suffix should be added.
32 */
33 public function __construct( $plugin_file, $add_suffix = true ) {
34 $this->plugin_file = $plugin_file;
35 $this->add_suffix = $add_suffix;
36 }
37
38 /**
39 * Determines the URL of the asset on the dev server.
40 *
41 * @param WPSEO_Admin_Asset $asset The asset to determine the URL for.
42 * @param string $type The type of asset. Usually JS or CSS.
43 *
44 * @return string The URL of the asset.
45 */
46 public function get_url( WPSEO_Admin_Asset $asset, $type ) {
47 $path = $this->get_path( $asset, $type );
48 if ( empty( $path ) ) {
49 return '';
50 }
51
52 return plugins_url( $path, $this->plugin_file );
53 }
54
55 /**
56 * Determines the path relative to the plugin folder of an asset.
57 *
58 * @param WPSEO_Admin_Asset $asset The asset to determine the path for.
59 * @param string $type The type of asset.
60 *
61 * @return string The path to the asset file.
62 */
63 protected function get_path( WPSEO_Admin_Asset $asset, $type ) {
64 $relative_path = '';
65 $rtl_suffix = '';
66
67 switch ( $type ) {
68 case WPSEO_Admin_Asset::TYPE_JS:
69 $relative_path = 'js/dist/' . $asset->get_src();
70 if ( $this->add_suffix ) {
71 $relative_path .= $asset->get_suffix() . '.js';
72 }
73 break;
74
75 case WPSEO_Admin_Asset::TYPE_CSS:
76 // Path and suffix for RTL stylesheets.
77 if ( is_rtl() && $asset->has_rtl() ) {
78 $rtl_suffix = '-rtl';
79 }
80 $relative_path = 'css/dist/' . $asset->get_src() . $rtl_suffix . $asset->get_suffix() . '.css';
81 break;
82 }
83
84 return $relative_path;
85 }
86 }
87