<?php // Add below this line to functions.php add_filter( 'wpmem_member_links', 'update_terms_agreement' ); function update_terms_agreement( $links ) { // Settings. $process_name = 'update_terms'; $button_text = 'Agree to Terms'; $success_msg = 'Thank you for updating your information.'; $error_msg = 'Sorry, the updated terms must be agreed to before continuing to use the site. If you do not agree to the new terms, please <a href="#">log out</a>.'; $meta_key = 'tos'; $meta_value = 'agree'; global $wp, $wpmem; /* * Handle form processing here so we can return a success * message on the links page or an error message on the * form page depending on result. */ $update_success = false; $form_validation = false; // Check if custom form was submitted, and if so, process update. if ( isset( $_POST[ $process_name . '_save' ] ) && 1 == $_POST[ $process_name . '_save' ] ) { // You'll need the current user ID. $user_id = get_current_user_id(); // ToS agreement is required. If not checked, the user will not be able to continue. if ( isset( $_POST[ $meta_key ] ) ) { $form_validation = ( $meta_value == $_POST[ $meta_key ] ) ? true : false; } if ( $form_validation ) { // Use update_user_meta( $user_id, $meta_key, $meta_value ) to save user meta update_user_meta( $user_id, $meta_key, $_POST[ $meta_key ] ); // Set $update_success to true for displaying success message. $update_success = true; } else { // We are in an error state. $update_success = 'error'; } } // If the page is the custom process page, build and display the form. if ( ( isset( $_REQUEST['a' ] ) && $process_name == $_REQUEST['a'] ) || 'error' == $update_success ) { // If form submission was not successful, add the error message. $error_msg = '<div class="wpmem_msg" align="center"><p>' . $error_msg . '</p></div>'; $form_before = ( 'error' == $update_success ) ? $error_msg : ''; // Build the form. $form_before.= '<div id="wpmem_reg">'; $form_before.= '<form name="form" method="post" action="' . $wpmem->user_pages['profile'] . '" id="" class="form">'; /* * Custom HTML for the form here. * * Custom HTML is built into the variable $form_custom. To build onto the $form custom variable, * each additional line should be $form_custom.= '<p>your additional html</p>'; (note the "." * between the variable name and the = in each additional line. This basically means "add this * to the what is already in the variable." */ $form_custom = '<p><strong>Our Terms of Service have changed.</strong><br />Please agree to the new terms to continue using the site.</p>'; $form_custom.= '<p><input type="checkbox" name="tos" value="agree" /> I agree</p>'. /* * End custom HTML. */ // Add a hidden input for us to check if the form is submitted so we can save the selection. $form_after = '<input type="hidden" name="' . $process_name . '_save" value="1" />'; // Add a form submit button. $form_after.= '<br /><input type="submit" name="submit" value="' . $button_text . '" class="buttons" />'; // Close the form tag. $form_after.= '</form></div>'; // Assemble components. $links = $form_before . $form_custom . $form_after; } else { // If update was successful, add the success message. if ( $update_success ) { $links = '<div class="wpmem_msg" align="center"><p>' . $success_msg . '</p></div>' . $links; } } return $links; }
Not sure what to do with this code?
You're not a "coder" and don't know what to do? Don't worry! Code Snippets are the basic building blocks of WordPress customization, and once you know the basics, they are simple to use.
Here are some free articles to get you started:
- Using Code Snippets from the Site
- Using a code snippets plugin
- The functions.php File
- Create a plugin file for custom functions
- Create a child theme
- Do not modify plugin files!
For "hands on" help, consider a plugin support subscription or the Pro Bundle.