├── languages ├── pmpro-network.mo ├── pmpro-network.po └── pmpro-network.pot ├── pages └── manage-sites.php ├── pmpro-network.php └── readme.txt /languages/pmpro-network.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/strangerstudios/pmpro-network/1a19226e7145d03123bb39eb023477d2de003e60/languages/pmpro-network.mo -------------------------------------------------------------------------------- /languages/pmpro-network.po: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Paid Memberships Pro 2 | # This file is distributed under the same license as the Paid Memberships Pro - Member Network Sites Add On plugin. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Paid Memberships Pro - Member Network Sites Add On 0.5.4\n" 6 | "Report-Msgid-Bugs-To: info@paidmembershipspro.com\n" 7 | "Last-Translator: Paid Memberships Pro \n" 8 | "Language-Team: Paid Memberships Pro \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2024-02-06T14:00:16+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.9.0\n" 15 | "X-Domain: pmpro-network\n" 16 | 17 | #. Plugin Name of the plugin 18 | msgid "Paid Memberships Pro - Member Network Sites Add On" 19 | msgstr "" 20 | 21 | #. Plugin URI of the plugin 22 | msgid "https://www.paidmembershipspro.com/add-ons/pmpro-network-multisite-membership/" 23 | msgstr "" 24 | 25 | #. Description of the plugin 26 | msgid "Create a network site for the member as part of membership to the main site." 27 | msgstr "" 28 | 29 | #. Author of the plugin 30 | msgid "Paid Memberships Pro" 31 | msgstr "" 32 | 33 | #. Author URI of the plugin 34 | msgid "https://www.paidmembershipspro.com" 35 | msgstr "" 36 | 37 | #: pages/manage-sites.php:42 38 | #: pages/manage-sites.php:47 39 | msgid "Error creating site." 40 | msgstr "" 41 | 42 | #: pages/manage-sites.php:45 43 | #: pages/manage-sites.php:50 44 | msgid "Your site has been created." 45 | msgstr "" 46 | 47 | #: pages/manage-sites.php:66 48 | #: pages/manage-sites.php:73 49 | #: pages/manage-sites.php:71 50 | #: pages/manage-sites.php:78 51 | msgid "You have used %s of %s site credits." 52 | msgstr "" 53 | 54 | #: pages/manage-sites.php:69 55 | #: pages/manage-sites.php:74 56 | msgid "%s of your sites have been deactivated." 57 | msgstr "" 58 | 59 | #: pages/manage-sites.php:83 60 | #: pages/manage-sites.php:88 61 | msgid "Add a Site" 62 | msgstr "" 63 | 64 | #: pages/manage-sites.php:87 65 | #: pmpro-network.php:155 66 | #: pmpro-network.php:156 67 | #: pages/manage-sites.php:92 68 | msgid "Site Name" 69 | msgstr "" 70 | 71 | #: pages/manage-sites.php:98 72 | #: pmpro-network.php:166 73 | #: pmpro-network.php:167 74 | #: pages/manage-sites.php:103 75 | msgid "Your address will be %s" 76 | msgstr "" 77 | 78 | #: pages/manage-sites.php:98 79 | #: pmpro-network.php:166 80 | #: pmpro-network.php:167 81 | #: pages/manage-sites.php:103 82 | msgid "Your Site Name must be at least 4 characters (letters/numbers only). Once your site is created the site name cannot be changed." 83 | msgstr "" 84 | 85 | #: pages/manage-sites.php:103 86 | #: pmpro-network.php:171 87 | #: pmpro-network.php:172 88 | #: pages/manage-sites.php:108 89 | msgid "Site Title" 90 | msgstr "" 91 | 92 | #: pages/manage-sites.php:108 93 | #: pages/manage-sites.php:114 94 | msgid "Add Site" 95 | msgstr "" 96 | 97 | #: pages/manage-sites.php:120 98 | #: pages/manage-sites.php:126 99 | msgid "Your Sites" 100 | msgstr "" 101 | 102 | #: pages/manage-sites.php:139 103 | #: pages/manage-sites.php:145 104 | msgid "(deactivated)" 105 | msgstr "" 106 | 107 | #: pages/manage-sites.php:145 108 | #: pmpro-network.php:563 109 | #: pmpro-network.php:569 110 | #: pages/manage-sites.php:151 111 | msgid "Visit" 112 | msgstr "" 113 | 114 | #: pages/manage-sites.php:145 115 | #: pmpro-network.php:563 116 | #: pmpro-network.php:569 117 | #: pages/manage-sites.php:151 118 | msgid "Dashboard" 119 | msgstr "" 120 | 121 | #: pmpro-network.php:109 122 | #: pmpro-network.php:110 123 | msgid "Site Information" 124 | msgstr "" 125 | 126 | #: pmpro-network.php:110 127 | #: pmpro-network.php:111 128 | msgid "Sites Included: %s" 129 | msgstr "" 130 | 131 | #: pmpro-network.php:134 132 | #: pmpro-network.php:135 133 | msgid "You will be reclaiming your previous sites." 134 | msgstr "" 135 | 136 | #: pmpro-network.php:144 137 | #: pmpro-network.php:145 138 | msgid "You will be reclaiming your site %s." 139 | msgstr "" 140 | 141 | #: pmpro-network.php:172 142 | #: pmpro-network.php:173 143 | msgid "Required Field" 144 | msgstr "" 145 | 146 | #: pmpro-network.php:342 147 | #: pmpro-network.php:711 148 | #: pmpro-network.php:714 149 | #: pmpro-network.php:341 150 | #: pmpro-network.php:757 151 | #: pmpro-network.php:760 152 | msgid "Site Credits" 153 | msgstr "" 154 | 155 | #: pmpro-network.php:346 156 | #: pmpro-network.php:345 157 | msgid "Number of Sites" 158 | msgstr "" 159 | 160 | #: pmpro-network.php:350 161 | #: pmpro-network.php:349 162 | msgid "Set the number of sites members of this level will be allowed to create as part of membership. Numerical values only (no letters or special characters)." 163 | msgstr "" 164 | 165 | #: pmpro-network.php:562 166 | #: pmpro-network.php:568 167 | msgid "Your Primary Site" 168 | msgstr "" 169 | 170 | #: pmpro-network.php:691 171 | #: pmpro-network.php:737 172 | msgid "Below is a list of all sites you are an owner or member of." 173 | msgstr "" 174 | 175 | #: pmpro-network.php:724 176 | #: pmpro-network.php:770 177 | msgid "currently using %s" 178 | msgstr "" 179 | 180 | #: pmpro-network.php:766 181 | #: pmpro-network.php:812 182 | msgid "View Documentation" 183 | msgstr "" 184 | 185 | #: pmpro-network.php:766 186 | #: pmpro-network.php:812 187 | msgid "Docs" 188 | msgstr "" 189 | 190 | #: pmpro-network.php:767 191 | #: pmpro-network.php:813 192 | msgid "Visit Customer Support Forum" 193 | msgstr "" 194 | 195 | #: pmpro-network.php:767 196 | #: pmpro-network.php:813 197 | msgid "Support" 198 | msgstr "" 199 | 200 | #: pages/manage-sites.php:57 201 | msgid "Error creating site. Please try again" 202 | msgstr "" 203 | -------------------------------------------------------------------------------- /languages/pmpro-network.pot: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2024 Paid Memberships Pro 2 | # This file is distributed under the same license as the Paid Memberships Pro - Member Network Sites Add On plugin. 3 | msgid "" 4 | msgstr "" 5 | "Project-Id-Version: Paid Memberships Pro - Member Network Sites Add On 0.5.4\n" 6 | "Report-Msgid-Bugs-To: info@paidmembershipspro.com\n" 7 | "Last-Translator: Paid Memberships Pro \n" 8 | "Language-Team: Paid Memberships Pro \n" 9 | "MIME-Version: 1.0\n" 10 | "Content-Type: text/plain; charset=UTF-8\n" 11 | "Content-Transfer-Encoding: 8bit\n" 12 | "POT-Creation-Date: 2024-02-06T14:00:16+00:00\n" 13 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 14 | "X-Generator: WP-CLI 2.9.0\n" 15 | "X-Domain: pmpro-network\n" 16 | 17 | #. Plugin Name of the plugin 18 | msgid "Paid Memberships Pro - Member Network Sites Add On" 19 | msgstr "" 20 | 21 | #. Plugin URI of the plugin 22 | msgid "https://www.paidmembershipspro.com/add-ons/pmpro-network-multisite-membership/" 23 | msgstr "" 24 | 25 | #. Description of the plugin 26 | msgid "Create a network site for the member as part of membership to the main site." 27 | msgstr "" 28 | 29 | #. Author of the plugin 30 | msgid "Paid Memberships Pro" 31 | msgstr "" 32 | 33 | #. Author URI of the plugin 34 | msgid "https://www.paidmembershipspro.com" 35 | msgstr "" 36 | 37 | #: pages/manage-sites.php:47 38 | msgid "Error creating site." 39 | msgstr "" 40 | 41 | #: pages/manage-sites.php:50 42 | msgid "Your site has been created." 43 | msgstr "" 44 | 45 | #: pages/manage-sites.php:57 46 | msgid "Error creating site. Please try again" 47 | msgstr "" 48 | 49 | #: pages/manage-sites.php:71 50 | #: pages/manage-sites.php:78 51 | msgid "You have used %s of %s site credits." 52 | msgstr "" 53 | 54 | #: pages/manage-sites.php:74 55 | msgid "%s of your sites have been deactivated." 56 | msgstr "" 57 | 58 | #: pages/manage-sites.php:88 59 | msgid "Add a Site" 60 | msgstr "" 61 | 62 | #: pages/manage-sites.php:92 63 | #: pmpro-network.php:156 64 | msgid "Site Name" 65 | msgstr "" 66 | 67 | #: pages/manage-sites.php:103 68 | #: pmpro-network.php:167 69 | msgid "Your address will be %s" 70 | msgstr "" 71 | 72 | #: pages/manage-sites.php:103 73 | #: pmpro-network.php:167 74 | msgid "Your Site Name must be at least 4 characters (letters/numbers only). Once your site is created the site name cannot be changed." 75 | msgstr "" 76 | 77 | #: pages/manage-sites.php:108 78 | #: pmpro-network.php:172 79 | msgid "Site Title" 80 | msgstr "" 81 | 82 | #: pages/manage-sites.php:114 83 | msgid "Add Site" 84 | msgstr "" 85 | 86 | #: pages/manage-sites.php:126 87 | msgid "Your Sites" 88 | msgstr "" 89 | 90 | #: pages/manage-sites.php:145 91 | msgid "(deactivated)" 92 | msgstr "" 93 | 94 | #: pages/manage-sites.php:151 95 | #: pmpro-network.php:569 96 | msgid "Visit" 97 | msgstr "" 98 | 99 | #: pages/manage-sites.php:151 100 | #: pmpro-network.php:569 101 | msgid "Dashboard" 102 | msgstr "" 103 | 104 | #: pmpro-network.php:110 105 | msgid "Site Information" 106 | msgstr "" 107 | 108 | #: pmpro-network.php:111 109 | msgid "Sites Included: %s" 110 | msgstr "" 111 | 112 | #: pmpro-network.php:135 113 | msgid "You will be reclaiming your previous sites." 114 | msgstr "" 115 | 116 | #: pmpro-network.php:145 117 | msgid "You will be reclaiming your site %s." 118 | msgstr "" 119 | 120 | #: pmpro-network.php:173 121 | msgid "Required Field" 122 | msgstr "" 123 | 124 | #: pmpro-network.php:341 125 | #: pmpro-network.php:757 126 | #: pmpro-network.php:760 127 | msgid "Site Credits" 128 | msgstr "" 129 | 130 | #: pmpro-network.php:345 131 | msgid "Number of Sites" 132 | msgstr "" 133 | 134 | #: pmpro-network.php:349 135 | msgid "Set the number of sites members of this level will be allowed to create as part of membership. Numerical values only (no letters or special characters)." 136 | msgstr "" 137 | 138 | #: pmpro-network.php:568 139 | msgid "Your Primary Site" 140 | msgstr "" 141 | 142 | #: pmpro-network.php:737 143 | msgid "Below is a list of all sites you are an owner or member of." 144 | msgstr "" 145 | 146 | #: pmpro-network.php:770 147 | msgid "currently using %s" 148 | msgstr "" 149 | 150 | #: pmpro-network.php:812 151 | msgid "View Documentation" 152 | msgstr "" 153 | 154 | #: pmpro-network.php:812 155 | msgid "Docs" 156 | msgstr "" 157 | 158 | #: pmpro-network.php:813 159 | msgid "Visit Customer Support Forum" 160 | msgstr "" 161 | 162 | #: pmpro-network.php:813 163 | msgid "Support" 164 | msgstr "" 165 | -------------------------------------------------------------------------------- /pages/manage-sites.php: -------------------------------------------------------------------------------- 1 | post_content) && strpos($post->post_content, "[pmpron_manage_sites") !== false) { 9 | /* 10 | Preheader operations here. 11 | */ 12 | 13 | //make sure they have site credits 14 | global $current_user; 15 | $credits = $current_user->pmpron_site_credits; 16 | 17 | if(empty($credits)) { 18 | //redirect to levels 19 | wp_redirect(pmpro_url("levels")); 20 | exit; 21 | } 22 | } 23 | } 24 | } 25 | add_action("wp", "pmpron_manage_sites_preheader", 1); 26 | 27 | /* 28 | Shortcode Wrapper 29 | */ 30 | function pmpron_manage_sites_shortcode($atts, $content=null, $code="") { 31 | ob_start(); 32 | 33 | global $current_user, $pmpro_msg, $pmpro_msgt; 34 | 35 | // default values for site names. 36 | $sitename = ''; 37 | $sitetitle = ''; 38 | 39 | //adding a site, check the submission and nonce. 40 | if ( ! empty( $_POST['addsite'] ) && ( ! empty( $_POST['pmpron_add_site_nonce'] ) && wp_verify_nonce( $_POST['pmpron_add_site_nonce'], 'pmpron_add_site' ) ) ) { 41 | $sitename = sanitize_text_field( $_REQUEST['sitename'] ); 42 | $sitetitle = sanitize_text_field( $_REQUEST['sitetitle'] ); 43 | 44 | if ( pmpron_checkSiteName( $sitename, $sitetitle ) ) { 45 | $blog_id = pmpron_addSite( $sitename, $sitetitle ); 46 | if ( is_wp_error( $blog_id ) ) { 47 | $pmpro_msg = __( 'Error creating site.', 'pmpro-network' ); 48 | $pmpro_msgt = "pmpro_error"; 49 | } else { 50 | $pmpro_msg = __( 'Your site has been created.', 'pmpro-network' ); 51 | $pmpro_msgt = "pmpro_success"; 52 | } 53 | } 54 | 55 | } elseif ( ! empty ( $_POST['addsite'] ) ) { // Nonce is missing entirely during page submit or failed. Throw an error. 56 | 57 | $pmpro_msg = __( 'Error creating site. Please try again', 'pmpro-network' ); 58 | $pmpro_msgt = "pmpro_error"; 59 | } 60 | 61 | //show page 62 | $blog_ids = pmpron_getBlogsForUser($current_user->ID); 63 | 64 | // Show the error message if there is an error. 65 | if ( ! empty( $pmpro_msg ) ) { 66 | ?> 67 |
68 | 69 |
70 | = intval($current_user->pmpron_site_credits) ) { ?> 71 | pmpron_site_credits), intval($current_user->pmpron_site_credits) ) ); ?> 72 | 73 | intval($current_user->pmpron_site_credits)) { ?> 74 | pmpron_site_credits) ) ); ?> 75 | 76 | 77 | 78 | pmpron_site_credits) ) ); ?> 79 | 80 | 81 |
82 | 83 | pmpron_site_credits > count($blog_ids)) { ?> 84 |
85 |
86 |
87 |

88 | 89 |

90 |
91 |
92 | 93 | 94 | domain ); 97 | 98 | if ( !is_subdomain_install() ) 99 | $site = $current_site->domain . $current_site->path . __( 'sitename' ); 100 | else 101 | $site = __( '{site name}' ) . '.' . $site_domain . $current_site->path; 102 | 103 | echo '

' . esc_html( sprintf( __('Your address will be %s', 'pmpro-network' ), $site ) ) . '.
' . __( 'Your Site Name must be at least 4 characters (letters/numbers only). Once your site is created the site name cannot be changed.', 'pmpro-network' ) . '

'; 104 | 105 | ?> 106 |
107 |
108 | 109 | 110 |
111 |
112 | 113 | 114 | 115 | 116 |
117 |
118 |
119 |
120 |
121 | 122 | 123 | 124 |
125 |

126 | 127 |

128 |
    129 | 143 |
  • 144 | 145 | 146 | 147 | 148 |
    149 | 150 | 154 | 155 |
  • 156 | 157 |
158 | 159 | ID, $level_id); 29 | 30 | /* 31 | Backwards compatibility. If there are site credits for a level, but the option isn't saved, 32 | let's save this value (which is being set by the filter) in options. 33 | */ 34 | if(!empty($site_credits) && $option === null) { 35 | update_option( 'pmpron_site_credits_' . $level_id, $site_credits, 'no'); 36 | } 37 | 38 | return $site_credits; 39 | } 40 | 41 | 42 | /* 43 | * Include Manage Sites page template 44 | * Update $pmpro_network_non_site_levels array 45 | */ 46 | function pmpron_init() { 47 | //include manage sites page template 48 | if ( file_exists( get_stylesheet_directory() . '/paid-memberships-pro/pages/manage-sites.php' ) ) { 49 | $template = get_stylesheet_directory() . '/paid-memberships-pro/pages/manage-sites.php'; 50 | } elseif ( file_exists( get_template_directory() . '/paid-memberships-pro/pages/manage-sites.php' ) ) { 51 | $template = get_template_directory() . '/paid-memberships-pro/pages/manage-sites.php'; 52 | } else { 53 | $template = 'pages/manage-sites.php'; 54 | } 55 | require_once($template); 56 | 57 | //setup non site levels 58 | global $pmpro_network_non_site_levels; 59 | if(!is_array($pmpro_network_non_site_levels)) 60 | $pmpro_network_non_site_levels = array(); 61 | 62 | //filter for non site levels 63 | $pmpro_network_non_site_levels = apply_filters('pmpron_non_site_level_array', $pmpro_network_non_site_levels); 64 | } 65 | add_action('init', 'pmpron_init'); 66 | 67 | /* 68 | First we need to add some fields to the checkout page. 69 | */ 70 | //add the fields to the form 71 | function pmpron_pmpro_checkout_boxes() 72 | { 73 | global $current_user, $wpdb, $pmpro_network_non_site_levels; 74 | 75 | $level_id = null; 76 | 77 | // Get the level info 78 | $level = pmpro_getLevelAtCheckout(); 79 | if ( ! empty( $level->id ) ) { 80 | $level_id = intval( $level->id ); 81 | } 82 | 83 | // Return if requested level is in non site levels array 84 | if ( !empty($level_id) && !empty($pmpro_network_non_site_levels) && in_array( $level_id, $pmpro_network_non_site_levels ) ) 85 | return; 86 | 87 | // Return if site credits for this level is < 1 88 | $site_credits = pmpron_getSiteCredits($level_id); 89 | if(intval($site_credits) < 1) 90 | return; 91 | 92 | if(!empty($_REQUEST['sitename'])) 93 | { 94 | $sitename = $_REQUEST['sitename']; 95 | $sitetitle = $_REQUEST['sitetitle']; 96 | } 97 | elseif(!empty($_SESSION['sitename'])) 98 | { 99 | $sitename = $_SESSION['sitename']; 100 | $sitetitle = $_SESSION['sitetitle']; 101 | } 102 | else { 103 | $sitename = ''; 104 | $sitetitle = ''; 105 | } 106 | ?> 107 |
108 |
109 |

110 | 111 | %s', 'pmpro-network' ), pmpron_getSiteCredits($level_id), 'pmpro-network'); ?> 112 |

113 |
114 | ID) 117 | { 118 | $all_blog_ids = pmpron_getBlogsForUser($current_user->ID); 119 | $blog_id = get_user_meta($current_user->ID, "pmpron_blog_id", true); 120 | if(count($all_blog_ids) > 1) 121 | { 122 | $blogname = "many"; 123 | } 124 | elseif($blog_id) 125 | { 126 | $user_blog = $wpdb->get_row("SELECT * FROM $wpdb->blogs WHERE blog_id = '" . $blog_id . "' LIMIT 1"); 127 | $blogname = get_blog_option($blog_id, "blogname"); 128 | } 129 | } 130 | if(!empty($blogname)) { 131 | if($blogname == "many") 132 | { 133 | ?> 134 |
135 |

136 | 137 | 138 |
139 | 144 |
145 |

%s.', 'pmpro-network' ), $blogname ); ?>

146 | 147 | 148 |
149 | 155 |
156 | 157 | * 158 | domain ); 161 | 162 | if ( !is_subdomain_install() ) 163 | $site = $current_site->domain . $current_site->path . __( 'sitename' ); 164 | else 165 | $site = __( '{site name}' ) . '.' . $site_domain . $current_site->path; 166 | 167 | echo '

' . esc_html( sprintf( __( 'Your address will be %s', 'pmpro-network' ), $site ) ) . '.
' . __( 'Your Site Name must be at least 4 characters (letters/numbers only). Once your site is created the site name cannot be changed.', 'pmpro-network' ) . '

'; 168 | 169 | ?> 170 |
171 |
172 | 173 | * 174 | 175 |
176 | 179 |
180 |
181 | ERROR: Site reactivation failed.')); 234 | } 235 | } 236 | elseif( ! empty( $order->membership_id ) && ! in_array( $order->membership_id, $pmpro_network_non_site_levels ) && pmpron_getSiteCredits( $order->membership_id ) > 0 ) 237 | { 238 | $blog_id = pmpron_addSite($sitename, $sitetitle); 239 | if(is_wp_error($blog_id)) 240 | $r = $blog_id; 241 | } 242 | 243 | //clear session vars 244 | unset($_SESSION['sitename']); 245 | unset($_SESSION['sitetitle']); 246 | unset($_SESSION['blog_id']); 247 | 248 | return $r; 249 | } 250 | add_action( 'pmpro_after_checkout', 'pmpron_update_site_after_checkout', 10, 2 ); 251 | 252 | /* 253 | Set the "Manage Sites" page in Memberships > Page Setting 254 | */ 255 | function pmpron_extra_page_settings($pages) { 256 | $pages['manage_sites'] = array('title'=>'Manage Sites', 'content'=>'[pmpron_manage_sites]', 'hint'=>'Include the shortcode [pmpron_manage_sites].'); 257 | return $pages; 258 | } 259 | add_action('pmpro_extra_page_settings', 'pmpron_extra_page_settings'); 260 | 261 | /** 262 | * Get the post object for the "Manage Sites" page. 263 | * 264 | * @since 0.5.2 265 | * 266 | * @return null|WP_Post The WP_Post object for the manage sites post or null if not set/found. 267 | */ 268 | function pmpron_get_manage_sites_post() { 269 | global $pmpro_pages; 270 | 271 | // If the Manage Sites page is set in the global variable, return it. 272 | $manage_post = $pmpro_pages['manage_sites']; 273 | if ( ! empty( $manage_post ) ) { 274 | return get_post( $manage_post ); 275 | } 276 | 277 | // Check if the Manage Sites page is defined (this was an old way we offered before the UI). 278 | if ( defined( 'PMPRO_NETWORK_MANAGE_SITES_SLUG' ) ) { 279 | //check if the manage sites slug is defined. 280 | return get_page_by_path( PMPRO_NETWORK_MANAGE_SITES_SLUG ); 281 | } 282 | 283 | return null; 284 | } 285 | 286 | 287 | /* 288 | Add "Manage Sites" link to Member Links 289 | */ 290 | function pmpron_pmpro_member_links_top() { 291 | global $current_user; 292 | 293 | // Get the current user's number of site credits. 294 | $site_credits = $current_user->pmpron_site_credits; 295 | 296 | // Get the manage sites post object. 297 | $manage_post = pmpron_get_manage_sites_post(); 298 | 299 | // Don't show a link if the "Manage Sites" page is the "Membership Account" page. 300 | global $pmpro_pages; 301 | if ( $manage_post && ( $manage_post === $pmpro_pages['account'] || $manage_post->ID == $pmpro_pages['account'] ) ) { 302 | 303 | return; 304 | } 305 | 306 | // Show a link to manage sites if the member has credits and the page exists. 307 | if ( ! empty( $site_credits ) && ! empty( $manage_post ) ) { ?> 308 |
  • 309 | 310 | 0) { 331 | //want to specifically get the value from options here 332 | $pmpro_site_credits = get_option('pmpron_site_credits_' . $level_id, null); 333 | //check if there is something set via filter 334 | if($pmpro_site_credits === null) { 335 | $pmpro_site_credits = pmpron_getSiteCredits($level_id); 336 | } 337 | } else { 338 | $pmpro_site_credits = ''; 339 | } 340 | ?> 341 |

    342 | 343 | 344 | 345 | 346 | 351 | 352 | 353 |
    347 | 348 | 349 |

    350 |
    354 | domain ); 369 | 370 | if ( !is_subdomain_install() ) 371 | { 372 | $site = $current_site->domain; 373 | $path = $current_site->path . $sitename; 374 | } 375 | else 376 | { 377 | $site = $sitename . '.' . $site_domain; 378 | $path = $current_site->path; 379 | } 380 | 381 | //alright create the blog 382 | $meta = apply_filters('signup_create_blog_meta', array ('lang_id' => 'en', 'public' => 0)); 383 | $blog_id = wpmu_create_blog($site, $path, $sitetitle, $current_user->ID, $meta); 384 | 385 | do_action("pmpro_network_new_site", $blog_id, $current_user->ID); 386 | 387 | if ( is_a($blog_id, "WP_Error") ) { 388 | return new WP_Error('blogcreate_failed', __('ERROR: Site creation failed.')); 389 | } 390 | 391 | //save array of all blog ids 392 | $blog_ids = pmpron_getBlogsForUser($current_user->ID); 393 | if(!in_array($blog_id, $blog_ids)) 394 | { 395 | $blog_ids[] = $blog_id; 396 | update_user_meta($current_user->ID, "pmpron_blog_ids", $blog_ids); 397 | 398 | //if this is the first site, set it as the main site 399 | if(count($blog_ids) == 1) 400 | update_user_meta($current_user->ID, "pmpron_blog_id", $blog_id); 401 | } 402 | 403 | do_action('wpmu_activate_blog', $blog_id, $current_user->ID, $current_user->user_pass, $sitetitle, $meta); 404 | 405 | return $blog_id; 406 | } 407 | 408 | /* 409 | These bits are required for PayPal Express only. 410 | */ 411 | function pmpron_pmpro_paypalexpress_session_vars() 412 | { 413 | //save our added fields in session while the user goes off to PayPal 414 | $_SESSION['sitename'] = $_REQUEST['sitename']; 415 | $_SESSION['sitetitle'] = $_REQUEST['sitetitle']; 416 | $_SESSION['blog_id'] = $_REQUEST['blog_id']; 417 | } 418 | add_action("pmpro_paypalexpress_session_vars", "pmpron_pmpro_paypalexpress_session_vars"); 419 | 420 | //require the fields and check for dupes 421 | function pmpron_pmpro_registration_checks($pmpro_continue_registration) 422 | { 423 | global $pmpro_msg, $pmpro_msgt, $current_site, $current_user, $pmpro_network_non_site_levels, $pmpro_level; 424 | 425 | if ( !$pmpro_continue_registration ) 426 | return $pmpro_continue_registration; 427 | 428 | if(!empty($_REQUEST['sitename'])) 429 | $sitename = $_REQUEST['sitename']; 430 | else 431 | $sitename = ''; 432 | 433 | if(!empty($_REQUEST['sitetitle'])) 434 | $sitetitle = $_REQUEST['sitetitle']; 435 | else 436 | $sitetitle = ''; 437 | 438 | if(!empty($_REQUEST['blog_id'])) 439 | $blog_id = $_REQUEST['blog_id']; 440 | else 441 | $blog_id = ''; 442 | 443 | $site_credits = pmpron_getSiteCredits($pmpro_level->id); 444 | 445 | // Return if requested level is in non site levels array 446 | if ( ! empty( $pmpro_network_non_site_levels ) && in_array( $pmpro_level->id, $pmpro_network_non_site_levels ) ) { 447 | return $pmpro_continue_registration; 448 | } 449 | 450 | // Return if site credits for this level is < 1 451 | if( intval($site_credits) < 1 ) { 452 | return $pmpro_continue_registration; 453 | } 454 | 455 | if( !empty($sitename) && !empty($sitetitle) ) { 456 | if(pmpron_checkSiteName( $sitename, $sitetitle, $current_user ) ) { 457 | //all good 458 | return $pmpro_continue_registration; 459 | } else { 460 | //error set in checkSiteName 461 | return false; 462 | } 463 | } elseif( !empty($blog_id) ) { 464 | //check that the blog id matches the user meta 465 | pmpron_updateBlogsForUser($current_user->ID); 466 | $meta_blog_id = get_user_meta($current_user->ID, "pmpron_blog_id", true); 467 | if($meta_blog_id != $blog_id) 468 | { 469 | $pmpro_msg = "There was an error finding your old site. Make sure you are logged in. Contact the site owner for help signing up or reactivating your site."; 470 | $pmpro_msgt = "pmpro_error"; 471 | return false; 472 | } else { 473 | //all good 474 | return true; 475 | } 476 | } else { 477 | //error message shown below 478 | return false; 479 | } 480 | } 481 | add_filter( 'pmpro_registration_checks', 'pmpron_pmpro_registration_checks' ); 482 | 483 | /* 484 | Checks if a domain/site name is available. 485 | */ 486 | function pmpron_checkSiteName( $sitename, $sitetitle, $user = null ) 487 | { 488 | global $current_user; 489 | 490 | // assume Current User 491 | if ( empty( $user ) ) { 492 | $user = $current_user; 493 | } 494 | 495 | $result = wpmu_validate_blog_signup( $sitename, $sitetitle, $user ); 496 | $errors = $result['errors']->get_error_messages(); 497 | if( empty( $errors ) ) { 498 | return true; 499 | } else { 500 | $pmpro_msg = 'There were errors creating your site.'; 501 | $pmpro_msg .= '
      '; 502 | foreach($errors as $error) { 503 | $pmpro_msg .= '
    • ' . $error . '
    • '; 504 | } 505 | $pmpro_msg .= '
    '; 506 | 507 | pmpro_setMessage($pmpro_msg, 'pmpro_error'); 508 | 509 | return false; 510 | } 511 | } 512 | 513 | /* 514 | Shows how to change some of the blog settings on site creation. 515 | */ 516 | function pmpron_new_blogs_settings($blog_id) 517 | { 518 | global $wpdb; 519 | 520 | //change the default theme 521 | /* 522 | update_blog_option($blog_id, 'current_theme', 'Your Theme Name'); 523 | update_blog_option($blog_id, 'template', 'your-theme-directory'); 524 | update_blog_option($blog_id, 'stylesheet', 'your-theme-directory'); 525 | */ 526 | 527 | //change the subtitle "blogdescription" 528 | update_blog_option($blog_id, 'blogdescription', 'Change your subtitle'); 529 | 530 | //change the category 1 to "general" (pet peeve of mine) 531 | $sqlQuery = "UPDATE " . $wpdb->prefix . $blog_id . "_terms SET name = 'General', slug = 'general' WHERE term_id = 1 LIMIT 1"; 532 | $wpdb->query($sqlQuery); 533 | 534 | //make the blog public 535 | $sqlQuery = "UPDATE $wpdb->blogs SET public = 1 WHERE blog_id = '" . $blog_id . "' LIMIT 1"; 536 | $wpdb->query($sqlQuery); 537 | 538 | //add some other categories 539 | /* 540 | wls_add_category($blog_id, "Books", "books"); 541 | wls_add_category($blog_id, "Events", "events"); 542 | wls_add_category($blog_id, "Food", "food"); 543 | wls_add_category($blog_id, "News and Interest", "news"); 544 | */ 545 | } 546 | //actions 547 | add_action( 'wpmu_new_blog', 'pmpron_new_blogs_settings' ); 548 | 549 | /* 550 | Update the confirmation message to show links to the new site. 551 | */ 552 | function pmpron_pmpro_confirmation_message($message, $invoice) 553 | { 554 | global $current_user, $wpdb, $pmpro_pages; 555 | 556 | //where is the user's site? 557 | pmpron_updateBlogsForUser($current_user->ID); 558 | $blog_id = get_user_meta($current_user->ID, "pmpron_blog_id", true); 559 | 560 | // Get the manage sites post object. 561 | $manage_post = pmpron_get_manage_sites_post(); 562 | 563 | if($blog_id) 564 | { 565 | //get the site address 566 | $address = get_blogaddress_by_id( $blog_id ); 567 | $message .= '
    '; 568 | $message .= '

    ' . __('Your Primary Site', 'pmpro-network') . '

    '; 569 | $message .= '

    ' . $address . ' | ' . __('Visit', 'pmpro-network') . ' | ' . __('Dashboard', 'pmpro-network') . '

    '; 570 | if ( ! empty( $manage_post ) ) { 571 | $message .= '

    ' . esc_html( get_the_title( $manage_post ) ) . '

    '; 572 | } 573 | $message .= '
    '; 574 | } 575 | 576 | return $message; 577 | } 578 | add_filter( 'pmpro_confirmation_message', 'pmpron_pmpro_confirmation_message', 10, 2 ); 579 | 580 | /* 581 | * Set site credits, remove admin access and deactivate a blogs when a user's membership level changes. 582 | */ 583 | function pmpron_after_all_membership_level_changes( $old_user_levels ) { 584 | foreach ( $old_user_levels as $user_id => $level_arr ) { 585 | // Loop through all levels for this user and get the one with the most site credits. 586 | $site_credits = 0; 587 | $new_levels = pmpro_getMembershipLevelsForUser( $user_id ); 588 | foreach ( $new_levels as $level ) { 589 | $site_credits = max( $site_credits, pmpron_getSiteCredits($level->id) ); 590 | } 591 | 592 | update_user_meta( $user_id, 'pmpron_site_credits', $site_credits ); 593 | 594 | // Activate user's blogs based on number of site credits they have. 595 | $blog_ids = pmpron_getBlogsForUser( $user_id ); 596 | $n = 0; 597 | foreach( $blog_ids as $blog_id ) { 598 | $n++; 599 | 600 | if ( $site_credits >= $n ) { 601 | // As long as site_credits > $n, let's make sure this blog is active. 602 | update_blog_status( $blog_id, 'deleted', '0' ); 603 | do_action( 'activate_blog', $blog_id ); 604 | } else { 605 | // Otherwise, let's deactivate this blog as long as it's not an admin site. 606 | if ( ! user_can( 'manage_network', $user_id ) ) { 607 | do_action( 'deactivate_blog', $blog_id ); 608 | update_blog_status( $blog_id, 'deleted', '1' ); 609 | } 610 | } 611 | } 612 | } 613 | } 614 | add_action( 'pmpro_after_all_membership_level_changes', 'pmpron_after_all_membership_level_changes' ); 615 | 616 | /* 617 | Set site credits, remove admin access and deactivate a blogs when a user's membership level changes. 618 | 619 | @deprecated 0.5.3 620 | */ 621 | function pmpron_pmpro_after_change_membership_level($level_id, $user_id) 622 | { 623 | // Mark function as deprecated. 624 | _deprecated_function( __FUNCTION__, '0.5.3', 'pmpron_after_all_membership_level_changes' ); 625 | 626 | //set site credits 627 | if(!pmpro_hasMembershipLevel(NULL, $user_id)) { 628 | $site_credits = 0; 629 | } else { 630 | $site_credits = pmpron_getSiteCredits($level_id); 631 | } 632 | update_user_meta($user_id, 'pmpron_site_credits', $site_credits); 633 | 634 | //activate user's blogs based on number of site credits they have 635 | $blog_ids = pmpron_getBlogsForUser($user_id); 636 | $n = 0; 637 | foreach($blog_ids as $blog_id) 638 | { 639 | $n++; 640 | 641 | if($site_credits >= $n) 642 | { 643 | //as long as site_credits > $n, let's make sure this blog is active 644 | update_blog_status( $blog_id, 'deleted', '0' ); 645 | do_action( 'activate_blog', $blog_id ); 646 | } 647 | else 648 | { 649 | //don't deactivate admin sites 650 | if(!user_can("manage_network", $user_id)) 651 | { 652 | //site credits < $n, so let's deactivate blogs from now on 653 | do_action( 'deactivate_blog', $blog_id ); 654 | update_blog_status( $blog_id, 'deleted', '1' ); 655 | } 656 | } 657 | } 658 | } 659 | 660 | /* 661 | Get an array of blog ids for a user. 662 | */ 663 | function pmpron_getBlogsForUser($user_id) { 664 | 665 | pmpron_updateBlogsForUser($user_id); 666 | 667 | $user = get_userdata($user_id); 668 | $main_blog_id = $user->pmpron_blog_id; 669 | $all_blog_ids = $user->pmpron_blog_ids; 670 | 671 | if(!empty($all_blog_ids)) { 672 | return $all_blog_ids; 673 | } elseif(!empty($main_blog_id)) { 674 | return array($main_blog_id); 675 | } else { 676 | return array(); 677 | } 678 | } 679 | 680 | /* 681 | * Update a user's blogs. 682 | */ 683 | function pmpron_updateBlogsForUser($user_id) { 684 | 685 | $user = get_userdata($user_id); 686 | $main_blog_id = $user->pmpron_blog_id; 687 | $all_blog_ids = $user->pmpron_blog_ids; 688 | 689 | if(empty($main_blog_id) && empty($all_blog_ids)) { 690 | return; 691 | } 692 | 693 | if(!empty($all_blog_ids)) { 694 | 695 | // Make sure they exist 696 | foreach($all_blog_ids as $key => $blog_id) { 697 | if( ! get_blog_details($blog_id) ) { 698 | unset($all_blog_ids[$key]); 699 | } 700 | } 701 | 702 | // Update user blogs 703 | update_user_meta($user_id, 'pmpron_blog_ids', $all_blog_ids); 704 | } 705 | if(!empty($main_blog_id)) { 706 | if( ! get_blog_details($main_blog_id) ) { 707 | delete_user_meta($user_id, 'pmpron_blog_id'); 708 | } 709 | } 710 | } 711 | 712 | /* 713 | Add link to add new sites for users with multiple site credits 714 | */ 715 | function pmpron_myblogs_allblogs_options() 716 | { 717 | global $current_user, $pmpro_pages; 718 | 719 | //how many sites have they created? 720 | $all_blog_ids = pmpron_getBlogsForUser($current_user->ID); 721 | $num = count($all_blog_ids); 722 | 723 | //how many can they create? 724 | $site_credits = $current_user->pmpron_site_credits; 725 | 726 | // Get the manage sites post object. 727 | $manage_post = pmpron_get_manage_sites_post(); 728 | 729 | //In case they have sites but no site credit yet. Assume they have $num site credits. 730 | //This will give 1 site credit to users on sites upgrading pmpro-network from .1/.2 to .3. 731 | if(empty($site_credits) && !empty($num)) { 732 | $site_credits = $num; 733 | update_user_meta($current_user->ID, "pmpron_site_credits", $site_credits); 734 | } 735 | ?> 736 |
    737 |

    738 | 740 | 741 | 743 |

    744 | 757 |

    758 | 759 | 760 | 761 | 773 | 774 |
    762 | ID); 765 | $num = count($all_blog_ids); 766 | 767 | //how many can they create? 768 | $site_credits = $profile_user->pmpron_site_credits; 769 | ?> 770 | 771 | 772 |
    775 | ' . __( 'Docs', 'pmpro-network' ) . '', 813 | '' . __( 'Support', 'pmpro-network' ) . '', 814 | ); 815 | $links = array_merge($links, $new_links); 816 | } 817 | return $links; 818 | } 819 | add_filter( 'plugin_row_meta', 'pmpron_plugin_row_meta', 10, 2 ); 820 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | === Paid Memberships Pro - Member Network Sites Add On === 2 | Contributors: strangerstudios 3 | Tags: paid memberships pro, pmpro, multisite, network, network sites, wpmu 4 | Requires at least: 5.2 5 | Tested up to: 6.4 6 | Stable tag: 0.5.4 7 | 8 | Create a network site for the member as part of membership to the main site. 9 | 10 | == Description == 11 | 12 | Allow a member to purchase one or more sites as part of membership. Once configured, the member can purchase membership at the network’s main site (the primary domain of the network) and specify the "Site Name" and "Site Title" for their new site on the network. 13 | 14 | The site will be created for them after registering. Any sites attached to a member will be deactivated when membership expires or cancels. If they sign up for a membership again, the site will be reactivated. 15 | 16 | Full documentation is available at https://www.paidmembershipspro.com/add-ons/pmpro-network-multisite-membership/ 17 | 18 | == Installation == 19 | 20 | 1. Make sure you have the Paid Memberships Pro plugin installed and activated. 21 | 1. Make sure you have properly configured Network Sites on your WordPress Multisite. 22 | 1. Upload the 'pmpro-network' directory to the '/wp-content/plugins/' directory of your site. 23 | 1. Activate the plugin on the main site (the primary domaoin of the network) through the 'Plugins' menu in WordPress. 24 | 25 | == Defining the Membership Level "Site Credits" == 26 | You must create a page to allow members to manage their sites. This page can be generated on the Memberships > Page Settings page of the WordPress dashboard. The page should contain the shortcode [pmpron_manage_sites]. 27 | 28 | Or, you can define the constant PMPRO_NETWORK_MANAGE_SITES_SLUG in a plugin for PMPro Customizations on your main network site. This is the page that members will see to let them manage their sites on the network and create new sites based on the level’s allowance. 29 | 30 | Then, set the number of "site credits" given per level by editing the level on the main site under Memberships > Membership Levels > Edit Level. Users checking out for these levels will be able to create a subsite on the network for each site credit they have. 31 | 32 | You may also use the pmpron_site_credits filter (example below) to customize the number of sites allotted by level ID. The filter should be placed in your active theme’s functions.php file or a helper plugin for PMPro Customizations (our recommended method). 33 | 34 | ` 35 | //set site credits for levels 1-3 36 | function my_pmpron_site_credits( $credits, $user_id, $level_id ) { 37 | if($level_id == 1) { 38 | $credits = 1; 39 | } elseif($level_id == 2) { 40 | $credits = 3; 41 | } elseif($level_id == 3) { 42 | $credits = 9999; 43 | } 44 | return $credits; 45 | } 46 | add_filter( 'pmpron_site_credits', 'my_pmpron_site_credits', 10, 3 ); 47 | ` 48 | 49 | == Frequently Asked Questions == 50 | 51 | = I found a bug in the plugin. = 52 | 53 | Please post it in the GitHub issue tracker here: https://github.com/strangerstudios/pmpro-network/issues 54 | 55 | = I need help installing, configuring, or customizing the plugin. = 56 | 57 | Please visit our premium support site at https://www.paidmembershipspro.com for more documentation and our support forums. 58 | 59 | == Changelog == 60 | = 0.5.4 - 2024-02-06 = 61 | * SECURITY: Improved security to the frontend shortcode to create and manage sites. 62 | 63 | = 0.5.3 - 2023-10-16 = 64 | * ENHANCEMENT: Updating `

    ` tags to `

    ` tags for better accessibility. #28 (@dwanjuki) 65 | * BUG FIX/ENHANCEMENT: Improving compatibility with Multiple Memberships Per User. #26 (@dparker1005) 66 | * BUG FIX: Fixed checkout error when trying to add a site with the same slug as the purchaser’s username. #25 (@ideadude) 67 | * REFACTOR: No longer pulling the checkout level from the `$_REQUEST` variable. #27 (@dparker1005) 68 | 69 | = 0.5.2 - 2022-01-08 = 70 | * BUG FIX/ENHANCEMENT: Improved logic for generating the link to the "Manage Sites" page in Member Links section of account page. 71 | * ENHANCEMENT: Improved fields display on "Manage Sites" page to use no tables. 72 | * ENHANCEMENT: Make Add On translation ready. 73 | * ENHANCEMENT: Improved escaping and sanitization throughout code. 74 | * ENHANCEMENT: Added GitHub files for issue templates, README.md, and generate translations workflow. 75 | 76 | = .5.1 = 77 | * ENHANCEMENT: Improved fields display on membership checkout page to use no tables 78 | 79 | = .5 = 80 | * BUG FIX: Fixed issue with levels set with 0 site credits. 81 | * ENHANCEMENT: You can now set the number of site credits for a level by editing that level on the main site. These values will default to the value set via the pmpron_site_credits filter. You can remove your custom pmpron_site_credits filter code or continue to use the filter which will override the value set for the level. 82 | * ENHANCEMENT: Added pmpron_getSiteCredits($level_id) function to get the number of site credits for a given level. This will get the option for the level and also apply the pmpron_site_credits filter. 83 | * ENHANCEMENT: Improving readme documentation and updating add on name. 84 | 85 | = .4.2 = 86 | * BUG: Fixed some more warnings. 87 | 88 | = .4.1 = 89 | * BUG: Fixed some warnings during account creation. 90 | 91 | = .4 = 92 | * BUG/ENHANCEMENT: Fixed some issues where an old/deleted blog_id would still be associated with a user. 93 | * ENHANCEMENT: Added pmpron_non_site_level_array filter to setup that array vs using a global var. 94 | * ENHANCEMENT: If you use the pmpron_site_credits filter and the # of credits for a level is 0, then the level is treated as a non site level. 95 | 96 | = .3.3.1 = 97 | * BUG: Fixed some warnings. 98 | 99 | = .3.3 = 100 | * BUG: Fixed bug where we weren't checking $pmpro_network_non_site_levels global in pmpron_update_site_after_checkout. 101 | * BUG: Now making sure sites still exist before displaying them on the Manage Sites page. 102 | * FEATURE: Added ability to use custom templates for Manage Sites page. 103 | 104 | = .3.2.1 = 105 | * Fixed some warnings on the checkout page when not logged in. 106 | 107 | = .3.2 = 108 | * Added "site credits" field to profile for admins to override. 109 | 110 | = .3.1 = 111 | * Won't deactivate sites when changing levels on a network admin. 112 | * Checking for blog_ids before showing sites table on manage sites page. 113 | * Fixed pmpron_pmpro_after_change_membership_level to expect level_id instead of level object 114 | 115 | = .3 = 116 | * Added ability for users to register multiple sites on the network. Storing blog ids in pmpron_blog_ids user meta. The pmpron_blog_id (no s) meta value will still hold the first site created. Create a page with the [pmpron_manage_sites] shortcode on it to create the page to add new sites; use the pmpron_site_credits filter to change the number of site credits given to users signing up. 117 | * Abstracted some of the code around site creation. 118 | * Fixed a potential bug with the check to see if a sitename was already taken. 119 | 120 | = .2 = 121 | * Storing some vars in $_SESSION for when using PayPal Express or other offsite payment processors. 122 | * Fixed wp-admin link to new site dashboard on confirmation page. 123 | 124 | = .1 = 125 | * Initial version. 126 | --------------------------------------------------------------------------------