summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/functions.global.php')
-rw-r--r--plugins/jetpack/functions.global.php112
1 files changed, 111 insertions, 1 deletions
diff --git a/plugins/jetpack/functions.global.php b/plugins/jetpack/functions.global.php
index 44152b19..9d983fd9 100644
--- a/plugins/jetpack/functions.global.php
+++ b/plugins/jetpack/functions.global.php
@@ -10,6 +10,8 @@
* @package Jetpack
*/
+use Automattic\Jetpack\Connection\Client;
+
/**
* Disable direct access.
*/
@@ -17,6 +19,38 @@ if ( ! defined( 'ABSPATH' ) ) {
exit;
}
+if ( ! function_exists( 'wp_timezone' ) ) {
+ /**
+ * Shim for WordPress 5.3's wp_timezone() function.
+ *
+ * This is a mix of wp_timezone(), which calls wp_timezone_string().
+ * We don't need both in Jetpack, so providing only one function.
+ *
+ * @since 7.9.0
+ * @todo Remove when WP 5.3 is Jetpack's minimum
+ *
+ * @return DateTimeZone Site's DateTimeZone
+ */
+ function wp_timezone() {
+ $timezone_string = get_option( 'timezone_string' );
+
+ if ( $timezone_string ) {
+ return new DateTimeZone( $timezone_string );
+ }
+
+ $offset = (float) get_option( 'gmt_offset' );
+ $hours = (int) $offset;
+ $minutes = ( $offset - $hours );
+
+ $sign = ( $offset < 0 ) ? '-' : '+';
+ $abs_hour = abs( $hours );
+ $abs_mins = abs( $minutes * 60 );
+ $tz_offset = sprintf( '%s%02d:%02d', $sign, $abs_hour, $abs_mins );
+
+ return new DateTimeZone( $tz_offset );
+ }
+}
+
/**
* Set the admin language, based on user language.
*
@@ -153,7 +187,7 @@ function jetpack_theme_update( $preempt, $r, $url ) {
// Remove filter to avoid endless loop since wpcom_json_api_request_as_blog uses this too.
remove_filter( 'pre_http_request', 'jetpack_theme_update' );
- $result = Jetpack_Client::wpcom_json_api_request_as_blog(
+ $result = Client::wpcom_json_api_request_as_blog(
"themes/download/$theme.zip",
'1.1',
array(
@@ -226,3 +260,79 @@ function jetpack_json_wrap( &$any, $seen_nodes = array() ) {
return $any;
}
+
+/**
+ * Checks if the mime_content_type function is available and return it if so.
+ *
+ * The function mime_content_type is enabled by default in PHP, but can be disabled. We attempt to
+ * enforce this via composer.json, but that won't be checked in majority of cases where
+ * this would be happening.
+ *
+ * @since 7.8.0
+ *
+ * @param string $file File location.
+ *
+ * @return string|false MIME type or false if functionality is not available.
+ */
+function jetpack_mime_content_type( $file ) {
+ if ( function_exists( 'mime_content_type' ) ) {
+ return mime_content_type( $file );
+ }
+
+ return false;
+}
+
+/**
+ * Checks that the mime type of the specified file is among those in a filterable list of mime types.
+ *
+ * @since 7.8.0
+ *
+ * @param string $file Path to file to get its mime type.
+ *
+ * @return bool
+ */
+function jetpack_is_file_supported_for_sideloading( $file ) {
+ $type = jetpack_mime_content_type( $file );
+
+ if ( ! $type ) {
+ return false;
+ }
+
+ /**
+ * Filter the list of supported mime types for media sideloading.
+ *
+ * @since 4.0.0
+ *
+ * @module json-api
+ *
+ * @param array $supported_mime_types Array of the supported mime types for media sideloading.
+ */
+ $supported_mime_types = apply_filters(
+ 'jetpack_supported_media_sideload_types',
+ array(
+ 'image/png',
+ 'image/jpeg',
+ 'image/gif',
+ 'image/bmp',
+ 'video/quicktime',
+ 'video/mp4',
+ 'video/mpeg',
+ 'video/ogg',
+ 'video/3gpp',
+ 'video/3gpp2',
+ 'video/h261',
+ 'video/h262',
+ 'video/h264',
+ 'video/x-msvideo',
+ 'video/x-ms-wmv',
+ 'video/x-ms-asf',
+ )
+ );
+
+ // If the type returned was not an array as expected, then we know we don't have a match.
+ if ( ! is_array( $supported_mime_types ) ) {
+ return false;
+ }
+
+ return in_array( $type, $supported_mime_types, true );
+}