Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
alan2

Populating UPLOAD_URL_PATH with content-serving subdomain breaks File Size field

Thanks for a highly valueable Admin Columns Pro plugin. I bought it when trying to optimize image sizes for an image-laden site. Part of that optimization is serving images from a subdomain that points to the site’s standard wp-content/uploads directory. Populating UPLOAD_URL_PATH with the subdomain string causes the File Size field values not to display. Here is the detail:

Site URL: https://www.domain.com
Standard upload location: https://www.domain.com/wp-content/uploads
Subdomain that serves images: https://media.domain.com
Subdomain points to the http://www.domain.com, so doesn’t skip any directories by pointing directly to the uploads directory
UPLOAD_URL_OPTIONS in wp-options must be populated with https://media.domain.com/wp-content/uploads for new images to be tagged with the subdomain so they’ll be served from there.

Even with the Admin Columns File Size values not displayed, I can still sort on the File Size column, and WP still displays an image’s File size when Edit is selected. The only issue I can find is that Admin Columns File Size field is empty.

Can you either tell me what I need to change in the plugin (couldn’t find any exposed settings to address this), or patch it so that the File Size field accommodates changes to UPLOAD_URL_PATH.

Many thanks.

Alan

6 years, 9 months ago
alan2

Stefan – I misstated something in the third sentence and stated it correctly farther down: The media.domain.com subdomain does NOT point to the wp-content/uploads directory. It points to https://www.domain.com, so the full path to the uploads directory looks like the standard WP UNC: https://media.domain.com/wp-content/uploads.

Sorry for sounding like an idiot!

6 years, 9 months ago
Stefan van den Dungen Gronovius
Developer

Hi Alan,

No problem, I understand you issue. I’m not sure how you can change the upload path in WordPress with the constants you mentioned. I know the UPLOAD constant but not the UPLOAD_URL_PATH. So the best way here to get the correct file size in your case, is to use the our ac/column/value filter to change the value for the file size column. I prepared this filter for you, and all you have to do is to change the $abs path so it point to the correct file on your file system. Can you please send me the working version in your environment to support@admincolumns.com so I can see what you did and consider to change it in our code? If it is something that will work for every environment than we can change it in our code.

/**
 * @param $value  string
 * @param $id     int
 * @param $column AC_Column
 */
function acp_column_value_file_size( $value, $id, $column ) {

	if ( 'column-file_size' === $column->get_type() ) {
		$file = wp_get_attachment_url( $id );

		// Change $abs to get the correct absolute path of the file
		$abs = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $file );

		if ( file_exists( $abs ) ) {
			$value = ac_helper()->file->get_readable_filesize( filesize( $abs ) );
		}
	}

	return $value;
}

add_filter( 'ac/column/value', 'acp_column_value_file_size', 10, 3 );
6 years, 9 months ago
alan2

Thanks for your instant response. The UPLOAD_URL_PATH setting is in the ‘hidden’ UI at /wp-admin/options.php.

This is what I did:
1. Added your code (except the rem’d out statements) to my child theme’s functions.php
a: tried $abs = str_replace( upload_url_path, upload_url, $file );
b. tried $abs = str_replace( wp_content_url, wp_content_dir, $file );
where upload_url_path = https://media.domain.com/wp-content/uploads and upload_path = wp-content/uploads
2. Installed your Admin Columns Pro – Advanced Custom Fields (ACF)
3. Installed Advanced Custom Fields plugin that ACP-ACF plugin said was required

I was never able to get AC to show me a filter to select for the new column, but there is the distinct possibility that I didn’t try to select it the right way. ACF shows No ACF fields available when I try to make the new field Type = ACF.

What should I do differently to get your new filter to be available? I read all of the online documentation that I could see that might apply, but wasn’t able to pick out the steps I’m missing.

6 years, 9 months ago
Stefan van den Dungen Gronovius
Developer

Hi Alan,

Thanks for the information.

Please notice that $abs need to be the exact location on your server for the file. This does not include the domain of your website, but it points to the location on the file system. For example, the path should look something like this:
/public/wp-content/uploads/sites/{site-number}/{date_params}/{$file}

The first part might be specific for your environment. Try to return the $abs path for the column to see what is happening here. Please notice that we need a file on the server to get the file size. The file size column will not work for CDN solutions.

I’m not sure btw, what the ACF solution you mentioned has to do with this issue. But if you don’t see any ACF fields in the column, you’ll have to create some ACF fields first. But again, I do not see how this is related to the file size issue.

6 years, 9 months ago
alan2

Are any additional plugins required, or does your solution work directly in Admin Columns Pro with no additional plugins?
Not a developer – so how do I query for the value of $abs?
You say that you need a file on the server to get file size; which file contains that information in a standard wordpress installation?

6 years, 9 months ago
Stefan van den Dungen Gronovius
Developer

Hi Alan,

You don’t need any other plugins to make this work.
The only problem here, is that I don’t know much about your environment.
If you login to your website with FTP, you can see the structure of your WordPress install.
Since you’re using a multisite environment, structure for your uploads will look something like this:

/wp-content/uploads/sites/{site-number}/{date_params}/{$file}
/wp-content/uploads/sites/1/2018/01/myfile.txt

I’m still not sure how the UPLOAD_URL_PATH changes will affect this in your environment. Do you have a developer for your website who can help you out with this? Otherwise. we could continue this issue by email since I may need some more sensitive information about your environment. I would like to know what the default $abspath is and what the value is of UPLOAD_URL_PATH.

6 years, 9 months ago

You must be logged in to reply to this topic.