Advertisement
faulty

Custom admin boxes example

Apr 11th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.09 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Test p2p
  4. */
  5. add_action('init', 'project_testp2p_init');
  6. add_action( 'add_meta_boxes', array('project_testp2p_editor', 'register_p2p_meta_box'));
  7. add_action( 'wp_loaded', 'project_testp2p_wp_loaded' );
  8. function project_testp2p_init()
  9. {
  10.     $labels = array(
  11.         'name' => _x('Sub Posts', 'post type general name'),
  12.         'singular_name' => _x('Sub Post', 'post type singular name'),
  13.         'add_new' => _x('Add New Sub Post', 'Event'),
  14.         'add_new_item' => __('Add New Sub Post'),
  15.         'edit_item' => __('Edit Sub Post'),
  16.         'new_item' => __('New Sub Post'),
  17.         'view_item' => __('View Sub Post'),
  18.         'search_items' => __('Search Sub Posts'),
  19.         'not_found' =>  __('No Sub Posts found'),
  20.         'not_found_in_trash' => __('No Sub Posts found in Trash'),
  21.         'parent_item_colon' => '',
  22.     );
  23.  
  24.     $supports = array('editor', 'revisions', 'comments', 'author', 'custom-fields', 'title');
  25.  
  26.     register_post_type( 'subpost',
  27.                         array('labels' => $labels,
  28.                              'public' => true,
  29.                              'show_in_menu' => true,
  30.                              'supports' => $supports,
  31.                              'hierarchical' => true
  32.                         ));
  33. }
  34. function project_testp2p_wp_loaded() {
  35.     // Make sure the Posts 2 Posts plugin is active.
  36.     if ( !function_exists( 'p2p_register_connection_type' ) )
  37.         return;
  38.  
  39.     p2p_register_connection_type(
  40.         array(
  41.             'name' => 'subpost_to_post',
  42.             'from' => 'subpost',
  43.             'to' => 'post',
  44.             'cardinality' => 'many-to-one',
  45.             'admin_box' => 'any',
  46.             'admin_column' => 'any',
  47.         )
  48.     );
  49. }
  50. class project_testp2p_editor {
  51.     static function register_p2p_meta_box() {
  52.         add_meta_box( 'project-ace-program-box', 'Link SubPost', array('project_testp2p_editor', 'render_post_meta_box'), 'post' );
  53.         add_meta_box( 'project-ace-program-tab-box', 'Link Post', array('project_testp2p_editor', 'render_program_subpost_meta_box'), 'subpost' );
  54.     }
  55.  
  56.     static function render_post_meta_box( $post ) {
  57.         p2p_list_posts( p2p_type('subpost_to_post')->get_connected( $post->ID ));
  58.     }
  59.  
  60.     static function render_program_subpost_meta_box( $post ) {
  61.         p2p_list_posts( p2p_type('subpost_to_post')->get_connected( $post->ID ) );
  62.     }
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement