PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / addons / includes / functions.php
robin-image-optimizer / libs / addons / includes Last commit date
classes 3 months ago functions.php 5 months ago index.php 5 months ago
functions.php
115 lines
1 <?php
2 /**
3 * Supporting functions for premium plugin
4 *
5 * @version 1.0
6 */
7
8 /**
9 * Get the path to NextGen galleries on monosites.
10 *
11 * @since 1.0.4
12 * @return string|bool An absolute path. False if it can't be retrieved.
13 */
14 function wrio_get_ngg_galleries_path() {
15 $galleries_path = get_site_option( 'ngg_options' );
16
17 if ( empty( $galleries_path['gallerypath'] ) ) {
18 return false;
19 }
20
21 $galleries_path = wp_normalize_path( $galleries_path['gallerypath'] );
22 $galleries_path = trim( $galleries_path, '/' ); // Something like `wp-content/gallery`.
23
24 $ngg_root = defined( 'NGG_GALLERY_ROOT_TYPE' ) ? NGG_GALLERY_ROOT_TYPE : 'site';
25
26 if ( $galleries_path && 'content' === $ngg_root ) {
27 $ngg_root = wp_normalize_path( WP_CONTENT_DIR );
28 $ngg_root = trim( $ngg_root, '/' ); // Something like `abs-path/to/wp-content`.
29
30 $exploded_root = explode( '/', $ngg_root );
31 $exploded_galleries = explode( '/', $galleries_path );
32 $first_gallery_dirname = reset( $exploded_galleries );
33 $last_root_dirname = end( $exploded_root );
34
35 if ( $last_root_dirname === $first_gallery_dirname ) {
36 array_shift( $exploded_galleries );
37 $galleries_path = implode( '/', $exploded_galleries );
38 }
39 }
40
41 if ( 'content' === $ngg_root ) {
42 $ngg_root = wp_normalize_path( WP_CONTENT_DIR );
43 } else {
44 $ngg_root = wp_normalize_path( ABSPATH );
45 }
46
47 if ( strpos( $galleries_path, $ngg_root ) !== 0 ) {
48 $galleries_path = $ngg_root . $galleries_path;
49 }
50
51 return $galleries_path;
52 }
53
54 /**
55 * Get the path to WooCommerce logs on monosites.
56 *
57 * @since 1.0.4
58 * @access public
59 * @return string An absolute path.
60 */
61 function wrio_get_wc_logs_path() {
62 if ( defined( 'WC_LOG_DIR' ) ) {
63 return WC_LOG_DIR;
64 }
65
66 $wp_upload_dir = wp_upload_dir();
67
68 if ( isset( $wp_upload_dir['error'] ) && $wp_upload_dir['error'] !== false ) {
69 return null;
70 }
71
72 $wp_upload_dir_path = wp_normalize_path( trailingslashit( $wp_upload_dir['basedir'] ) );
73
74 return $wp_upload_dir_path . 'wc-logs';
75 }
76
77 /**
78 * Get the path to EWWW optimization tools.
79 * It is the same for all sites on multisite.
80 *
81 * @since 1.0.4
82 * @return string An absolute path.
83 */
84 function wrio_get_ewww_tools_path() {
85 if ( defined( 'EWWW_IMAGE_OPTIMIZER_TOOL_PATH' ) ) {
86 return wp_normalize_path( EWWW_IMAGE_OPTIMIZER_TOOL_PATH );
87 }
88
89 return trailingslashit( wp_normalize_path( WP_CONTENT_DIR ) ) . 'ewww';
90 }
91
92 /**
93 * Get the path to ShortPixel backup folder.
94 * It is the same for all sites on multisite (and yes, you'll get a surprise if your upload base dir -aka uploads/sites/12/- is not 2 folders deeper than theuploads folder).
95 *
96 * @since 1.0.4
97 * @access public
98 * @return string An absolute path.
99 */
100 function wrio_get_shortpixel_path() {
101 if ( defined( 'SHORTPIXEL_BACKUP_FOLDER' ) ) {
102 return trailingslashit( SHORTPIXEL_BACKUP_FOLDER );
103 }
104
105 $wp_upload_dir = wp_upload_dir();
106
107 if ( isset( $wp_upload_dir['error'] ) && $wp_upload_dir['error'] !== false ) {
108 return null;
109 }
110
111 $wp_upload_dir_path = wp_normalize_path( trailingslashit( $wp_upload_dir['basedir'] ) );
112
113 return $wp_upload_dir_path . 'ShortpixelBackups';
114 }
115