@@ -289,4 +289,147 @@ function dsframework_add_admin_scripts( $hook ) {
289
289
}
290
290
add_action ( 'admin_enqueue_scripts ' , 'dsframework_add_admin_scripts ' , 10 , 1 );
291
291
292
+ /**
293
+ * Retrieve list of galleryCategory objects.
294
+ *
295
+ * If you change the type to 'link' in the arguments, then the link categories
296
+ * will be returned instead. Also all categories will be updated to be backwards
297
+ * compatible with pre-2.3 plugins and themes.
298
+ *
299
+ * @since 2.1.0
300
+ * @see get_terms() Type of arguments that can be changed.
301
+ * @link http://codex.wordpress.org/Function_Reference/get_categories
302
+ *
303
+ * @param string|array $args Optional. Change the defaults retrieving categories.
304
+ * @return array List of categories.
305
+ */
306
+ function get_gallery_categories ( $ args = '' ) {
307
+ $ defaults = array ( 'taxonomy ' => 'ds-gallery-category ' );
308
+ $ args = wp_parse_args ( $ args , $ defaults );
309
+
310
+ $ taxonomy = $ args ['taxonomy ' ];
311
+ /**
312
+ * Filter the taxonomy used to retrieve terms when calling get_gallery_categories().
313
+ *
314
+ * @since 2.7.0
315
+ *
316
+ * @param string $taxonomy Taxonomy to retrieve terms from.
317
+ * @param array $args An array of arguments. @see get_terms()
318
+ */
319
+ $ taxonomy = apply_filters ( 'get_gallery_categories_taxonomy ' , $ taxonomy , $ args );
320
+
321
+ // Back compat
322
+ if ( isset ($ args ['type ' ]) && 'link ' == $ args ['type ' ] ) {
323
+ _deprecated_argument ( __FUNCTION__ , '3.0 ' , '' );
324
+ $ taxonomy = $ args ['taxonomy ' ] = 'link_gallery_category ' ;
325
+ }
326
+
327
+ $ categories = (array ) get_terms ( $ taxonomy , $ args );
328
+
329
+ foreach ( array_keys ( $ categories ) as $ k )
330
+ _make_cat_compat ( $ categories [$ k ] );
331
+
332
+ return $ categories ;
333
+ }
334
+
335
+ /**
336
+ * Retrieves galleryCategory data given a galleryCategory ID or galleryCategory object.
337
+ *
338
+ * If you pass the $galleryCategory parameter an object, which is assumed to be the
339
+ * galleryCategory row object retrieved the database. It will cache the galleryCategory data.
340
+ *
341
+ * If you pass $galleryCategory an integer of the galleryCategory ID, then that galleryCategory will
342
+ * be retrieved from the database, if it isn't already cached, and pass it back.
343
+ *
344
+ * If you look at get_term(), then both types will be passed through several
345
+ * filters and finally sanitized based on the $filter parameter value.
346
+ *
347
+ * The galleryCategory will converted to maintain backwards compatibility.
348
+ *
349
+ * @since 1.5.1
350
+ * @uses get_term() Used to get the galleryCategory data from the taxonomy.
351
+ *
352
+ * @param int|object $galleryCategory Category ID or Category row object
353
+ * @param string $output Optional. Constant OBJECT, ARRAY_A, or ARRAY_N
354
+ * @param string $filter Optional. Default is raw or no WordPress defined filter will applied.
355
+ * @return mixed Category data in type defined by $output parameter.
356
+ */
357
+ function get_gallery_category ( $ galleryCategory , $ output = OBJECT , $ filter = 'raw ' ) {
358
+ $ galleryCategory = get_term ( $ galleryCategory , 'ds-gallery-category ' , $ output , $ filter );
359
+ if ( is_wp_error ( $ galleryCategory ) )
360
+ return $ galleryCategory ;
361
+
362
+ _make_cat_compat ( $ galleryCategory );
363
+
364
+ return $ galleryCategory ;
365
+ }
366
+
367
+ /**
368
+ * Retrieve galleryCategory object by galleryCategory slug.
369
+ *
370
+ * @since 2.3.0
371
+ *
372
+ * @param string $slug The galleryCategory slug.
373
+ * @return object GalleryCategory data object
374
+ */
375
+ function get_gallery_category_by_slug ( $ slug ) {
376
+ $ category = get_term_by ( 'slug ' , $ slug , 'ds-gallery-category ' );
377
+ if ( $ category )
378
+ _make_cat_compat ( $ category );
379
+
380
+ return $ category ;
381
+ }
382
+
383
+ /**
384
+ * Retrieve galleryCategory link URL.
385
+ *
386
+ * @since 1.0.0
387
+ * @see get_term_link()
388
+ *
389
+ * @param int|object $galleryCategory GalleryCategory ID or object.
390
+ * @return string Link on success, empty string if galleryCategory does not exist.
391
+ */
392
+ function get_gallery_category_link ( $ galleryCategory ) {
393
+ if ( ! is_object ( $ galleryCategory ) )
394
+ $ galleryCategory = (int ) $ galleryCategory ;
395
+
396
+ $ galleryCategory = get_term_link ( $ galleryCategory , 'ds-gallery-category ' );
397
+
398
+ if ( is_wp_error ( $ galleryCategory ) )
399
+ return '' ;
400
+
401
+ return $ galleryCategory ;
402
+ }
403
+
404
+ /**
405
+ * Retrieves post in subcategory of galleryCategory object.
406
+ *
407
+ * @uses WP_Query() Used to get the post data from the galleryCategory.
408
+ *
409
+ * @param object $galleryCategory Category row object
410
+ * @param boolean $includeChildren true for include children
411
+ * @return array List of post.
412
+ */
413
+ function post_in_gallery_category ( $ galleryCategory , $ includeChildren = false ) {
414
+ if (!isset ($ galleryCategory )) return array ();
415
+
416
+ $ tax_query = array (
417
+ 'relation ' => 'AND ' ,
418
+ array (
419
+ 'taxonomy ' => 'ds-gallery-category ' ,
420
+ 'field ' => 'slug ' ,
421
+ 'terms ' => $ galleryCategory ->slug ,
422
+ 'include_children ' => $ includeChildren ,
423
+ 'operator ' => 'IN '
424
+ )
425
+ );
426
+ $ postLoop = new WP_Query ( array (
427
+ 'post_type ' => 'ds-gallery ' ,
428
+ 'posts_per_page ' => -1 ,
429
+ 'tax_query ' => $ tax_query
430
+ ));
431
+
432
+ return $ postLoop ;
433
+ }
434
+
292
435
?>
0 commit comments