WPDKFilesystem::filename PHP Méthode

filename() public static méthode

Return the only filename part. if a filename is 'test.black.jpg' will return 'test.black'
See also: ext()
Since: 1.4.15
public static filename ( string $filename ) : string
$filename string A comoplete filename
Résultat string
    public static function filename($filename)
    {
        $filename = strtolower(basename($filename));
        $parts = explode('.', $filename);
        // No dot found
        if (empty($parts)) {
            return $filename;
        } elseif (count($parts) > 2) {
            unset($parts[count($parts) - 1]);
            return implode(',', $parts);
        } else {
            return current($parts);
        }
    }

Usage Example

Exemple #1
0
 /**
  * Register one or more script following the view controller standard
  *
  * @brief Register
  *
  * @param array $scripts   List of scripts
  *
  *     $scripts = array(
  *         'wpxbz-preferences.js' => array(
  *            'handle'  => 'my-handle',                  // Optional -sanitize_titile( $key ) + remove '.js'
  *            'path'    => WPXBANNERIZE_URL_JAVASCRIPT,  // Optional if set $path params
  *            'deps'    => array( 'jquery' ),            // Optional if set $deps params
  *            'version' => '1.2.3',                      // Optional if set $version
  *            'footer'  => false,                        // Optional override the $in_footer params,
  *          )
  *     );
  *
  *     WPDKScripts::registerScripts( $scripts );
  *
  *     OR
  *
  *     $scripts = array(
  *         'wpxbz-preferences.js',
  *         'wpxbz-admin.js',
  *     );
  *
  *     WPDKScripts::registerScripts( $scripts, $path, $version );
  *
  *     OR
  *
  *     $scripts = array(
  *         'wpxbz-preferences.js' => array(
  *            'handle'  => 'my-handle',                  // Optional -sanitize_titile( $key ) + remove '.js'
  *            'path'    => WPXBANNERIZE_URL_JAVASCRIPT,  // Optional if set $path params
  *            'version' => '1.2.3',                      // Optional if set $version
  *            'footer'  => false,                        // Optional override the $in_footer params
  *          ),
  *         'wpxbz-admin.js',
  *     );
  *
  *     // $path and version will be used for 2th iten
  *     WPDKScripts::registerScripts( $scripts, $path, $version );
  *
  * @param string       $path      Optional. If set all scripts will be loaded fron this url
  * @param string|array $deps      Optional. One or more handle dependiences
  * @param bool|string  $version   Optional. If set will apply to all script
  * @param bool         $in_footer Optional. Default all scripts are loaded in footer
  *
  * @return bool
  */
 public function registerScripts($scripts, $path = '', $deps = array(), $version = false, $in_footer = true)
 {
     if (!empty($scripts) && is_array($scripts)) {
         foreach ($scripts as $filename => $info) {
             // Case 1
             if (is_array($info)) {
                 $handle = isset($info['handle']) ? $info['handle'] : sanitize_title(WPDKFilesystem::filename($filename));
                 $_path = isset($info['path']) ? $info['path'] : $path;
                 $_deps = isset($info['deps']) ? $info['deps'] : $deps;
                 // Sanitize $deps
                 if (is_string($_deps)) {
                     $_deps = explode(',', $_deps);
                 }
                 $_version = isset($info['version']) ? $info['version'] : $version;
                 $_in_footer = isset($info['footer']) ? $info['footer'] : $in_footer;
                 $src = sprintf('%s%s', trailingslashit($_path), $filename);
             } elseif (is_string($info)) {
                 $handle = sanitize_title(WPDKFilesystem::filename($info));
                 $_path = $path;
                 $_deps = $deps;
                 // Sanitize $deps
                 if (is_string($_deps)) {
                     $_deps = explode(',', $_deps);
                 }
                 $_version = $version;
                 $_in_footer = $in_footer;
                 $src = sprintf('%s%s', trailingslashit($_path), $info);
             } else {
                 return false;
             }
             // Stability
             if (!empty($handle) && !empty($src)) {
                 wp_register_script($handle, $src, $_deps, $_version, $_in_footer);
             }
         }
     }
     return true;
 }