Advertisement
Guest User

profile-custom-content-type/views/fields/db-field.php

a guest
Feb 6th, 2014
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <?php
  2. class Profile_CCT_DB_Field {
  3. function init() {
  4. add_filter( 'profile_cct_dynamic_fields', array( __CLASS__, 'add_custom_fields' ) );
  5.  
  6. $profile = Profile_CCT::get_object();
  7.  
  8. foreach ( $profile->settings['clone_fields'] as $field_key => $field ):
  9. if ( ! is_numeric($field_key) ):
  10. add_action( 'profile_cct_shell_'.$field['type'], 'profile_cct_'.$field['field_clone'].'_shell', 10, 3 );
  11. else:
  12. //This removes old and invalid fields that are left over from previous versions of the plugin.
  13. unset($profile_cct->settings['clone_fields'][$field_key]);
  14. endif;
  15. endforeach;
  16.  
  17. foreach( $profile->settings['clone_fields'] as $field ):
  18. add_action( 'profile_cct_'.$field['type'].'_add_meta_box', array( __CLASS__, 'add_db_meta_box' ), 10, 4 );
  19. endforeach;
  20. }
  21.  
  22. /**
  23. * profile_cct_add_db_fields function.
  24. *
  25. * @access public
  26. * @param mixed $fields
  27. * @return void
  28. */
  29. function add_custom_fields( $fields ) {
  30. $profile_cct = Profile_CCT::get_object();
  31.  
  32. foreach ( $profile_cct->settings['clone_fields'] as $field_key => $field_data ):
  33. stripslashes_deep($field_data);
  34. if ( ! is_numeric($field_key) ):
  35. $fields[] = array(
  36. "type" => $field_data['type'],
  37. "label" => $field_data['label'],
  38. );
  39. else:
  40. //This removes old and invalid fields that are left over from previous versions of the plugin.
  41. // unset($profile_cct->settings['clone_fields'][$field_key]);
  42.  
  43. $fields[] = array( "type"=> $field_data['type'], "label"=> $field_data['label']);
  44.  
  45. endif;
  46. endforeach;
  47.  
  48. return $fields;
  49. }
  50.  
  51. /**
  52. * profile_cct_db_add_meta_box function.
  53. *
  54. * @access public
  55. * @param mixed $field
  56. * @param mixed $context
  57. * @param mixed $data
  58. * @param mixed $i
  59. * @return void
  60. */
  61. function add_db_meta_box( $field, $context, $data, $i ) {
  62. $profile = Profile_CCT::get_object();
  63.  
  64. if ( isset( $profile->settings['clone_fields'][$field['type']] ) ):
  65. $custom_field = $profile->settings['clone_fields'][$field['type']];
  66.  
  67. $id = $field['type']."-".$i.'-'.rand( 0, 999 );
  68. $type = $field['label'];
  69. $callback = 'profile_cct_'.$custom_field['field_clone'].'_shell';
  70. $post_type = 'profile_cct';
  71. $priority = 'core';
  72. $callback_args = array(
  73. 'options' => $field,
  74. 'data' => $data
  75. );
  76.  
  77. add_meta_box( $id, $type, $callback, $post_type, $context, $priority, $callback_args );
  78. endif;
  79. }
  80. }
  81.  
  82. if ( is_array( Profile_CCT::get_object()->settings['clone_fields'] ) ):
  83. Profile_CCT_DB_Field::init();
  84. endif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement