su_set_file_extension

The shortcodes-ultimate su set file extension function.

Published Date - February 15, 2021

Description

Helper function to add/remove file extension to/from a given path.

su_set_file_extension( $path, $extension );

Parameters

  1. $path

  2. $extension


Usage

The following example is for adding a hook callback.

if ( !function_exists( 'su_set_file_extension' ) ) {
    require_once ABSPATH . PLUGINDIR . 'shortcodes-ultimateshortcodes-ultimate/includes/functions-helpers.php';
}

// The input(s). 
$path = null;
$extension = null;

// NOTICE! Understand what this does before running.
$result = su_set_file_extension( $path, $extension );
            

Defined

The function is defined in the following location(s).

shortcodes-ultimate/includes/functions-helpers.php

function su_set_file_extension( $path, $extension ) {

	$path_info = pathinfo( $path );

	if ( ! $extension ) {
		return path_join( $path_info['dirname'], $path_info['filename'] );
	}

	if ( empty( $path_info['extension'] ) || $path_info['extension'] !== $extension ) {
		$path .= ".{$extension}";
	}

	return $path;

}