\O3PO_Environment

Provide information about and functions to interact with the environment in which this plugin is running.

Provide methods to obtain information about and functions to interact with the environment in which this plugin is running.

Summary

Methods
Properties
Constants
__construct()
is_test_environment()
modify_css_if_in_test_environment()
unique_filename_callback()
custom_upload_mimes()
disable_real_mime_check_for_selected_extensions()
download_to_media_library()
save_recursive_remove_dir()
file_get_contents_utf8()
get_feature_image_path()
max_file_upload_bytes()
No public properties found
No constants found
No protected methods found
$production_site_url
N/A
No private methods found
No private properties found
N/A

Properties

$production_site_url

$production_site_url : string

The url of the production system.

Type

string — Site URL of the production site.

Methods

__construct()

__construct(string  $production_site_url) 

Instantiate the envrionment object.

Parameters

string $production_site_url

Site URL of the production site.

is_test_environment()

is_test_environment() 

Returns whether this plugin is running on a test system or the production system.

modify_css_if_in_test_environment()

modify_css_if_in_test_environment() 

Modify the css if we are in a test environment to make the website look ugly to avoid confusion.

To be added to the 'wp_head' and 'admin_head' action.

unique_filename_callback()

unique_filename_callback(string  $dir, string  $filename, string  $ext) 

Returns a filename that is unique in the given directory.

This fuction is based on wp_unique_filename() from https://core.trac.wordpress.org/browser/tags/4.7.3/src/wp-includes/functions.php#L0 but it treats .tar.gz as a single extension.

Parameters

string $dir

Directory.

string $filename

Base Filename including the extension.

string $ext

Desired extension, e.g., '.txt', '.pdf', or '.tar.gz'.

custom_upload_mimes()

custom_upload_mimes(array  $mime_types = array()) 

Adds additional mime types to the given array.

Enables the upload of such file types to the media library.

Parameters

array $mime_types

Array of mime types.

disable_real_mime_check_for_selected_extensions()

disable_real_mime_check_for_selected_extensions(array  $data, string  $file, string  $filename, array  $mimes) : array

Works around a bug in WP that disallows upload of files to the media library even if they are marked as allowed via the 'upload_mimes' filter.

To be added to the 'wp_check_filetype_and_ext' filter.

Parameters

array $data

File data array containing 'ext', 'type', and 'proper_filename' keys.

string $file

Full path to the file.

string $filename

The name of the file (may differ from $file due to $file being in a tmp directory).

array $mimes

Key is the file extension with value as the mime type.

Returns

array —

Values for the extension, MIME, and filename.

download_to_media_library()

download_to_media_library(string  $url, string  $filename, string  $extension, string  $mime_type, integer  $parent_post_id, integer  $timeout_seconds = 40) 

Download a file to the WordPress media library.

$mime_type and $extension are optional, if set to something empty() they are guessed form the download file, where the extension is guessed based on the mime type. If the mime type is provided and the downloaded file does not actually have that mime type, an error is returned.

Parameters

string $url

Url to download from.

string $filename

Fielname under which to save the download.

string $extension

Extension of the file under which to save the download.

string $mime_type

Expected mime type of the download.

integer $parent_post_id

Id of post to which to link the download.

integer $timeout_seconds

Timeout of the download.

save_recursive_remove_dir()

save_recursive_remove_dir(string  $path, string  $root) 

Recursively remove a directory.

PHP itself does not offer a reasonable way to recursively remove directories. This is a subtle issue as links and nasty file names can be inlolved. We don't want to be hackble by uploading a malicious manuscript source to the arXiv, don't we? This is the best I could come up with after looking at many different implementations that can be found on the internet.

Parameters

string $path

Path to file/folder to delete.

string $root

Root folder to which to restric the deleting.

file_get_contents_utf8()

file_get_contents_utf8(string  $path) 

PHP seems to have problems correctly detecting utf-8 encoding of some .tex files when they are read with the standard file_get_contents() functinon (is this expected?). The following has turned out to work in all cases I have tested.

Parameters

string $path

Path to the file to get.

max_file_upload_bytes()

max_file_upload_bytes() 

Maximum file size allowed in uploads