|
1 | 1 | <?php
|
2 | 2 | /**
|
3 | 3 | * Admin features.
|
4 |
| - * |
5 |
| - * @package um_ext\um_optimize\admin |
6 | 4 | */
|
7 | 5 |
|
8 | 6 | namespace um_ext\um_optimize\admin;
|
@@ -37,130 +35,159 @@ public function __construct() {
|
37 | 35 | */
|
38 | 36 | public function extend_settings( $settings ) {
|
39 | 37 |
|
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' ), |
| 38 | + $sections = array( |
| 39 | + $this->settings_section_assets(), |
| 40 | + $this->settings_section_images(), |
| 41 | + $this->settings_section_queries(), |
72 | 42 | );
|
73 | 43 |
|
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' ), |
| 44 | + $settings['']['sections']['optimize'] = array( |
| 45 | + 'title' => __( 'Optimize', 'um-optimize' ), |
| 46 | + 'form_sections' => $sections, |
80 | 47 | );
|
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' ), |
| 48 | + |
| 49 | + return $settings; |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + /** |
| 54 | + * Section "CSS and JS". |
| 55 | + * |
| 56 | + * @return array |
| 57 | + */ |
| 58 | + public function settings_section_assets() { |
| 59 | + |
| 60 | + $fields = array( |
| 61 | + array( |
| 62 | + 'id' => 'um_optimize_css_dequeue', |
| 63 | + 'type' => 'checkbox', |
| 64 | + 'label' => __( 'Dequeue unused styles', 'um-optimize' ), |
| 65 | + 'description' => __( 'Dequeue CSS files on pages that do not have Ultimate Member components.', 'um-optimize' ), |
| 66 | + ), |
| 67 | + array( |
| 68 | + 'id' => 'um_optimize_js_dequeue', |
| 69 | + 'type' => 'checkbox', |
| 70 | + 'label' => __( 'Dequeue unused scripts', 'um-optimize' ), |
| 71 | + 'description' => __( 'Dequeue JS files on pages that do not have Ultimate Member components.', 'um-optimize' ), |
| 72 | + ), |
| 73 | + array( |
| 74 | + 'id' => 'um_optimize_css_combine', |
| 75 | + 'type' => 'checkbox', |
| 76 | + 'label' => __( 'Combine styles', 'um-optimize' ), |
| 77 | + 'description' => __( 'Combine CSS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ), |
| 78 | + ), |
| 79 | + array( |
| 80 | + 'id' => 'um_optimize_js_combine', |
| 81 | + 'type' => 'checkbox', |
| 82 | + 'label' => __( 'Combine scripts', 'um-optimize' ), |
| 83 | + 'description' => __( 'Combine JS files queued by the Ultimate Member plugin and its extensions.', 'um-optimize' ), |
| 84 | + ), |
86 | 85 | );
|
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' ), |
| 86 | + |
| 87 | + return array( |
| 88 | + 'title' => __( 'CSS and JS', 'um-optimize' ), |
| 89 | + 'description' => __( 'Ultimate Member loads various styles and scripts that are necessary for its components to work. Extensions can also load their own styles and scripts. Loading many styles and scripts can slow down page rendering. It is recommended to disable loading of Ultimate Member styles and scripts on pages that do not have its components. Loading one large style or script file has less impact on page rendering delay than loading multiple files. It is recommended to combine multiple Ultimate Member styles and scripts into one style file and one script file.', 'um-optimize' ), |
| 90 | + 'fields' => $fields, |
92 | 91 | );
|
| 92 | + } |
| 93 | + |
93 | 94 |
|
| 95 | + /** |
| 96 | + * Section "Images". |
| 97 | + * |
| 98 | + * @return array |
| 99 | + */ |
| 100 | + public function settings_section_images(){ |
94 | 101 | $sizes = UM()->files()->get_profile_photo_size( 'cover_thumb_sizes' );
|
95 | 102 | $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 | 103 |
|
| 104 | + $fields = array( |
| 105 | + array( |
| 106 | + 'id' => 'um_optimize_profile_photo', |
| 107 | + 'type' => 'checkbox', |
| 108 | + 'label' => __( 'Profile Photo caching', 'um-optimize' ), |
| 109 | + 'description' => __( 'Allow using Profile Photo images from the browser cache.', 'um-optimize' ), |
| 110 | + ), |
| 111 | + array( |
| 112 | + 'id' => 'um_optimize_cover_photo', |
| 113 | + 'type' => 'checkbox', |
| 114 | + 'label' => __( 'Cover Photo caching', 'um-optimize' ), |
| 115 | + 'description' => __( 'Allow using Cover Photo images from the browser cache.', 'um-optimize' ), |
| 116 | + ), |
| 117 | + array( |
| 118 | + 'id' => 'um_optimize_cover_photo_size', |
| 119 | + 'type' => 'select', |
| 120 | + 'size' => 'small', |
| 121 | + 'label' => __( 'Cover Photo size in directory', 'um-optimize' ), |
| 122 | + 'default' => UM()->options()->get( 'profile_coversize' ), |
| 123 | + 'options' => $sizes, |
| 124 | + 'description' => __( 'Select the size of the Cover Photo thumbnail for the member directory.', 'um-optimize' ), |
| 125 | + ), |
| 126 | + ); |
106 | 127 |
|
107 |
| - // SQL queries. |
108 |
| - $fields[] = array( |
109 |
| - 'id' => 'um_optimize_queries_info', |
110 |
| - 'type' => 'info_text', |
111 |
| - 'label' => __( 'SQL queries', 'um-optimize' ), |
112 |
| - 'value' => __( 'Optimize SQL queries to get posts and users faster', 'um-optimize' ), |
| 128 | + return array( |
| 129 | + 'title' => __( 'Images', 'um-optimize' ), |
| 130 | + 'description' => __( 'Ultimate Member does not allow using Cover Photo and Profile Photo images from the browser cache. This approach is safe and secure, but it slows down rendering pages with Ultimate Member components and loading the member directory. It is recommended to allow using images from the browser cache if your site is public. Ultimate Member uses the largest Cover Photo thumbnail in the member directory on the desktop. Such large images are usually not necessary. It is recommended to use an image that is 500px wide or slightly larger.', 'um-optimize' ), |
| 131 | + 'fields' => $fields, |
113 | 132 | );
|
| 133 | + } |
| 134 | + |
| 135 | + |
| 136 | + /** |
| 137 | + * Section "SQL queries". |
| 138 | + * |
| 139 | + * @return array |
| 140 | + */ |
| 141 | + public function settings_section_queries(){ |
| 142 | + |
| 143 | + $fields = array(); |
| 144 | + |
| 145 | + if ( UM()->options()->get( 'members_page' ) ) { |
| 146 | + $fields[] = array( |
| 147 | + 'id' => 'um_optimize_members', |
| 148 | + 'type' => 'checkbox', |
| 149 | + 'label' => __( 'Speed up member directories', 'um-optimize' ), |
| 150 | + 'description' => __( 'Optimize the SQL query that retrieves users for the member directory.', 'um-optimize' ), |
| 151 | + ); |
| 152 | + } |
114 | 153 | if ( defined( 'um_activity_version' ) ) {
|
115 | 154 | $fields[] = array(
|
116 |
| - 'id' => 'um_optimize_activity', |
117 |
| - 'type' => 'checkbox', |
118 |
| - 'label' => __( 'Speed up Activity', 'um-optimize' ), |
119 |
| - 'tooltip' => __( 'Optimize the SQL query that retrieves posts for the Social Activity extension.', 'um-optimize' ), |
| 155 | + 'id' => 'um_optimize_activity', |
| 156 | + 'type' => 'checkbox', |
| 157 | + 'label' => __( 'Speed up Activity', 'um-optimize' ), |
| 158 | + 'description' => __( 'Optimize the SQL query that retrieves posts for the Social Activity extension.', 'um-optimize' ), |
120 | 159 | );
|
121 | 160 | }
|
122 | 161 | if ( defined( 'um_groups_version' ) ) {
|
123 | 162 | $fields[] = array(
|
124 |
| - 'id' => 'um_optimize_groups', |
125 |
| - 'type' => 'checkbox', |
126 |
| - 'label' => __( 'Speed up Groups', 'um-optimize' ), |
127 |
| - 'tooltip' => __( 'Optimize the SQL query that retrieves posts for the Groups extension.', 'um-optimize' ), |
| 163 | + 'id' => 'um_optimize_groups', |
| 164 | + 'type' => 'checkbox', |
| 165 | + 'label' => __( 'Speed up Groups', 'um-optimize' ), |
| 166 | + 'description' => __( 'Optimize the SQL query that retrieves posts for the Groups extension.', 'um-optimize' ), |
128 | 167 | );
|
129 | 168 | }
|
130 | 169 | if ( defined( 'um_user_notes_version' ) ) {
|
131 | 170 | $fields[] = array(
|
132 |
| - 'id' => 'um_optimize_notes', |
133 |
| - 'type' => 'checkbox', |
134 |
| - 'label' => __( 'Speed up Notes', 'um-optimize' ), |
135 |
| - 'tooltip' => __( 'Optimize the SQL query that retrieves notes for the User Notes extension.', 'um-optimize' ), |
| 171 | + 'id' => 'um_optimize_notes', |
| 172 | + 'type' => 'checkbox', |
| 173 | + 'label' => __( 'Speed up Notes', 'um-optimize' ), |
| 174 | + 'description' => __( 'Optimize the SQL query that retrieves notes for the User Notes extension.', 'um-optimize' ), |
136 | 175 | );
|
137 | 176 | }
|
138 | 177 | if ( defined( 'um_user_photos_version' ) ) {
|
139 | 178 | $fields[] = array(
|
140 |
| - 'id' => 'um_optimize_photos', |
141 |
| - 'type' => 'checkbox', |
142 |
| - 'label' => __( 'Speed up Photos', 'um-optimize' ), |
143 |
| - 'tooltip' => __( 'Optimize the SQL query that retrieves albums for the User Photos extension.', 'um-optimize' ), |
144 |
| - ); |
145 |
| - } |
146 |
| - if ( UM()->options()->get( 'members_page' ) ) { |
147 |
| - $fields[] = array( |
148 |
| - 'id' => 'um_optimize_members', |
149 |
| - 'type' => 'checkbox', |
150 |
| - 'label' => __( 'Speed up member directories', 'um-optimize' ), |
151 |
| - 'tooltip' => __( 'Optimize the SQL query that retrieves users for the member directory.', 'um-optimize' ), |
| 179 | + 'id' => 'um_optimize_photos', |
| 180 | + 'type' => 'checkbox', |
| 181 | + 'label' => __( 'Speed up Photos', 'um-optimize' ), |
| 182 | + 'description' => __( 'Optimize the SQL query that retrieves albums for the User Photos extension.', 'um-optimize' ), |
152 | 183 | );
|
153 | 184 | }
|
154 | 185 |
|
155 |
| - $section = array( |
156 |
| - 'title' => __( 'Optimize', 'um-optimize' ), |
157 |
| - 'fields' => $fields, |
| 186 | + return empty( $fields ) ? null : array( |
| 187 | + 'title' => __( 'SQL queries', 'um-optimize' ), |
| 188 | + 'description' => __( 'Ultimate Member uses the standard WP_Query and WP_User_Query classes to build database queries. Queries built this way are reliable and stable, but not optimized. This slows down retrieving users in the user directory and posts in extensions that use custom post type, which slows down page rendering. It is recommended to enable SQL queries optimization to get posts and users faster.', 'um-optimize' ), |
| 189 | + 'fields' => $fields, |
158 | 190 | );
|
159 |
| - |
160 |
| - $settings['']['sections']['optimize'] = $section; |
161 |
| - |
162 |
| - return $settings; |
163 | 191 | }
|
164 |
| - |
165 | 192 | }
|
166 | 193 | }
|
0 commit comments