Overview

Classes

  • xu
  • Xu\Foundation\Foundation
  • Xu\Foundation\Jsonable
  • Xu\Model\Collection
  • Xu\Model\Model

Functions

  • xu
  • xu_add_option
  • xu_attachment_url_to_postid
  • xu_cache_delete
  • xu_cache_delete_group
  • xu_cache_get
  • xu_cache_key
  • xu_camel_case
  • xu_clean_attachment_cache
  • xu_clean_nav_menu_cache
  • xu_clean_post_cache
  • xu_contains
  • xu_convert_to_string
  • xu_current_attachment_url_to_postid
  • xu_current_url
  • xu_current_url_to_postid
  • xu_dashify
  • xu_delete_option
  • xu_delete_site_transient
  • xu_delete_transient
  • xu_doing_ajax
  • xu_ends_with
  • xu_get_class_name
  • xu_get_model
  • xu_get_option
  • xu_get_option_name
  • xu_get_option_post_id
  • xu_get_posts
  • xu_get_site_transient
  • xu_get_top_parent_post
  • xu_get_top_parent_post_type
  • xu_get_top_parent_post_type_object
  • xu_get_transient
  • xu_is_empty
  • xu_is_http_method
  • xu_is_json
  • xu_is_post_type
  • xu_is_wp
  • xu_is_xml
  • xu_post_exists
  • xu_register_large_option_post_type
  • xu_snake_case
  • xu_starts_with
  • xu_strip_spaces
  • xu_studly_case
  • xu_update_option
  • xu_url_to_postid
  • xu_valid_personnummer
  • xu_wp_get_attachment_image
  • xu_wp_get_attachment_image_sizes
  • xu_wp_get_attachment_image_src
  • xu_wp_get_attachment_image_srcset
  • xu_wp_get_attachment_url
  • xu_wp_nav_menu
  • Overview
  • Class
 1: <?php
 2: 
 3: /**
 4:  * Get a model.
 5:  *
 6:  * @param  mixed  $model The model name or a model object.
 7:  * @param  array  $args  The model args. Default empty array.
 8:  * @param  string $dir   The models directory. Default 'models'.
 9:  *
10:  * @return mixed
11:  */
12: function xu_get_model( $model, array $args = [], $dir = 'models' ) {
13:     if ( method_exists( $model, 'model' ) ) {
14:         return call_user_func_array( [$model, 'model'], $args );
15:     }
16: 
17:     $file  = null;
18:     $names = [
19:         sprintf( '%s/class-%s.php', $dir, $model ),
20:         sprintf( '%s/%s.php', $dir, $model )
21:     ];
22: 
23:     foreach ( $names as $name ) {
24:         /**
25:          * Get model in different location than the theme.
26:          *
27:          * @param  string $name
28:          */
29:         if ( $file = apply_filters( 'xu_get_model', $model ) ) {
30:             if ( file_exists( $file ) ) {
31:                 break;
32:             }
33:         }
34: 
35:         // Locate model in theme.
36:         if ( $file = locate_template( $name, true ) ) {
37:             if ( file_exists( $file ) ) {
38:                 break;
39:             }
40:         }
41:     }
42: 
43:     if ( empty( $file ) ) {
44:         return;
45:     }
46: 
47:     $class_name = xu_get_class_name( $file );
48:     $reflection = new ReflectionClass( $class_name );
49: 
50:     return $reflection->newInstanceArgs( $args );
51: }
52: 
API documentation generated by ApiGen