PluginProbe
WP-Stateless – Google Cloud Storage / 3.0.3
WP-Stateless – Google Cloud Storage v3.0.3
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / vendor / udx / lib-wp-bootstrap / lib / classes / class-utility.php

class-utility.php in WP-Stateless – Google Cloud Storage 3.0.3, at vendor/udx/lib-wp-bootstrap/lib/classes/class-utility.php

108 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Helper.
4 *
5 */
6 namespace UsabilityDynamics\WP {
7
8 if( !defined( 'ABSPATH' ) ) {
9 die();
10 }
11
12 if (!class_exists('UsabilityDynamics\WP\Utility')) {
13
14 class Utility {
15
16 /**
17 * Return root path to library.
18 */
19 static public function path( $shortpath, $type = 'dir' ) {
20 /** Determine where th library installed ( it's a theme or plugin ) */
21 if( defined( 'WPMU_PLUGIN_DIR' ) && strpos( wp_normalize_path( dirname(__FILE__) ), wp_normalize_path( WPMU_PLUGIN_DIR ) ) !== false
22 ) {
23 $instance = 'mu-plugin';
24 } elseif ( defined( 'WP_PLUGIN_DIR' ) && strpos( wp_normalize_path( dirname(__FILE__) ), wp_normalize_path( WP_PLUGIN_DIR ) ) !== false
25 ){
26 $instance = 'plugin';
27 } elseif ( strpos( wp_normalize_path( get_template_directory() ), wp_normalize_path( dirname(__FILE__) ) ) !== false ){
28 $instance = 'template';
29 } else {
30 $instance = 'stylesheet';
31 }
32
33 $path = false;
34 switch( $type ) {
35 case 'dir':
36 $path = self::_path_dir( $instance );
37 break;
38 case 'url':
39 $path = self::_path_url( $instance );
40 break;
41 }
42 if( $path ) {
43 $path = preg_replace( '|^(.*)(\/lib)(\/classes)(\/)?$|', '$1', $path );
44 $path = trailingslashit( $path );
45 $path .= ltrim( $shortpath, '/\\' );
46 }
47 return $path;
48 }
49
50 /**
51 * Returns correct absolute URL path to lib-ui directory
52 *
53 * @param $instance
54 * @return string
55 */
56 static private function _path_url( $instance ) {
57 $path = false;
58 switch( $instance ) {
59 case 'mu-plugin':
60 case 'plugin':
61 $path = plugin_dir_url( __FILE__ );
62 break;
63 case 'template':
64 $s = str_replace( wp_normalize_path( ABSPATH ), '', wp_normalize_path(get_template_directory()) );
65 $s = str_replace( '/', '\/', $s );
66 $reg = '|^(.)*(' . $s . ')(.*)$|';
67 $p = preg_replace( $reg, '$3', wp_normalize_path( dirname( __FILE__ ) ) );
68 $path = get_template_directory_uri() . $p;
69 break;
70 case 'stylesheet':
71 $s = str_replace( wp_normalize_path( ABSPATH ), '', wp_normalize_path(get_stylesheet_directory()) );
72 $s = str_replace( '/', '\/', $s );
73 $reg = '|^(.)*(' . $s . ')(.*)$|';
74 $p = preg_replace( $reg, '$3', wp_normalize_path( dirname( __FILE__ ) ) );
75 $path = get_stylesheet_directory_uri() . $p;
76 break;
77 }
78 return $path;
79 }
80
81 /**
82 * Returns correct absolute DIR path to lib-ui directory
83 *
84 * @param $instance
85 * @return string
86 */
87 static private function _path_dir( $instance ) {
88 $path = false;
89 switch( $instance ) {
90 case 'mu-plugin':
91 case 'plugin':
92 $path = plugin_dir_path( __FILE__ );
93 break;
94 case 'template':
95 case 'stylesheet':
96 $path = dirname( __FILE__ );
97 break;
98 }
99 if( $path )
100 $path = wp_normalize_path( $path );
101 return $path;
102 }
103
104 }
105
106 }
107
108 }