/core/controllers/third_party.php

  1. <?php  
  2.  
  3. /** 
  4. * acf_third_party 
  5. * 
  6. * @description: controller for add-ons sub menu page 
  7. * @since: 3.6 
  8. * @created: 25/01/13 
  9. */ 
  10.  
  11. class acf_third_party 
  12. /** 
  13. * __construct 
  14. * 
  15. * @description:  
  16. * @since 3.1.8 
  17. * @created: 23/06/12 
  18. */ 
  19.  
  20. function __construct() 
  21. // Tabify Edit Screen - http://wordpress.org/extend/plugins/tabify-edit-screen/ 
  22. add_action('admin_head-settings_page_tabify-edit-screen', array($this, 'admin_head_tabify')); 
  23.  
  24.  
  25. // Duplicate Post - http://wordpress.org/extend/plugins/duplicate-post/ 
  26. add_action('dp_duplicate_page', array($this, 'dp_duplicate_page'), 11, 2); 
  27.  
  28.  
  29. // Post Type Switcher - http://wordpress.org/extend/plugins/post-type-switcher/ 
  30. add_filter('pts_post_type_filter', array($this, 'pts_post_type_filter')); 
  31.  
  32.  
  33.  
  34. /** 
  35. * pts_allowed_pages 
  36. * 
  37. * @description:  
  38. * @since 3.5.3 
  39. * @created: 19/11/12 
  40. */ 
  41.  
  42. function pts_post_type_filter( $args ) 
  43.  
  44. // global 
  45. global $typenow; 
  46.  
  47. if( $typenow == "acf" ) 
  48. $args = array( 
  49. 'public' => false,  
  50. 'show_ui' => true 
  51. ); 
  52.  
  53.  
  54. // return 
  55. return $args; 
  56.  
  57.  
  58. /** 
  59. * admin_head_tabify 
  60. * 
  61. * @description:  
  62. * @since 3.5.1 
  63. * @created: 9/10/12 
  64. */ 
  65.  
  66. function admin_head_tabify() 
  67. // remove ACF from the tabs 
  68. add_filter('tabify_posttypes', array($this, 'tabify_posttypes')); 
  69.  
  70.  
  71. // add acf metaboxes to list 
  72. add_action('tabify_add_meta_boxes' , array($this, 'tabify_add_meta_boxes')); 
  73.  
  74.  
  75.  
  76. /** 
  77. * tabify_posttypes 
  78. * 
  79. * @description:  
  80. * @since 3.5.1 
  81. * @created: 9/10/12 
  82. */ 
  83.  
  84. function tabify_posttypes( $posttypes ) 
  85. if( isset($posttypes['acf']) ) 
  86. unset( $posttypes['acf'] ); 
  87.  
  88. return $posttypes; 
  89.  
  90.  
  91. /** 
  92. * tabify_add_meta_boxes 
  93. * 
  94. * @description:  
  95. * @since 3.5.1 
  96. * @created: 9/10/12 
  97. */ 
  98.  
  99. function tabify_add_meta_boxes( $post_type ) 
  100. // get acf's 
  101. $acfs = apply_filters('acf/get_field_groups', array()); 
  102.  
  103. if($acfs) 
  104. foreach($acfs as $acf) 
  105. // add meta box 
  106. add_meta_box( 
  107. 'acf_' . $acf['id'],  
  108. $acf['title'],  
  109. array($this, 'dummy'),  
  110. $post_type 
  111. ); 
  112.  
  113. // foreach($acfs as $acf) 
  114. // if($acfs) 
  115.  
  116. function dummy() { /** Do Nothing */
  117.  
  118.  
  119.  
  120. /** 
  121. * dp_duplicate_page 
  122. * 
  123. * @description:  
  124. * @since 3.5.1 
  125. * @created: 9/10/12 
  126. */ 
  127.  
  128. function dp_duplicate_page( $new_post_id, $old_post_object ) 
  129. // only for acf 
  130. if( $old_post_object->post_type != "acf" ) 
  131. return; 
  132.  
  133.  
  134. // update keys 
  135. $metas = get_post_custom( $new_post_id ); 
  136.  
  137.  
  138. if( $metas ) 
  139. foreach( $metas as $field_key => $field ) 
  140. if( strpos($field_key, 'field_') !== false ) 
  141. $field = $field[0]; 
  142. $field = maybe_unserialize( $field ); 
  143. $field = maybe_unserialize( $field ); // just to be sure! 
  144.  
  145. // delete old field 
  146. delete_post_meta($new_post_id, $field_key); 
  147.  
  148.  
  149. // set new keys (recursive for sub fields) 
  150. $this->create_new_field_keys( $field ); 
  151.  
  152.  
  153. // save it! 
  154. update_post_meta($new_post_id, $field['key'], $field); 
  155.  
  156. // if( strpos($field_key, 'field_') !== false ) 
  157. // foreach( $metas as $field_key => $field ) 
  158. // if( $metas ) 
  159.  
  160.  
  161.  
  162. /** 
  163. * create_new_field_keys 
  164. * 
  165. * @description:  
  166. * @since 3.5.1 
  167. * @created: 9/10/12 
  168. */ 
  169.  
  170. function create_new_field_keys( &$field ) 
  171. // update key 
  172. $field['key'] = 'field_' . uniqid(); 
  173.  
  174.  
  175. if( isset($field['sub_fields']) && is_array($field['sub_fields']) ) 
  176. foreach( $field['sub_fields'] as $f ) 
  177. $this->create_new_field_keys( $f ); 
  178. elseif( isset($field['layouts']) && is_array($field['layouts']) ) 
  179. foreach( $field['layouts'] as $layout ) 
  180. if( isset($layout['sub_fields']) && is_array($layout['sub_fields']) ) 
  181. foreach( $layout['sub_fields'] as $f ) 
  182. $this->create_new_field_keys( $f ); 
  183.  
  184.  
  185.  
  186.  
  187.  
  188. new acf_third_party(); 
  189.  
  190. ?> 
.