Advertisement
imath

Migre post to bp docs

Dec 5th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.83 KB | None | 0 0
  1. <?php
  2.  
  3. function migre_post_to_bp_docs() {
  4.     global $wpdb;
  5.    
  6.     // le tag ayant pour nom tagA aura pour slug taga
  7.     // un petit tableau de corresp
  8.     $corresp['taga'] = array( 'tag_slug' => 'taga', 'group_id' => 3);
  9.    
  10.     /*si plusieurs du type
  11.     $corresp['tagb'] = array( 'tag_slug' => 'tagb', 'group_id' => 4);
  12.     ..
  13.     if faudra boucler sur le tableau corresp pour lancer ce qui suit :
  14.     */
  15.    
  16.     $group_ids = $wpdb->get_col("SELECT id FROM {$wpdb->base_prefix}bp_groups");
  17.  
  18.     if( count( $group_ids ) >= 1) {
  19.         foreach( $group_ids as $group_id ){
  20.            
  21.             if( $group_id == $corresp['taga']['group_id'] ) {
  22.                
  23.                 // a-t-on des posts dans le tagA ?
  24.                 $args = array(
  25.                     'tax_query' => array(
  26.                         array(
  27.                             'taxonomy' => 'post_tag',
  28.                             'field' => 'slug',
  29.                             'terms' => $corresp['taga']['tag_slug']
  30.                         )
  31.                     )
  32.                 );
  33.                 $postslist = get_posts( $args );
  34.                
  35.                 // si on a des posts... on poursuit
  36.                 if( count( $postslist ) >= 1 ) {
  37.                    
  38.                     // bp doc activé sur le groupe
  39.                     $bpdoc_is_active = groups_get_groupmeta( $group_id, 'bp-docs');
  40.                    
  41.                     //si pas le cas on active
  42.                     if( empty( $bpdoc_is_active ) ) {
  43.                         $default_group_setting = array('group-enable' => "1", "can-create" => "member");
  44.                         groups_update_groupmeta( $group_id, 'bp-docs', $default_group_setting);
  45.                     }
  46.                    
  47.                     // créons la custom taxo de bp doc pour ce group avant de modifié le post type puis de l'assigner à cette taxo.
  48.                     if( $term_id = bp_docs_get_item_term_id( $group_id, 'group' ) ) {
  49.                        
  50.                         foreach( $postslist as $new_bp_doc ) {
  51.                             set_post_type( $new_bp_doc->ID, bp_docs_get_post_type_name() );
  52.                            
  53.                             wp_set_post_terms( $new_bp_doc->ID, array( $term_id ), bp_docs_get_associated_item_tax_name(), false);
  54.                            
  55.                         }
  56.                            
  57.                     }
  58.                
  59.                 }
  60.                
  61.             }
  62.            
  63.         }
  64.        
  65.     }
  66.    
  67. }
  68. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement