pmpro_generatePages

Function to generate PMPro front end pages.

Description

(array) pmpro_generatePages( (array) $pages ); 

Returns (array)

$created_pages Created page IDs.

Parameters (1)

0. $pages (array)
Formatted as array($name => $title) or array(array('title'=>'The Title', content=>'The Content'))

Options

  • name (string) => ''

    Page name. (Letters, numbers, and underscores only.)

array(

    /**
     * Page name. (Letters, numbers, and underscores only.)
     *
     * @type string
     * @default ''
     */
    'name' => ''
);        


Usage

  1. if ( !function_exists( 'pmpro_generatePages' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // Formatted as array($name => $title) or array(array('title'=>'The Title', 'content'=>'The Content')) 
  5. $pages = array( 
  6. 'name' => '' 
  7. ); 
  8.  
  9. // NOTICE! Understand what this does before running. 
  10. $result = pmpro_generatePages($pages); 
  11.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_generatePages($pages) { 
  2.  
  3. global $pmpro_pages; 
  4.  
  5. $pages_created = array(); 
  6.  
  7. if(!empty($pages)) { 
  8. foreach($pages as $name => $page) { 
  9.  
  10. //does it already exist? 
  11. if(!empty($pmpro_pages[$name])) 
  12. continue; 
  13.  
  14. //no id set. create an array to store the page info 
  15. if(is_array($page)) { 
  16. $title = $page['title']; 
  17. $content = $page['content']; 
  18. } else { 
  19. $title = $page; 
  20. $content = '[pmpro_' . $name . ']'; 
  21.  
  22. $insert = array( 
  23. 'post_title' => $title,  
  24. 'post_status' => 'publish',  
  25. 'post_type' => 'page',  
  26. 'post_content' => $content,  
  27. 'comment_status' => 'closed',  
  28. 'ping_status' => 'closed' 
  29. ); 
  30.  
  31. //make non-account pages a subpage of account 
  32. if ($name != "account") { 
  33. $insert['post_parent'] = $pmpro_pages[account]; 
  34.  
  35. //create the page 
  36. $pmpro_pages[$name] = wp_insert_post($insert); 
  37.  
  38. //update the option too 
  39. pmpro_setOption($name . "_page_id", $pmpro_pages[$name]); 
  40. $pages_created[] = $pmpro_pages[$name]; 
  41.  
  42. return $pages_created;