Skip to content

Commit 211bff2

Browse files
committed
Prepare version 1.1.3
- added the "Profile Photo caching" setting - added the "Cover Photo caching" setting - added the "Cover Photo size in directory" setting - updated documentation
1 parent 45fa7e8 commit 211bff2

File tree

6 files changed

+198
-12
lines changed

6 files changed

+198
-12
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin >
2222

2323
### How to install from ZIP archive
2424

25-
You can install this plugin from the [ZIP file](https://drive.google.com/file/d/15YDvFMcfVFAixVLI4n3jbwFQZrgz6Rfu/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
25+
You can install this plugin from the [ZIP file](https://drive.google.com/file/d/11oT04a0zRPo0wshpBs6Mm22URLVTJmZs/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
2626

2727
## How to use
2828

@@ -40,7 +40,7 @@ Go to *wp-admin > Ultimate Member > Settings > General > Optimize* to manage set
4040
- **Speed up member directories** - *(optional)* Optimize the SQL query that retrieves users for the member directory.
4141

4242
Image - Optimize settings.
43-
![UM Settings, General, Optimize](https://github.com/umdevelopera/um-optimize/assets/113178913/22783720-c9af-4562-8ca7-7fff43123d99)
43+
![UM Settings, General, Optimize ()](https://github.com/user-attachments/assets/cd9873a0-332d-48ab-ba4d-8f28fcba803e)
4444

4545
## Support
4646

@@ -53,5 +53,3 @@ Ultimate Member home page: https://ultimatemember.com
5353
Ultimate Member documentation: https://docs.ultimatemember.com
5454

5555
Ultimate Member download: https://wordpress.org/plugins/ultimate-member
56-
57-
Article: [How to remove CSS and JS on non UM pages](https://docs.ultimatemember.com/article/1490-how-to-remove-css-and-js-on-non-um-pages)

includes/admin/class-admin.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,42 @@ public function extend_settings( $settings ) {
7171
'tooltip' => __( 'Combine JS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ),
7272
);
7373

74+
// Images.
75+
$fields[] = array(
76+
'id' => 'um_optimize_images_info',
77+
'type' => 'info_text',
78+
'label' => __( 'Images', 'um-optimize' ),
79+
'value' => __( 'Optimize images loading', 'um-optimize' ),
80+
);
81+
$fields[] = array(
82+
'id' => 'um_optimize_profile_photo',
83+
'type' => 'checkbox',
84+
'label' => __( 'Profile Photo caching', 'um-optimize' ),
85+
'description' => __( 'Ultimate Member does not allow caching Profile Photo in the browser. This is secure but slows your website. It is recommended to enable the Profile Photo caching if your website is public.', 'um-optimize' ),
86+
);
87+
$fields[] = array(
88+
'id' => 'um_optimize_cover_photo',
89+
'type' => 'checkbox',
90+
'label' => __( 'Cover Photo caching', 'um-optimize' ),
91+
'description' => __( 'Ultimate Member does not allow caching Cover Photo in the browser. This is secure but slows your website. It is recommended to enable the Cover Photo caching if your website is public.', 'um-optimize' ),
92+
);
93+
94+
$sizes = UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' );
95+
$sizes[''] = __( 'Default', 'um-optimize' );
96+
$fields[] = array(
97+
'id' => 'um_optimize_cover_photo_size',
98+
'type' => 'select',
99+
'size' => 'small',
100+
'label' => __( 'Cover Photo size in directory', 'um-optimize' ),
101+
'default' => UM()->options()->get( 'profile_coversize' ),
102+
'options' => $sizes,
103+
'description' => __( 'Ultimate Member uses the greatest cover photo thumbnail in the member directory on the desktop. So big images are unnecessary. It is enough to use the 500px width image. Here you can select the cover photo thumbnail for the member directory.', 'um-optimize' ),
104+
);
105+
106+
74107
// SQL queries.
75108
$fields[] = array(
76-
'id' => 'um_optimize_assets_info',
109+
'id' => 'um_optimize_queries_info',
77110
'type' => 'info_text',
78111
'label' => __( 'SQL queries', 'um-optimize' ),
79112
'value' => __( 'Optimize SQL queries to get posts and users faster', 'um-optimize' ),

includes/core/class-images.php

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
/**
3+
* Optimize images.
4+
*
5+
* @package um_ext\um_optimize\core
6+
*/
7+
8+
namespace um_ext\um_optimize\core;
9+
10+
if ( ! defined( 'ABSPATH' ) ) {
11+
exit;
12+
}
13+
14+
if ( ! class_exists( 'um_ext\um_optimize\core\Images' ) ) {
15+
16+
17+
/**
18+
* Class Images
19+
*
20+
* How to get an instance:
21+
* UM()->classes['um_optimize_images']
22+
* UM()->Optimize()->images()
23+
*/
24+
class Images {
25+
26+
27+
/**
28+
* Class constructor
29+
*/
30+
public function __construct() {
31+
32+
$profile_photo_caching = UM()->options()->get( 'um_optimize_profile_photo' );
33+
if ( $profile_photo_caching ) {
34+
add_filter( 'um_filter_avatar_cache_time', array( $this, 'avatar_cache_time' ), 10, 2 );
35+
}
36+
37+
$cover_photo_caching = UM()->options()->get( 'um_optimize_cover_photo' );
38+
if ( $cover_photo_caching ) {
39+
add_filter( 'um_user_cover_photo_uri__filter', array( $this, 'cover_photo_uri' ), 10, 3 );
40+
}
41+
42+
$cover_photo_size = UM()->options()->get( 'um_optimize_cover_photo_size' );
43+
if ( $cover_photo_size && ! UM()->mobile()->isTablet() ) {
44+
add_action( 'um_members_after_user_name', array( $this, 'cover_photo_size' ), 10, 2 );
45+
}
46+
}
47+
48+
49+
/**
50+
* Change Profile Photo cache time.
51+
*
52+
* Added to the filter hook `um_filter_avatar_cache_time`.
53+
*
54+
* @see um_get_avatar_uri()
55+
*
56+
* @since 1.2.0
57+
*
58+
* @param int $cache_time Avatar cache time.
59+
* @param int $user_id User ID.
60+
* @return int
61+
*/
62+
public function avatar_cache_time( $cache_time, $user_id ) {
63+
$image = um_profile( 'profile_photo' );
64+
if ( $image ) {
65+
$dir = wp_normalize_path( UM()->uploader()->get_upload_base_dir() );
66+
if ( is_multisite() ) {
67+
$blog_id = get_current_blog_id();
68+
$dir = str_replace( wp_normalize_path( "/sites/$blog_id/" ), '/', $dir );
69+
}
70+
$filename = wp_normalize_path( "$dir/$user_id/$image" );
71+
$filetime = filemtime( $filename );
72+
if ( $filetime ) {
73+
$cache_time = $filetime;
74+
}
75+
}
76+
return $cache_time;
77+
}
78+
79+
80+
/**
81+
* Change Cover Photo cache time.
82+
*
83+
* Added to the filter hook `um_user_cover_photo_uri__filter`.
84+
*
85+
* @see um_user()
86+
*
87+
* @since 1.2.0
88+
*
89+
* @param string $cover_uri Cover photo URL.
90+
* @param bool $is_default Default or not.
91+
* @param array $attrs Attributes.
92+
* @return string
93+
*/
94+
public function cover_photo_uri( $cover_uri, $is_default, $attrs ) {
95+
if ( ! $is_default ) {
96+
$image = um_profile( 'cover_photo' );
97+
$user_id = um_profile( 'ID' );
98+
if ( $image && $user_id ) {
99+
$dir = wp_normalize_path( UM()->uploader()->get_upload_base_dir() );
100+
if ( is_multisite() ) {
101+
$blog_id = get_current_blog_id();
102+
$dir = str_replace( wp_normalize_path( "/sites/$blog_id/" ), '/', $dir );
103+
}
104+
$filename = wp_normalize_path( "$dir/$user_id/$image" );
105+
$filetime = filemtime( $filename );
106+
if ( $filetime ) {
107+
$cover_url = current( explode( '?', $cover_uri ) );
108+
$cover_uri = "$cover_url?$filetime";
109+
}
110+
}
111+
}
112+
return $cover_uri;
113+
}
114+
115+
116+
/**
117+
* Change Cover Photo size for the member directory.
118+
*
119+
* Added to the action hook `um_members_after_user_name`.
120+
*
121+
* @see \um\core\Member_Directory::build_user_card_data()
122+
*
123+
* @since 1.2.0
124+
*
125+
* @param int $user_id User ID.
126+
* @param array $directory_data Directory settings.
127+
*/
128+
public function cover_photo_size( $user_id, $directory_data ) {
129+
UM()->member_directory()->cover_size = UM()->options()->get( 'um_optimize_cover_photo_size' );
130+
}
131+
132+
}
133+
134+
}

includes/core/class-um-optimize.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ static public function instance() {
4848
public function __construct() {
4949

5050
if( UM()->is_ajax() ) {
51+
$this->images();
5152
$this->member_directory();
5253
$this->query();
5354
} elseif ( UM()->is_request( 'admin' ) ) {
5455
$this->admin();
5556
} elseif ( UM()->is_request( 'frontend' ) ) {
5657
$this->assets();
58+
$this->images();
5759
$this->query();
5860
}
5961

@@ -107,6 +109,20 @@ public function assets() {
107109
}
108110

109111

112+
/**
113+
* Optimize images.
114+
*
115+
* @return um_ext\um_optimize\core\Images()
116+
*/
117+
public function images() {
118+
if ( empty( UM()->classes['um_optimize_images'] ) ) {
119+
require_once um_optimize_path . 'includes/core/class-images.php';
120+
UM()->classes['um_optimize_images'] = new um_ext\um_optimize\core\Images();
121+
}
122+
return UM()->classes['um_optimize_images'];
123+
}
124+
125+
110126
/**
111127
* Optimize member directories.
112128
*
@@ -143,7 +159,7 @@ public function query() {
143159
public function clear_files() {
144160
$i = 0;
145161
$dir = wp_normalize_path( UM()->uploader()->get_upload_base_dir() . 'um_optimize/' );
146-
162+
147163
if ( is_dir( $dir ) ) {
148164
$files = scandir( $dir );
149165
foreach( $files as $file ) {

readme.txt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ Author URI: https://github.com/umdevelopera
55
Plugin URI: https://github.com/umdevelopera/um-optimize
66
Tags: ultimate member, optimize, assets
77
Requires at least: 5.5
8-
Tested up to: 6.5.4
9-
Requires UM core at least: 2.6.8
10-
Tested UM core up to: 2.8.6
11-
Stable tag: 1.1.2
8+
Tested up to: 6.6.2
9+
Requires UM core at least: 2.7.0
10+
Tested UM core up to: 2.8.7
11+
Stable tag: 1.1.3
1212
License: GNU Version 2 or Any Later Version
1313
License URI: http://www.gnu.org/licenses/gpl-3.0.txt
1414

@@ -36,6 +36,11 @@ You can install this plugin from the ZIP file as any other plugin. Follow this i
3636

3737
== Changelog ==
3838

39+
= 1.1.3: October 4, 2024 =
40+
41+
* Added: Hook um_optimize_not_dequeue used to filter assets that should not be dequeued.
42+
* Fixed: Issue #5 - Notification Bell.
43+
3944
= 1.1.2: June 13, 2024 =
4045

4146
* Fixed: Issue #2 - Error when "Combine CSS" is active.

um-optimize.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
* Text Domain: um-optimize
99
* Domain Path: /languages
1010
*
11-
* Version: 1.1.2
12-
* UM version: 2.8.6
11+
* Version: 1.1.3
12+
* UM version: 2.8.7
1313
* Requires at least: 5.5
1414
* Requires PHP: 5.6
1515
*

0 commit comments

Comments
 (0)