Pods_Advanced_Relationships

The Pods - Custom Content Types and Fields Pods Advanced Relationships class.

Defined (1)

The class is defined in the following location(s).

/components/Advanced-Relationships.php  
  1. class Pods_Advanced_Relationships extends PodsComponent { 
  2.  
  3. /** 
  4. * Do things like register/enqueue scripts and stylesheets 
  5. * @since 2.3 
  6. */ 
  7. public function __construct () { 
  8. add_action( 'pods_form_ui_field_pick_related_objects_other', array( $this, 'add_related_objects' ) ); 
  9.  
  10. /** 
  11. * Add Advanced Related Objects 
  12. * @since 2.3 
  13. */ 
  14. public function add_related_objects () { 
  15. PodsField_Pick::$related_objects[ 'table' ] = array( 
  16. 'label' => __( 'Database Tables', 'pods' ),  
  17. 'group' => __( 'Advanced Objects', 'pods' ) 
  18. ); 
  19.  
  20. if ( is_multisite() ) { 
  21. PodsField_Pick::$related_objects[ 'site' ] = array( 
  22. 'label' => __( 'Multisite Sites', 'pods' ),  
  23. 'group' => __( 'Advanced Objects', 'pods' ) 
  24. ); 
  25.  
  26. PodsField_Pick::$related_objects[ 'network' ] = array( 
  27. 'label' => __( 'Multisite Networks', 'pods' ),  
  28. 'group' => __( 'Advanced Objects', 'pods' ) 
  29. ); 
  30.  
  31. PodsField_Pick::$related_objects[ 'theme' ] = array( 
  32. 'label' => __( 'Themes', 'pods' ),  
  33. 'group' => __( 'Advanced Objects', 'pods' ),  
  34. 'simple' => true,  
  35. 'data_callback' => array( $this, 'data_themes' ) 
  36. ); 
  37.  
  38. PodsField_Pick::$related_objects[ 'page-template' ] = array( 
  39. 'label' => __( 'Page Templates', 'pods' ),  
  40. 'group' => __( 'Advanced Objects', 'pods' ),  
  41. 'simple' => true,  
  42. 'data_callback' => array( $this, 'data_page_templates' ) 
  43. ); 
  44.  
  45. PodsField_Pick::$related_objects[ 'sidebar' ] = array( 
  46. 'label' => __( 'Sidebars', 'pods' ),  
  47. 'group' => __( 'Advanced Objects', 'pods' ),  
  48. 'simple' => true,  
  49. 'data_callback' => array( $this, 'data_sidebars' ) 
  50. ); 
  51.  
  52. PodsField_Pick::$related_objects[ 'post-types' ] = array( 
  53. 'label' => __( 'Post Type Objects', 'pods' ),  
  54. 'group' => __( 'Advanced Objects', 'pods' ),  
  55. 'simple' => true,  
  56. 'data_callback' => array( $this, 'data_post_types' ) 
  57. ); 
  58.  
  59. PodsField_Pick::$related_objects[ 'taxonomies' ] = array( 
  60. 'label' => __( 'Taxonomy Objects', 'pods' ),  
  61. 'group' => __( 'Advanced Objects', 'pods' ),  
  62. 'simple' => true,  
  63. 'data_callback' => array( $this, 'data_taxonomies' ) 
  64. ); 
  65.  
  66. /** 
  67. * Data callback for Themes 
  68. * @param string $name The name of the field 
  69. * @param string|array $value The value of the field 
  70. * @param array $options Field options 
  71. * @param array $pod Pod data 
  72. * @param int $id Item ID 
  73. * @return array 
  74. * @since 2.3 
  75. */ 
  76. public function data_themes ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  77. $data = array(); 
  78.  
  79. $themes = wp_get_themes( array( 'allowed' => true ) ); 
  80.  
  81. foreach ( $themes as $theme ) { 
  82. $data[ $theme->Template ] = $theme->Name; 
  83.  
  84. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  85.  
  86. /** 
  87. * Data callback for Page Templates 
  88. * @param string $name The name of the field 
  89. * @param string|array $value The value of the field 
  90. * @param array $options Field options 
  91. * @param array $pod Pod data 
  92. * @param int $id Item ID 
  93. * @return array 
  94. * @since 2.3 
  95. */ 
  96. public function data_page_templates ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  97. $data = array(); 
  98.  
  99. if ( !function_exists( 'get_page_templates' ) ) 
  100. include_once ABSPATH . 'wp-admin/includes/theme.php'; 
  101.  
  102. $page_templates = apply_filters( 'pods_page_templates', get_page_templates() ); 
  103.  
  104. if ( !in_array( 'page.php', $page_templates ) && locate_template( array( 'page.php', false ) ) ) 
  105. $page_templates[ 'Page (WP Default)' ] = 'page.php'; 
  106.  
  107. if ( !in_array( 'index.php', $page_templates ) && locate_template( array( 'index.php', false ) ) ) 
  108. $page_templates[ 'Index (WP Fallback)' ] = 'index.php'; 
  109.  
  110. ksort( $page_templates ); 
  111.  
  112. $page_templates = array_flip( $page_templates ); 
  113.  
  114. foreach ( $page_templates as $page_template_file => $page_template ) { 
  115. $data[ $page_template_file ] = $page_template; 
  116.  
  117. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  118.  
  119. /** 
  120. * Data callback for Sidebars 
  121. * @param string $name The name of the field 
  122. * @param string|array $value The value of the field 
  123. * @param array $options Field options 
  124. * @param array $pod Pod data 
  125. * @param int $id Item ID 
  126. * @return array 
  127. * @since 2.3 
  128. */ 
  129. public function data_sidebars ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  130. $data = array(); 
  131.  
  132. global $wp_registered_sidebars; 
  133.  
  134. if ( !empty( $wp_registered_sidebars ) ) { 
  135. foreach ( $wp_registered_sidebars as $sidebar ) { 
  136. $data[ $sidebar[ 'id' ] ] = $sidebar[ 'name' ]; 
  137.  
  138. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  139.  
  140. /** 
  141. * Data callback for Post Types 
  142. * @param string $name The name of the field 
  143. * @param string|array $value The value of the field 
  144. * @param array $options Field options 
  145. * @param array $pod Pod data 
  146. * @param int $id Item ID 
  147. * @return array 
  148. * @since 2.3 
  149. */ 
  150. public function data_post_types ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  151. $data = array(); 
  152.  
  153. $post_types = get_post_types( array(), 'objects' ); 
  154.  
  155. $ignore = array( 'revision', 'nav_menu_item' ); 
  156.  
  157. foreach ( $post_types as $post_type ) { 
  158. if ( in_array( $post_type->name, $ignore ) || 0 === strpos( $post_type->name, '_pods_' ) ) 
  159. continue; 
  160.  
  161. $data[ $post_type->name ] = $post_type->label; 
  162.  
  163. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  164.  
  165. /** 
  166. * Data callback for Taxonomies 
  167. * @param string $name The name of the field 
  168. * @param string|array $value The value of the field 
  169. * @param array $options Field options 
  170. * @param array $pod Pod data 
  171. * @param int $id Item ID 
  172. * @return array 
  173. * @since 2.3 
  174. */ 
  175. public function data_taxonomies ( $name = null, $value = null, $options = null, $pod = null, $id = null ) { 
  176. $data = array(); 
  177.  
  178. $taxonomies = get_taxonomies( array(), 'objects' ); 
  179.  
  180. $ignore = array( 'nav_menu', 'post_format' ); 
  181.  
  182. foreach ( $taxonomies as $taxonomy ) { 
  183. if ( in_array( $taxonomy->name, $ignore ) ) 
  184. continue; 
  185.  
  186. $data[ $taxonomy->name ] = $taxonomy->label; 
  187.  
  188. return apply_filters( 'pods_form_ui_field_pick_' . __FUNCTION__, $data, $name, $value, $options, $pod, $id ); 
  189.