Skip to content

Commit 289c42d

Browse files
committed
Prepare version 1.1.0
- Optimize SQL queries to get posts and users faster.
1 parent 8bbf15c commit 289c42d

15 files changed

+1082
-106
lines changed

README.md

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,58 @@ Optimize loading for sites with the Ultimate Member plugin.
66
- Removes CSS and JS files that belongs to Ultimate Member and its extensions from pages where there are no Ultimate Member elements.
77
- Combines CSS and JS files that belongs to Ultimate Member and its extensions on pages with Ultimate Member elements.
88
- Minifies combined files.
9+
- Optimizes SQL queries to get posts and users faster.
910

1011
## Installation
1112

1213
__Note:__ This plugin requires the [Ultimate Member](https://wordpress.org/plugins/ultimate-member/) plugin to be installed first.
1314

1415
### How to install from GitHub
16+
1517
Open git bash, navigate to the **plugins** folder and execute this command:
1618

1719
`git clone --branch=main git@github.com:umdevelopera/um-optimize.git um-optimize`
1820

1921
Once the plugin is cloned, enter your site admin dashboard and go to _wp-admin > Plugins > Installed Plugins_. Find the "Ultimate Member - Optimize" plugin and click the "Activate" link.
2022

2123
### How to install from ZIP archive
22-
You can install this plugin from the [ZIP file](https://drive.google.com/file/d/1It6F176qYjLV3FaQ0b8pXrGdaOAfYJ6H/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
24+
25+
You can install this plugin from the [ZIP file](https://drive.google.com/file/d/1vtzVKyZJ5pgFAWKBs734ehL8Z1JZfuF3/view) as any other plugin. Follow [this instruction](https://wordpress.org/support/article/managing-plugins/#upload-via-wordpress-admin).
2326

2427
## How to use
28+
2529
Go to *wp-admin > Ultimate Member > Settings > General > Optimize* to manage settings:
26-
- Dequeue unused CSS files - Dequeue CSS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.
27-
- Dequeue unused JS files - Dequeue JS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.
28-
- Combine CSS files - Combine CSS files queued by the Ultimate Member plugin and its extensions.
29-
- Combine JS files - Combine JS files queued by the Ultimate Member plugin and its extensions.
30-
- Minify CSS files - *(optional)* Minify combined CSS files.
31-
- Minify JS files - *(optional)* Minify combined JS files.
30+
31+
- **Dequeue unused CSS files** - Dequeue CSS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.
32+
- **Dequeue unused JS files** - Dequeue JS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.
33+
- **Combine CSS files** - Combine CSS files queued by the Ultimate Member plugin and its extensions.
34+
- **Combine JS files** - Combine JS files queued by the Ultimate Member plugin and its extensions.
35+
- **Minify CSS files** - *(optional)* Minify combined CSS files.
36+
- **Minify JS files** - *(optional)* Minify combined JS files.
3237

3338
__Note:__ Settings "Minify CSS files" and "Minify JS files" are hidden if original files are minified.
3439

35-
### Screenshots
40+
- **Speed up Activity** - *(optional)* Optimize the SQL query that retrieves posts for the [Social Activity](https://ultimatemember.com/extensions/social-activity/) extension.
41+
- **Speed up Groups** - *(optional)* Optimize the SQL query that retrieves posts for the [Groups](https://ultimatemember.com/extensions/groups/) extension.
42+
- **Speed up Notes** - *(optional)* Optimize the SQL query that retrieves notes for the [User Notes](https://ultimatemember.com/extensions/user-notes/) extension.
43+
- **Speed up Photos** - *(optional)* Optimize the SQL query that retrieves albums for the [User Photos](https://ultimatemember.com/extensions/user-photos/) extension.
44+
- **Speed up member directories** - *(optional)* Optimize the SQL query that retrieves users for the member directory.
45+
46+
__Note:__ The experimental tool "Speed up member directories" is only available in debug mode for now.
47+
48+
Image - Optimize settings.
49+
![UM Settings, General, Optimize](https://github.com/umdevelopera/um-optimize/assets/113178913/22783720-c9af-4562-8ca7-7fff43123d99)
3650

3751
## Support
3852

39-
This is a free extension created for the community. The Ultimate Member team does not provide any support for this extension. Open new [issue](https://github.com/umdevelopera/um-optimize/issues) if you face a problem.
53+
This is a free extension created for the community. The Ultimate Member team does not provide support for this extension. Open new [issue](https://github.com/umdevelopera/um-optimize/issues) if you are facing a problem or have a suggestion.
4054

4155
## Related links
56+
4257
Ultimate Member home page: https://ultimatemember.com
4358

4459
Ultimate Member documentation: https://docs.ultimatemember.com
4560

4661
Ultimate Member download: https://wordpress.org/plugins/ultimate-member
4762

48-
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)
63+
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: 81 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,38 @@ public function __construct() {
3737
*/
3838
public function extend_settings( $settings ) {
3939

40-
$fields = array(
41-
array(
42-
'id' => 'um_optimize_assets_info',
43-
'type' => 'info_text',
44-
'label' => __( 'CSS and JS', 'um-optimize' ),
45-
'value' => __( 'Optimize CSS and JS files loading', 'um-optimize' ),
46-
),
47-
array(
48-
'id' => 'um_optimize_css_dequeue',
49-
'type' => 'checkbox',
50-
'label' => __( 'Dequeue unused CSS files', 'um-optimize' ),
51-
'tooltip' => __( 'Dequeue CSS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.', 'um-optimize' ),
52-
),
53-
array(
54-
'id' => 'um_optimize_js_dequeue',
55-
'type' => 'checkbox',
56-
'label' => __( 'Dequeue unused JS files', 'um-optimize' ),
57-
'tooltip' => __( 'Dequeue JS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.', 'um-optimize' ),
58-
),
59-
array(
60-
'id' => 'um_optimize_css_combine',
61-
'type' => 'checkbox',
62-
'label' => __( 'Combine CSS files', 'um-optimize' ),
63-
'tooltip' => __( 'Combine CSS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ),
64-
),
65-
array(
66-
'id' => 'um_optimize_js_combine',
67-
'type' => 'checkbox',
68-
'label' => __( 'Combine JS files', 'um-optimize' ),
69-
'tooltip' => __( 'Combine JS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ),
70-
),
40+
$fields = array();
41+
42+
// CSS and JS.
43+
$fields[] = array(
44+
'id' => 'um_optimize_assets_info',
45+
'type' => 'info_text',
46+
'label' => __( 'CSS and JS', 'um-optimize' ),
47+
'value' => __( 'Optimize CSS and JS files loading', 'um-optimize' ),
48+
);
49+
$fields[] = array(
50+
'id' => 'um_optimize_css_dequeue',
51+
'type' => 'checkbox',
52+
'label' => __( 'Dequeue unused CSS files', 'um-optimize' ),
53+
'tooltip' => __( 'Dequeue CSS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.', 'um-optimize' ),
54+
);
55+
$fields[] = array(
56+
'id' => 'um_optimize_js_dequeue',
57+
'type' => 'checkbox',
58+
'label' => __( 'Dequeue unused JS files', 'um-optimize' ),
59+
'tooltip' => __( 'Dequeue JS files queued by the Ultimate Member plugin from pages where there are no Ultimate Member elements.', 'um-optimize' ),
60+
);
61+
$fields[] = array(
62+
'id' => 'um_optimize_css_combine',
63+
'type' => 'checkbox',
64+
'label' => __( 'Combine CSS files', 'um-optimize' ),
65+
'tooltip' => __( 'Combine CSS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ),
66+
);
67+
$fields[] = array(
68+
'id' => 'um_optimize_js_combine',
69+
'type' => 'checkbox',
70+
'label' => __( 'Combine JS files', 'um-optimize' ),
71+
'tooltip' => __( 'Combine JS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ),
7172
);
7273

7374
if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'UM_SCRIPT_DEBUG' ) && UM_SCRIPT_DEBUG ) ) {
@@ -87,6 +88,55 @@ public function extend_settings( $settings ) {
8788
);
8889
}
8990

91+
// SQL queries.
92+
$fields[] = array(
93+
'id' => 'um_optimize_assets_info',
94+
'type' => 'info_text',
95+
'label' => __( 'SQL queries', 'um-optimize' ),
96+
'value' => __( 'Optimize SQL queries to get posts and users faster', 'um-optimize' ),
97+
);
98+
if ( defined( 'um_activity_version' ) ) {
99+
$fields[] = array(
100+
'id' => 'um_optimize_activity',
101+
'type' => 'checkbox',
102+
'label' => __( 'Speed up Activity', 'um-optimize' ),
103+
'tooltip' => __( 'Optimize the SQL query that retrieves posts for the Social Activity extension.', 'um-optimize' ),
104+
);
105+
}
106+
if ( defined( 'um_groups_version' ) ) {
107+
$fields[] = array(
108+
'id' => 'um_optimize_groups',
109+
'type' => 'checkbox',
110+
'label' => __( 'Speed up Groups', 'um-optimize' ),
111+
'tooltip' => __( 'Optimize the SQL query that retrieves posts for the Groups extension.', 'um-optimize' ),
112+
);
113+
}
114+
if ( defined( 'um_user_notes_version' ) ) {
115+
$fields[] = array(
116+
'id' => 'um_optimize_notes',
117+
'type' => 'checkbox',
118+
'label' => __( 'Speed up Notes', 'um-optimize' ),
119+
'tooltip' => __( 'Optimize the SQL query that retrieves notes for the User Notes extension.', 'um-optimize' ),
120+
);
121+
}
122+
if ( defined( 'um_user_photos_version' ) ) {
123+
$fields[] = array(
124+
'id' => 'um_optimize_photos',
125+
'type' => 'checkbox',
126+
'label' => __( 'Speed up Photos', 'um-optimize' ),
127+
'tooltip' => __( 'Optimize the SQL query that retrieves albums for the User Photos extension.', 'um-optimize' ),
128+
);
129+
}
130+
if ( defined( 'WP_DEBUG' ) && UM()->options()->get( 'members_page' ) ) {
131+
$fields[] = array(
132+
'id' => 'um_optimize_members',
133+
'type' => 'checkbox',
134+
'label' => __( 'Speed up member directories', 'um-optimize' ),
135+
'tooltip' => __( 'Optimize the SQL query that retrieves users for the member directory.', 'um-optimize' ),
136+
'description' => __( 'This experimental tool is only available in debug mode for now.', 'um-optimize' ),
137+
);
138+
}
139+
90140
$section = array(
91141
'title' => __( 'Optimize', 'um-optimize' ),
92142
'fields' => $fields,

includes/core/class-assets.php

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,35 @@ public function get_um_assets( $assets, $handles = array() ) {
287287
}
288288

289289

290+
/**
291+
* Get an array of post types added by Ultimate Member and its extensions
292+
*
293+
* @since 1.1.0
294+
*
295+
* @return array A collection of Ultimate Member post types.
296+
*/
297+
public function get_um_post_types() {
298+
$um_post_types = array(
299+
'um_directory',
300+
'um_form',
301+
'um_role',
302+
'um_account_tabs',
303+
'um_activity',
304+
'um_groups',
305+
'um_groups_discussion',
306+
'um_mailchimp',
307+
'um_notice',
308+
'um_private_content',
309+
'um_profile_tabs',
310+
'um_review',
311+
'um_social_login',
312+
'um_notes',
313+
'um_user_photos',
314+
);
315+
return apply_filters( 'um_optimize_post_types', $um_post_types );
316+
}
317+
318+
290319
/**
291320
* Get an array of shortcodes added by Ultimate Member and its extensions
292321
*
@@ -375,27 +404,23 @@ public function is_ultimatemember() {
375404
return true;
376405
}
377406

378-
$um_pages = UM()->config()->permalinks;
379-
$post = get_post();
407+
$um_pages = UM()->config()->permalinks;
408+
$um_post_types = $this->get_um_post_types();
380409

381-
if ( $post && is_a( $post, 'WP_Post' ) ) {
410+
if ( is_singular() ) {
411+
$post = get_post();
382412
if ( in_array( $post->ID, $um_pages, true ) ) {
383413
return true;
384414
}
415+
if ( in_array( $post->post_type, $um_post_types, true ) ) {
416+
return true;
417+
}
385418
foreach ( $this->get_um_shortcodes() as $shortcode ) {
386419
if ( strpos( $post->post_content, '[' . $shortcode ) !== FALSE ) {
387420
$this->has_um_shortcode = true;
388421
return true;
389422
}
390423
}
391-
} elseif ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
392-
$request_uri = wp_unslash( $_SERVER['REQUEST_URI'] );
393-
foreach ( $um_pages as $page_id ) {
394-
$permalink = get_permalink( $page_id );
395-
if ( false !== strpos( $permalink, $request_uri ) ) {
396-
return true;
397-
}
398-
}
399424
}
400425

401426
return false;
@@ -469,23 +494,13 @@ public function optimize_filecontent( $filecontent, $dependency, $ext ) {
469494
'url("../' => 'url("' . $parent_dir . '/',
470495
'url("font' => 'url("' . $dir . '/font',
471496
'url("images' => 'url("' . $dir . '/images',
497+
'url(./' => 'url(' . $dir . '/',
498+
'url(../' => 'url(' . $parent_dir . '/',
499+
'url(font' => 'url(' . $dir . '/font',
500+
'url(images' => 'url(' . $dir . '/images',
472501
);
473502
$filecontent = strtr( $filecontent, $replace_pairs );
474503

475-
/* For testing */
476-
// if ( false !== stripos( $filecontent, 'url("./' ) ) {
477-
// str_replace( 'url("./', 'url("' . $dir . '/', $filecontent );
478-
// }
479-
// if ( false !== stripos( $filecontent, 'url("../' ) ) {
480-
// str_replace( 'url("../', 'url("' . $parent_dir . '/', $filecontent );
481-
// }
482-
// if ( false !== stripos( $filecontent, 'url("font' ) ) {
483-
// str_replace( 'url("font', 'url("' . $dir . '/font', $filecontent );
484-
// }
485-
// if ( false !== stripos( $filecontent, 'url("images' ) ) {
486-
// str_replace( 'url("images', 'url("' . $dir . '/images', $filecontent );
487-
// }
488-
489504
if ( UM()->options()->get( 'um_optimize_css_combine' ) ) {
490505
if ( ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) || ( defined( 'UM_SCRIPT_DEBUG' ) && UM_SCRIPT_DEBUG ) ) {
491506
$pattern = array(
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?php
2+
/**
3+
* Optimize member directories.
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\Member_Directory' ) ) {
15+
16+
/**
17+
* Class Assets
18+
*
19+
* How to get an instance:
20+
* UM()->classes['um_optimize_member_directory']
21+
* UM()->Optimize()->member_directory()
22+
*/
23+
class Member_Directory {
24+
25+
26+
/**
27+
* Class constructor
28+
*/
29+
public function __construct() {
30+
add_filter( 'get_meta_sql', array( $this, 'get_meta_sql' ), 10, 6 );
31+
}
32+
33+
34+
/**
35+
* Filters SQL clauses to be appended to a main query.
36+
*
37+
* @since 1.1.0
38+
*
39+
* @see \um_ext\um_optimize\core\Query::get_meta_sql()
40+
*
41+
* @param string[] $sql Array containing the query's JOIN and WHERE clauses.
42+
* @param array $queries Array of meta queries.
43+
* @param string $type Type of meta.
44+
* @param string $primary_table Primary table.
45+
* @param string $primary_id_column Primary column ID.
46+
* @param object $context Optional. The main query object that corresponds to the type, for
47+
* example a `WP_Query`, `WP_User_Query`, or `WP_Site_Query`.
48+
* Default null.
49+
*
50+
* @return string[] {
51+
* Array containing JOIN and WHERE SQL clauses to append to the main query,
52+
* or false if no table exists for the requested meta type.
53+
*
54+
* @type string $join SQL fragment to append to the main JOIN clause.
55+
* @type string $where SQL fragment to append to the main WHERE clause.
56+
* }
57+
*/
58+
function get_meta_sql( $sql, $queries, $type, $primary_table, $primary_id_column, $context ) {
59+
if ( defined( 'DOING_AJAX' ) && DOING_AJAX
60+
&& defined( 'WP_DEBUG' ) && WP_DEBUG
61+
&& UM()->options()->get( 'members_page' )
62+
&& UM()->options()->get( 'um_optimize_members' )
63+
&& 'user' === $type
64+
&& isset( $_POST['action'] ) && 'um_get_members' === $_POST['action'] ) {
65+
66+
$sql_um = UM()->Optimize()->query()->get_meta_sql( $sql, $queries, $type, $primary_table, $primary_id_column, $context );
67+
68+
// TESTING.
69+
// error_log( 'Test member directory. JOIN: ' . $sql['join'] );
70+
// error_log( 'Test member directory. JOIN_UM: ' . $sql_um['join'] );
71+
// error_log( 'Test member directory. WHERE: ' . $sql['where'] );
72+
// error_log( 'Test member directory. WHERE_UM: ' . $sql_um['where'] );
73+
74+
return $sql_um;
75+
}
76+
return $sql;
77+
}
78+
79+
}
80+
}

0 commit comments

Comments
 (0)