O3PO_Environment
in package
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.
Tags
Table of Contents
Properties
- $production_site_url : string
- The url of the production system.
Methods
- __construct() : mixed
- Instantiate the envrionment object.
- custom_upload_mimes() : mixed
- Adds additional mime types to the given array.
- disable_real_mime_check_for_selected_extensions() : array<string|int, mixed>
- 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.
- download_to_media_library() : mixed
- Download a file to the WordPress media library.
- file_get_contents_utf8() : mixed
- 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.
- get_feature_image_path() : mixed
- Get the path of a feature image of a post
- is_test_environment() : mixed
- Returns whether this plugin is running on a test system or the production system.
- max_file_upload_bytes() : mixed
- Maximum file size allowed in uploads
- modify_css_if_in_test_environment() : mixed
- Modify the css if we are in a test environment to make the website look ugly to avoid confusion.
- save_recursive_remove_dir() : mixed
- Recursively remove a directory.
- unique_filename_callback() : mixed
- Returns a filename that is unique in the given directory.
Properties
$production_site_url
The url of the production system.
protected
string
$production_site_url
Site URL of the production site.
Tags
Methods
__construct()
Instantiate the envrionment object.
public
__construct(string $production_site_url) : mixed
Parameters
- $production_site_url : string
-
Site URL of the production site.
Tags
custom_upload_mimes()
Adds additional mime types to the given array.
public
custom_upload_mimes([array<string|int, mixed> $mime_types = array() ]) : mixed
Enables the upload of such file types to the media library.
Parameters
- $mime_types : array<string|int, mixed> = array()
-
Array of mime types.
Tags
disable_real_mime_check_for_selected_extensions()
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.
public
disable_real_mime_check_for_selected_extensions(array<string|int, mixed> $data, string $file, string $filename, array<string|int, mixed> $mimes) : array<string|int, mixed>
To be added to the 'wp_check_filetype_and_ext' filter.
Parameters
- $data : array<string|int, mixed>
-
File data array containing 'ext', 'type', and 'proper_filename' keys.
- $file : string
-
Full path to the file.
- $filename : string
-
The name of the file (may differ from $file due to $file being in a tmp directory).
- $mimes : array<string|int, mixed>
-
Key is the file extension with value as the mime type.
Tags
Return values
array<string|int, mixed> —Values for the extension, MIME, and filename.
download_to_media_library()
Download a file to the WordPress media library.
public
download_to_media_library(string $url, string $filename, string $extension, string $mime_type, int $parent_post_id[, int $timeout_seconds = 40 ]) : mixed
$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
- $url : string
-
Url to download from.
- $filename : string
-
Fielname under which to save the download.
- $extension : string
-
Extension of the file under which to save the download.
- $mime_type : string
-
Expected mime type of the download.
- $parent_post_id : int
-
Id of post to which to link the download.
- $timeout_seconds : int = 40
-
Timeout of the download.
Tags
file_get_contents_utf8()
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.
public
file_get_contents_utf8(string $path) : mixed
Parameters
- $path : string
-
Path to the file to get.
Tags
get_feature_image_path()
Get the path of a feature image of a post
public
get_feature_image_path(int $post_id) : mixed
Returns the path of the feature image, insired by https://stackoverflow.com/questions/27306882/actual-file-location-of-a-wordpress-featured-image
Parameters
- $post_id : int
-
Id of the post.
Tags
is_test_environment()
Returns whether this plugin is running on a test system or the production system.
public
is_test_environment() : mixed
Tags
max_file_upload_bytes()
Maximum file size allowed in uploads
public
static max_file_upload_bytes() : mixed
Tags
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.
public
modify_css_if_in_test_environment() : mixed
To be added to the 'wp_head' and 'admin_head' action.
Tags
save_recursive_remove_dir()
Recursively remove a directory.
public
static save_recursive_remove_dir(string $path, string $root) : mixed
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
- $path : string
-
Path to file/folder to delete.
- $root : string
-
Root folder to which to restric the deleting.
Tags
unique_filename_callback()
Returns a filename that is unique in the given directory.
public
unique_filename_callback(string $dir, string $filename, string $ext) : mixed
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
- $dir : string
-
Directory.
- $filename : string
-
Base Filename including the extension.
- $ext : string
-
Desired extension, e.g., '.txt', '.pdf', or '.tar.gz'.