unzip_file

Definition:
function unzip_file($file, $to) {}

Unzips a specified ZIP file to a location on the Filesystem via the WordPress Filesystem Abstraction.
Assumes that WP_Filesystem() has already been called and set up. Does not extract a root-level __MACOSX directory, if present.

Parameters

  • string $file: Full path and filename of zip archive
  • string $to: Full path on the filesystem to extract archive to

Return values

returns:WP_Error on failure, True on success

Defined filters

  • admin_memory_limit
    apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT )
  • unzip_file_use_ziparchive
    apply_filters('unzip_file_use_ziparchive', true )

Source code

function unzip_file($file, $to) {

	global $wp_filesystem;



	if ( ! $wp_filesystem || !is_object($wp_filesystem) )

		return new WP_Error('fs_unavailable', __('Could not access filesystem.'));



	// Unzip can use a lot of memory, but not this much hopefully

	@ini_set( 'memory_limit', apply_filters( 'admin_memory_limit', WP_MAX_MEMORY_LIMIT ) );



	$needed_dirs = array();

	$to = trailingslashit($to);



	// Determine any parent dir's needed (of the upgrade directory)

	if ( ! $wp_filesystem->is_dir($to) ) { //Only do parents if no children exist

		$path = preg_split('![/\\\]!', untrailingslashit($to));

		for ( $i = count($path); $i >= 0; $i-- ) {

			if ( empty($path[$i]) )

				continue;



			$dir = implode('/', array_slice($path, 0, $i+1) );

			if ( preg_match('!^[a-z]:$!i', $dir) ) // Skip it if it looks like a Windows Drive letter.

				continue;



			if ( ! $wp_filesystem->is_dir($dir) )

				$needed_dirs[] = $dir;

			else

				break; // A folder exists, therefor, we dont need the check the levels below this

		}

	}



	if ( class_exists('ZipArchive') && apply_filters('unzip_file_use_ziparchive', true ) ) {

		$result = _unzip_file_ziparchive($file, $to, $needed_dirs);

		if ( true === $result ) {

			return $result;

		} elseif ( is_wp_error($result) ) {

			if ( 'incompatible_archive' != $result->get_error_code() )

				return $result;

		}

	}

	// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.

	return _unzip_file_pclzip($file, $to, $needed_dirs);

}

3149

untrailingslashit

Definition:
function untrailingslashit($string) {}

Removes trailing slash if it exists.
The primary use of this is for paths and thus should be used for paths. It is not restricted to paths and offers no specific path support.

Parameters

  • string $string: What to remove the trailing slash from.

Return values

returns:String without the trailing slash.

Source code

function untrailingslashit($string) {

	return rtrim($string, '/');

}

3147

unstick_post

Definition:
function unstick_post($post_id) {}

Unstick a post.
Sticky posts should be displayed at the top of the front page.

Parameters

  • int $post_id: Post ID.

Source code

function unstick_post($post_id) {

	$stickies = get_option('sticky_posts');



	if ( !is_array($stickies) )

		return;



	if ( ! in_array($post_id, $stickies) )

		return;



	$offset = array_search($post_id, $stickies);

	if ( false === $offset )

		return;



	array_splice($stickies, $offset, 1);



	update_option('sticky_posts', $stickies);

}

3145

unregister_widget_control

Definition:
function unregister_widget_control($id) {}

Alias of wp_unregister_widget_control().

Parameters

  • int|string $id: Widget ID.

Source code

function unregister_widget_control($id) {

	_deprecated_function( __FUNCTION__, '2.8', 'wp_unregister_widget_control()' );

	return wp_unregister_widget_control($id);

}

3143

unregister_widget

Definition:
function unregister_widget($widget_class) {}

Unregister a widget
Unregisters a WP_Widget widget. Useful for unregistering default widgets. Run within a function hooked to the widgets_init action.

Parameters

  • string $widget_class: The name of a class that extends WP_Widget

Source code

function unregister_widget($widget_class) {

	global $wp_widget_factory;



	$wp_widget_factory->unregister($widget_class);

}

3141