Changeset 2477848
- Timestamp:
- 02/19/2021 04:44:16 PM (5 years ago)
- Location:
- hatch/trunk
- Files:
-
- 2 edited
-
abe-hatch.php (modified) (8 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
hatch/trunk/abe-hatch.php
r2474064 r2477848 3 3 * Plugin name: Hatch 4 4 * Author: A Big Egg 5 * Version: 0.4. 35 * Version: 0.4.4 6 6 * Description: Provides helper functions for working with Timber and ACF. Requires Timber (timber-library) and works well with Advanced Custom Fields Pro and Gravity Forms. 7 7 */ … … 15 15 16 16 static $post_transformers = []; 17 static $taxonomy_transformers = []; 17 18 18 19 function __construct() { … … 250 251 */ 251 252 static function get_terms( $args ) { 252 return Timber::get_terms( $args);253 return self::construct_terms( Timber::get_terms( $args ) ); 253 254 } 254 255 … … 291 292 } 292 293 294 295 /** 296 * construct term 297 * 298 * @param mixed $term_id 299 * @return void 300 */ 301 static function construct_term( $term_id = 0 ) { 302 if ( ! $term_id ) { 303 return $term_id; 304 } 305 306 $term = new Timber\Term( $term_id ); 307 308 if ( self::has_transformer_for_taxonomy( $term->taxonomy ) ) { 309 $term = self::transform_term( $term ); 310 } 311 312 return $term; 313 } 314 315 293 316 /** 294 317 * construct_image … … 316 339 317 340 /** 341 * has_transformer_for_term_type 342 * 343 * @param mixed $taxonomy 344 * @return void 345 */ 346 static function has_transformer_for_taxonomy( $taxonomy ) { 347 return isset( self::$taxonomy_transformers[$taxonomy] ); 348 } 349 350 351 /** 318 352 * transform_post 319 353 * … … 329 363 330 364 return call_user_func( $transformer, $post ); 365 } 366 367 /** 368 * transform_term 369 * 370 * @param mixed $post 371 * @return void 372 */ 373 static function transform_term( $term ) { 374 $transformer = self::$taxonomy_transformers[$term->taxonomy]; 375 376 if ( ! self::has_transformer_for_taxonomy( $term->taxonomy ) ) { 377 return $term; 378 } 379 380 return call_user_func( $transformer, $term ); 331 381 } 332 382 … … 346 396 347 397 398 /** 399 * construct_terms 400 * 401 * @param mixed $post_id 402 * @return void 403 */ 404 static function construct_terms( $array_of_terms ) { 405 if ( ! is_array( $array_of_terms ) ) { 406 return []; 407 } 408 409 return array_map( 'self::construct_term', $array_of_terms ); 410 } 411 412 348 413 349 414 /** … … 359 424 } 360 425 426 /** 427 * Register a transformer for a taxonomy 428 * 429 * @param mixed $taxonomy 430 * @param mixed $callback 431 * @return void 432 */ 433 static function register_transformer_for_taxonomy( $taxonomy, $callback ) { 434 self::$taxonomy_transformers[$taxonomy] = $callback; 435 } 361 436 /** 362 437 * Debug function - call this to dump the current context to inspect it -
hatch/trunk/readme.txt
r2474064 r2477848 4 4 Requires at least: 4.7 5 5 Tested up to: 5.6.1 6 Stable tag: 0.4. 36 Stable tag: 0.4.4 7 7 Requires PHP: 7.0 8 8 License: MIT
Note: See TracChangeset
for help on using the changeset viewer.