Advertisement
Guest User

Untitled

a guest
Jul 11th, 2014
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.46 KB | None | 0 0
  1. <?php
  2.  
  3. global $intense_post_types;
  4.  
  5. class Intense_Post_Type {
  6. public $type;
  7. public $title;
  8. public $singular;
  9. public $plural;
  10. public $fields;
  11. public $icon;
  12.  
  13. public function register() {
  14. //CPT's
  15. if ( $this->type != 'intense_post' ) {
  16. register_post_type(
  17. $this->type,
  18. array(
  19. 'labels' => array(
  20. 'name' => $this->plural,
  21. 'singular_name' => $this->singular,
  22. 'menu_name' => $this->plural,
  23. 'all_items' => __( 'All', "intense" ) . ' ' . $this->plural,
  24. 'add_new_item' => __( 'Add New', "intense" ) . ' ' . $this->singular,
  25. 'edit_item' => __( 'Edit', "intense" ) . ' ' . $this->singular,
  26. 'new_item' => __( 'New', "intense" ) . ' ' . $this->singular,
  27. 'view_item' => __( 'View', "intense" ) . ' ' . $this->singular,
  28. 'search_items' => __( 'Edit', "intense" ) . ' ' . $this->singular,
  29. 'not_found' => __( 'No', "intense" ) . ' ' . $this->plural . ' ' . __( 'found', "intense" ),
  30. 'not_found_in_trash' => __( 'No', "intense" ) . ' ' . $this->plural . ' ' . __( 'found in Trash', "intense" )
  31. ),
  32. 'public' => true,
  33. 'has_archive' => true,
  34. 'rewrite' => array( 'slug' => strtolower( $this->singular ) ),
  35. 'supports' => array( 'title', 'editor', 'thumbnail', 'comments' ),
  36. 'can_export' => true,
  37. 'menu_icon'=> $this->icon,
  38. )
  39. );
  40. flush_rewrite_rules();
  41. }
  42.  
  43. if ( function_exists( "register_field_group" ) && $this->type != 'intense_snippets' ) {
  44. $postType = $this->type;
  45.  
  46. if ( $this->type == 'intense_post' ) {
  47. $postType = 'post';
  48. }
  49.  
  50. register_field_group( array (
  51. 'id' => 'acf_' . strtolower( $this->singular ) . '-options',
  52. 'title' => $this->singular . ' ' . __( 'Options', "intense" ),
  53. 'fields' => $this->fields,
  54. 'location' => array (
  55. array (
  56. array (
  57. 'param' => 'post_type',
  58. 'operator' => '==',
  59. 'value' => $postType,
  60. 'order_no' => 0,
  61. 'group_no' => 0,
  62. ),
  63. ),
  64. ),
  65. 'options' => array (
  66. 'position' => 'normal',
  67. 'layout' => 'default',
  68. 'hide_on_screen' => array (
  69. ),
  70. ),
  71. 'menu_order' => 0,
  72. ) );
  73. }
  74.  
  75. if ( isset( $this->category_taxonomy_key ) && $this->category_taxonomy_key != '' ) {
  76. $this->register_category_taxonomy( $this->category_taxonomy_key );
  77. }
  78.  
  79. if ( is_array( $this->taxonomies ) ) {
  80. foreach ( $this->taxonomies as $key => $taxonomy ) {
  81. if ( is_array( $taxonomy ) ) {
  82. $this->register_taxonomy( $taxonomy['key'] ,$taxonomy['singular'], $taxonomy['plural'] );
  83. }
  84. }
  85. }
  86. }
  87.  
  88. public function register_category_taxonomy( $key ) {
  89. register_taxonomy( $key, $this->type, array( 'hierarchical' => true, 'label' => $this->singular . ' ' . __( 'Categories', "intense" ), 'query_var' => true, 'rewrite' => true ) );
  90. }
  91.  
  92. public function register_taxonomy( $key, $singular, $plural ) {
  93. $labels = array();
  94. $labels['name'] = $plural;
  95. $labels['singular_name'] = $singular;
  96. $labels['search_items'] = __( 'Search', "intense" ) . ' ' . $plural;
  97. $labels['add_new_item'] = __( 'Add New', "intense" ) . ' ' . $singular;
  98. $labels['new_item_name'] = __( 'New', "intense" ) . ' ' . $singular . ' ' . __( 'Name', "intense" );
  99. $labels['menu_name'] = $plural;
  100.  
  101. register_taxonomy( $key, $this->type, array( 'hierarchical' => true, 'label' => $plural, 'labels' => $labels, 'query_var' => true, 'rewrite' => true ) );
  102. }
  103.  
  104. public function get_excerpt( $limit ) {
  105. $excerpt = explode( ' ', get_the_excerpt(), $limit );
  106.  
  107. return $this->get_clean_excerpt( $excerpt, $limit );
  108. }
  109.  
  110. protected function get_clean_excerpt( $excerpt, $limit ) {
  111. if ( count( $excerpt ) >= $limit ) {
  112. array_pop( $excerpt );
  113. $excerpt = implode( " ", $excerpt ).'...';
  114. } else {
  115. $excerpt = implode( " ", $excerpt );
  116. }
  117.  
  118. $excerpt = preg_replace( '`\[[^\]]*\]`', '', $excerpt );
  119.  
  120. return $excerpt;
  121. }
  122.  
  123. public function get_content( $limit ) {
  124. $content = get_the_content();
  125.  
  126. return $this->get_clean_content( $content, $limit );
  127. }
  128.  
  129. protected function get_clean_content( $content, $limit ) {
  130. $original_content = preg_replace( "~(?:\[/?)[^/\]]+/?\]~s", '', $content );
  131.  
  132. $content = explode( ' ', $original_content, $limit );
  133.  
  134. if ( count( $content ) >= $limit ) {
  135. array_pop( $content );
  136. $content = implode( " ", $content ).'...';
  137. } else {
  138. $content = implode( " ", $content );
  139. }
  140.  
  141. $content = apply_filters( 'the_content', $content );
  142. $content = str_replace( ']]>', ']]&gt;', $content );
  143.  
  144. return $content;
  145. }
  146.  
  147. public function get_subtitle() {
  148. return '';
  149. }
  150. }
  151.  
  152. class Intense_Post_Types {
  153. public $post_types;
  154.  
  155. function __construct() {
  156. $this->add_types();
  157.  
  158. add_action( 'wp_loaded', array( $this, 'register' ) );
  159. add_filter( 'enter_title_here', array( $this, 'get_title' ) );
  160. add_filter( 'template_include', array( $this, 'content_single' ) );
  161. }
  162.  
  163. function add_types() {
  164. global $intense_visions_options;
  165.  
  166. $types = array (
  167. "books",
  168. "clients",
  169. "coupons",
  170. "events",
  171. "faq",
  172. "jobs",
  173. "locations",
  174. "movies",
  175. "news",
  176. "portfolio",
  177. "post",
  178. //"pricing",
  179. "project",
  180. "quotes",
  181. "recipes",
  182. "snippets",
  183. "team",
  184. "templates",
  185. "testimonials",
  186. );
  187.  
  188. foreach ( $types as $custom_post_type ) {
  189. if ( isset( $intense_visions_options[ 'intense_cpt_' . $custom_post_type ] ) && $intense_visions_options[ 'intense_cpt_' . $custom_post_type ] ) {
  190. require_once INTENSE_PLUGIN_FOLDER . '/inc/cpt/' . $custom_post_type . '.php';
  191.  
  192. $class = "Intense_Post_Type_" . ucfirst( $custom_post_type );
  193. $object = new $class();
  194.  
  195. $this->post_types[ strtolower( $class ) ] = $object;
  196. }
  197. }
  198.  
  199. require_once INTENSE_PLUGIN_FOLDER . '/inc/cpt/post.php';
  200. $this->post_types[ 'intense_post_type_post' ] = new Intense_Post_Type_Post();
  201. }
  202.  
  203. function is_type_enabled( $type ) {
  204. $post_type = $this->get_post_type( $type );
  205.  
  206. if ( isset( $post_type ) ) {
  207. return true;
  208. } else {
  209. return false;
  210. }
  211.  
  212. }
  213.  
  214. function register() {
  215. foreach ($this->post_types as $key => $value) {
  216. $value->register();
  217. }
  218. }
  219.  
  220. function get_post_type( $type ) {
  221. $class = strtolower( "Intense_Post_Type_" . ucfirst( str_replace( 'intense_', '', $type ) ) );
  222.  
  223. if ( isset( $this->post_types[ $class ] ) ) {
  224. return $this->post_types[ $class ];
  225. }
  226.  
  227. return null;
  228. }
  229.  
  230. function get_title( $title ) {
  231. $screen = get_current_screen();
  232. $type = $screen->post_type;
  233. $post_type = $this->get_post_type( $type );
  234.  
  235. if ( isset( $post_type ) ) {
  236. $title = $post_type->title;
  237. }
  238.  
  239. return $title;
  240. }
  241.  
  242. function content_single( $single_template ) {
  243. global $intense_visions_options;
  244.  
  245. $post_type = $this->get_post_type( get_post_type() );
  246.  
  247. if ( is_single() && !is_page() && !empty( $post_type ) && get_post_type() != 'intense_templates' ) {
  248. if ( get_field( get_post_type() . '_single_template' ) != '' ) {
  249. $template = get_field( 'intense_' . str_replace( 'intense_', '', get_post_type() ) . '_single_template' );
  250. } else {
  251. $template = $intense_visions_options[ 'intense_cpt_' . str_replace( 'intense_', '', get_post_type() ) . '_single' ];
  252. }
  253.  
  254. // if the template is numeric then it is a templates that they have saved in WordPress
  255. if ( is_numeric( str_replace("template_", "", $template ) ) ) {
  256. $template_post = get_post( str_replace("template_", "", $template ) );
  257. $found_template = Intense_Post_Type_Templates::get_template_cache( $template_post->ID );
  258. } else {
  259. $found_template = intense_locate_plugin_template( '/custom-post/' . get_post_type() . '/single/' . $template . '.php' );
  260. }
  261.  
  262. if ( !empty( $found_template ) ) {
  263. $single_template = $found_template;
  264. }
  265. }
  266.  
  267. return $single_template;
  268. }
  269. }
  270.  
  271. $intense_post_types = new Intense_Post_Types();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement