WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 2 years ago

#28238 new enhancement

Add filter to value returned from get_space_used()

Reported by: hereswhatidid Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.5
Component: Upload Keywords: has-patch needs-refresh
Focuses: multisite Cc:

Description

It would be helpful to have an additional filter to modify the returned value from the get_space_used() function in order to add additional space quantities without having to recreate the entire function by only having the 'pre_get_space_used' filter.

Attachments (1)

getspaceusedfilter.diff (895 bytes) - added by hereswhatidid 4 years ago.
Update get_space_used() to filter the returned $space_used value

Download all attachments as: .zip

Change History (7)

@hereswhatidid
4 years ago

Update get_space_used() to filter the returned $space_used value

#1 @SergeyBiryukov
3 years ago

  • Component changed from General to Upload

#2 @DrewAPicture
3 years ago

  • Keywords has-patch added

The hook docs in getspaceusedfilter.diff look ok, except that the @since should be 4.0.0 now.

Seems a bit overkill to have two filters in such a small function. Perhaps we could accomplish both goals and keep only a single filter -- might be worth looking at.

#3 @hereswhatidid
3 years ago

I'd be happy with just having the second filter on the output. It doesn't look like moving it from the current location to only filtering the output would have any effect on existing usages either. The only oddness then would be that the filter name "pre_get_space_used" doesn't really apply as it's no longer filtering the space used prior to calculating it.

Last edited 3 years ago by hereswhatidid (previous) (diff)

#4 @nacin
3 years ago

  • Version changed from trunk to 3.5

The existing pre_* filter makes sense here, I think. Could you describe your use case further? "in order to add additional space quantities" — are you sure you don't want to use the filter get_space_allowed, for example?

#5 @hereswhatidid
3 years ago

This was specifically for a couple plugins that were uploading media outside of the expected locations. So in order to calculate the current space used I would have to take the value from get_space_used and add the space used by the other files to this. The problem with the current pre_get_space_used is that in order to simply add additional space calculations to the value it's necessary to completely recreate how core is currently calculating the space used. If we had a filter that ran after the core space calculations are run it would be easier and more stable to just add the additional values to that. This would also be safer from a compatibility perspective in the off chance that the core method for calculating space used:

	if ( false === $space_used ) {
		$upload_dir = wp_upload_dir();
		$space_used = get_dirsize( $upload_dir['basedir'] ) / 1024 / 1024;
	}

were to change at some point.

#6 @chriscct7
2 years ago

  • Keywords needs-refresh added
Note: See TracTickets for help on using tickets.