RWMB_Loader::get_path PHP Method

get_path() public static method

The method is static and can be used in extensions.
public static get_path ( string $path = '' ) : array
$path string Base folder path
return array Path and URL.
    public static function get_path($path = '')
    {
        // Plugin base path
        $path = wp_normalize_path(untrailingslashit($path));
        $themes_dir = wp_normalize_path(untrailingslashit(dirname(realpath(get_stylesheet_directory()))));
        // Default URL
        $url = plugins_url('', $path . '/' . basename($path) . '.php');
        // Included into themes
        if (0 !== strpos($path, wp_normalize_path(WP_PLUGIN_DIR)) && 0 !== strpos($path, wp_normalize_path(WPMU_PLUGIN_DIR)) && 0 === strpos($path, $themes_dir)) {
            $themes_url = untrailingslashit(dirname(get_stylesheet_directory_uri()));
            $url = str_replace($themes_dir, $themes_url, $path);
        }
        $path = trailingslashit($path);
        $url = trailingslashit($url);
        return array($path, $url);
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Enqueue scripts and styles.
  */
 public static function admin_enqueue_scripts()
 {
     // Group field is the 1st param
     $args = func_get_args();
     $fields = $args[0]['fields'];
     // Load clone script conditionally
     foreach ($fields as $field) {
         if ($field['clone']) {
             wp_enqueue_script('rwmb-clone', RWMB_JS_URL . 'clone.js', array('jquery-ui-sortable'), RWMB_VER, true);
             break;
         }
     }
     // Enqueue sub-fields scripts and styles.
     foreach ($fields as $field) {
         RWMB_Field::call($field, 'admin_enqueue_scripts');
     }
     // Use helper function to get correct URL to current folder, which can be used in themes/plugins.
     list(, $url) = RWMB_Loader::get_path(dirname(__FILE__));
     wp_enqueue_style('rwmb-group', $url . 'group.css', '', '1.1.2');
     wp_enqueue_script('rwmb-group', $url . 'group.js', array('jquery'), '1.1.2', true);
 }
All Usage Examples Of RWMB_Loader::get_path