M_create_internal_URL_group

The Membership 2 M create internal URL group function.

Description

M_create_internal_URL_group( $rule, $post, $level_id ); 

Parameters (3)

0. $rule
The rule.
1. $post
The post.
2. $level_id
The level id.

Usage

  1. if ( !function_exists( 'M_create_internal_URL_group' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'membership-2/app_old/membershipincludes/classes/class.urlgroup.php'; 
  3.  
  4. // The rule. 
  5. $rule = null; 
  6.  
  7. // The post. 
  8. $post = null; 
  9.  
  10. // The level id. 
  11. $level_id = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = M_create_internal_URL_group($rule, $post, $level_id); 
  15.  

Defined (1)

The function is defined in the following location(s).

/app_old/membershipincludes/classes/class.urlgroup.php  
  1. function M_create_internal_URL_group( $rule, $post, $level_id ) { 
  2.  
  3. global $wpdb; 
  4.  
  5. switch( $rule ) { 
  6. case 'posts': $permalinks = array(); 
  7. foreach( $_POST[$rule] as $rule ) { 
  8. $thelink = get_permalink( $rule ); 
  9. $thelink = str_replace('http://', 'https?://', $thelink ); 
  10. $permalinks[] = untrailingslashit($thelink) . '(/.*)'; 
  11.  
  12. $sql = $wpdb->prepare( "SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0, 1", '_posts-' . $level_id ); 
  13. $id = $wpdb->get_var( $sql ); 
  14.  
  15. $data = array( "groupname" => '_posts-' . $level_id,  
  16. "groupurls" => implode("\n", $permalinks),  
  17. "isregexp" => 1,  
  18. "stripquerystring" => 1 
  19. ); 
  20.  
  21. if(!empty($id)) { 
  22. // exists so we're going to do an update 
  23. $wpdb->update( membership_db_prefix($wpdb, 'urlgroups'), $data, array( "id" => $id) ); 
  24. } else { 
  25. // doesn't exist so we're going to do an add. 
  26. $wpdb->insert( membership_db_prefix($wpdb, 'urlgroups'), $data ); 
  27.  
  28. break; 
  29.  
  30. case 'pages': $permalinks = array(); 
  31. foreach( $_POST[$rule] as $rule ) { 
  32. $thelink = get_permalink( $rule ); 
  33. $thelink = str_replace('http://', 'https?://', $thelink ); 
  34. $permalinks[] = untrailingslashit($thelink) . '(/.*)'; 
  35.  
  36. $sql = $wpdb->prepare( "SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0, 1", '_pages-' . $level_id ); 
  37. $id = $wpdb->get_var( $sql ); 
  38.  
  39. $data = array( "groupname" => '_pages-' . $level_id,  
  40. "groupurls" => implode("\n", $permalinks),  
  41. "isregexp" => 1,  
  42. "stripquerystring" => 1 
  43. ); 
  44.  
  45. if(!empty($id)) { 
  46. // exists so we're going to do an update 
  47. $wpdb->update( membership_db_prefix($wpdb, 'urlgroups'), $data, array( "id" => $id) ); 
  48. } else { 
  49. // doesn't exist so we're going to do an add. 
  50. $wpdb->insert( membership_db_prefix($wpdb, 'urlgroups'), $data ); 
  51.  
  52. break; 
  53.  
  54. case 'bppages': $permalinks = array(); 
  55. foreach( $_POST[$rule] as $rule ) { 
  56. $thelink = get_permalink( $rule ); 
  57. $thelink = str_replace('http://', 'https?://', $thelink ); 
  58. $permalinks[] = untrailingslashit($thelink) . '(/.*)'; 
  59.  
  60. $sql = $wpdb->prepare( "SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0, 1", '_bppages-' . $level_id); 
  61. $id = $wpdb->get_var( $sql ); 
  62.  
  63. $data = array( "groupname" => '_bppages-' . $level_id,  
  64. "groupurls" => implode("\n", $permalinks),  
  65. "isregexp" => 1,  
  66. "stripquerystring" => 1 
  67. ); 
  68.  
  69. if(!empty($id)) { 
  70. // exists so we're going to do an update 
  71. $wpdb->update( membership_db_prefix($wpdb, 'urlgroups'), $data, array( "id" => $id) ); 
  72. } else { 
  73. // doesn't exist so we're going to do an add. 
  74. $wpdb->insert( membership_db_prefix($wpdb, 'urlgroups'), $data ); 
  75.  
  76. break; 
  77.  
  78. case 'bpgroups': $permalinks = array(); 
  79. if(function_exists('bp_get_group_permalink')) { 
  80. foreach( $_POST[$rule] as $rule ) { 
  81. $group = new BP_Groups_Group( $rule ); 
  82. $thelink = bp_get_group_permalink( $group ); 
  83. $thelink = str_replace('http://', 'https?://', $thelink ); 
  84. $permalinks[] = untrailingslashit($thelink) . '(/.*)'; 
  85.  
  86.  
  87. $sql = $wpdb->prepare( "SELECT id FROM " . membership_db_prefix($wpdb, 'urlgroups') . " WHERE groupname = %s ORDER BY id DESC LIMIT 0, 1", '_bpgroups-' . $level_id); 
  88. $id = $wpdb->get_var( $sql ); 
  89.  
  90. $data = array( "groupname" => '_bpgroups-' . $level_id,  
  91. "groupurls" => implode("\n", $permalinks),  
  92. "isregexp" => 1,  
  93. "stripquerystring" => 1 
  94. ); 
  95.  
  96. if(!empty($id)) { 
  97. // exists so we're going to do an update 
  98. $wpdb->update( membership_db_prefix($wpdb, 'urlgroups'), $data, array( "id" => $id) ); 
  99. } else { 
  100. // doesn't exist so we're going to do an add. 
  101. $wpdb->insert( membership_db_prefix($wpdb, 'urlgroups'), $data ); 
  102.  
  103. break; 
  104.  
  105.