@@ -196,6 +196,7 @@ private static function cleanup_header_comment($str) {
196
196
*
197
197
* @param string $file Absolute path to the file.
198
198
*
199
+ * @copyright forked from https://developer.wordpress.org/reference/functions/get_file_data/
199
200
* @return string[] Array of file header values keyed by header name.
200
201
*/
201
202
public static function get_snippet_meta_from_file ($ file ) {
@@ -248,6 +249,7 @@ public static function add_builtin_snippets() {
248
249
global $ DB ;
249
250
$ paths = self ::get_builtin_snippet_paths ();
250
251
252
+ // Get builtin snippets which are known in the database.
251
253
$ present = $ DB ->get_records (
252
254
'theme_boost_union_snippets ' ,
253
255
['source ' => 'theme_boost_union ' ],
@@ -257,7 +259,8 @@ public static function add_builtin_snippets() {
257
259
0 ,
258
260
);
259
261
260
- $ sortorder = empty ($ present ) ? 0 : $ present [0 ]->sortorder + 1 ;
262
+ // Get the highest sortorder present.
263
+ $ sortorder = empty ($ present ) ? 0 : intval (reset ($ present )->sortorder ) + 1 ;
261
264
262
265
foreach ($ paths as $ path ) {
263
266
if (!array_key_exists ($ path , $ present )) {
@@ -269,6 +272,7 @@ public static function add_builtin_snippets() {
269
272
'sortorder ' => $ sortorder ,
270
273
]
271
274
);
275
+ // We add each record with incrementing sortorder.
272
276
$ sortorder += 1 ;
273
277
}
274
278
}
0 commit comments