• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Store
    • Cart
    • Checkout
  • Blog
    • Basics [Free]
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Contact
  • Sign In
  • Show Search
Hide Search
Home » Filters » Add a separator line of text in the registration form (wpmem_register_form_rows version)

Add a separator line of text in the registration form (wpmem_register_form_rows version)

Chad Butler · Oct 27, 2014 ·

Before the wpmem_register_form_rows filter was added, the way to insert a separator line of text into the registration form was by using php’s str_replace function to search/replace text/HTML in the form with the wpmem_register_form filter. While that way still works, wpmem_register_form_rows allows you an alternate approach that is much more simple using the wpmem_array_insert() API function.  

This article is only available to WP-Members Support Subscribers. If you have an existing subscription, please login below. If you do not have a current support subscription, you can purchase a support subscription here.

Already a Member? Log In Here
   
Forgot password? Click here to reset

To gain full access to WP-Members premium content, a current support subscription is required. You can purchase an annual support subscription for as little as $59, which provides you with access to priority support, a customer support forum, access to code snippets, and more.

Why wait? Choose your subscription option here.

[
Why join?]

Filters, Tips and Tricks str_replace, tips, wpmem_array_insert, wpmem_register_form, wpmem_register_form_rows

Welcome to RocketGeek Interactive › Forums › Add a separator line of text in the registration form (wpmem_register_form_rows version)

Tagged: str_replace, tips, wpmem_array_insert, wpmem_register_form, wpmem_register_form_rows

  • This topic has 7 replies, 3 voices, and was last updated 3 years, 10 months ago by Chad Butler.
Viewing 4 reply threads
  • Author
    Posts
    • October 27, 2014 at 12:01 pm #6253
      Chad Butler
      Keymaster

      Before the wpmem_register_form_rows filter was added, the way to insert a separator line of text into the registration form was by using php’s str_rep
      [See the full post at: Add a separator line of text in the registration form (wpmem_register_form_rows version)]

    • February 5, 2015 at 3:48 pm #7129
      uematsusoft
      Participant

      Hello.

      I need to translate the registration/edit custom fields and I wonder if using the filter “wpmem_register_form_rows” is the best option. I’m using polylang for the site translation and I would only translate the custom fields (pll__ ou pll_e) so my client doesn’t need to use the .po files.

      On the same subject, what is the best way to translate the options on the plugin settings? For example, translating the dialogs in the “Dialogs” tab.

      Best regards,
      Domingos Freitas

      • February 5, 2015 at 4:42 pm #7130
        Chad Butler
        Keymaster

        Yes, that would be the filter I would start with. I’m guessing that if you are only concerned with the custom fields, you are probably also only concerned with the labels for the fields.

        If you take a look at the documentation for this filter, you can just filter the elements you need to. Note that the labels all contain the HTML markup as well as the label.

        Hope this helps get you started.

    • February 6, 2015 at 8:16 am #7137
      uematsusoft
      Participant

      Thank you for your response.

      You’re correct, I only want to translate custom fields since the original fields I can use the PO files. I prefixed the field name so I can filter by start string.

      Can you advice me about the best way to translate (polylang) the options on the plugin settings? For example, translating the dialogs in the “Dialogs” tab.
      I’m thinking on putting all translated content in the options form and then parse (regexp…) the value displaying only the part of the current lang. I think there is a filter for prepping the dialogs output.

      Best regards,
      Domingos

      • February 6, 2015 at 10:15 am #7139
        Chad Butler
        Keymaster

        Yes – there are filters for most (if not all) of the dialogs. Some of the older filters are a little more tricky because they receive a string of the HTML output together with the actual message. However, in most cases, I have been able to add filters that come before these that provide an array of all the parts (so that the message part can be edited directly).

        With the exception of the login failed message, I think every message goes through the wpmem_inc_regmessage() function in the wp-members-dialogs.php file. In this function there is a filter – wpmem_msg_dialog_arr – that receives an array of the message parts. This array includes two keys that you’ll want to use in your filter function.

        The first is “toggles”. This array key will tell you what message is being displayed (if it is one of the defaults). Note that the toggle is not a requirement because all messages come through this filter. So in the case of a custom error, the toggle may be “other”. But all of the default messages editable in the plugin’s settings are one of the toggle values.

        The other key is “msg”. This array key contains the dialog message as a string. This is what you will want to change for the return value.

        Similar to this is the login failed message, which only handles the failed login error message. There is a filter that contains all the message parts in an array. The filter is wpmem_login_failed_args and I have not documented it fully yet. But you can look at what the pieces are in the wpmem_inc_loginfailed() function in wp-members-dialogs.php. The two keys you’ll want to filter are “heading” and “message” which contain strings for the message.

        The sidebar failed login has its own filter and does not yet have one of these “array filters” – the message is a string of the HTML plus the message. But it is documented here.

        Hope this helps get you started. Let me know if you need more direction/clarification.

    • February 6, 2015 at 10:53 am #7143
      uematsusoft
      Participant

      Thank you.
      This answer will certainly help me.

      Best regards,
      Domingos

    • April 25, 2017 at 4:23 am #12875
      GIFTwebadmin
      Participant

      I am able to use this code to add one sub heading but I cannot seem to add multiple sub headings. I tried using different values for my_field_separator eg. my_field_separator2.
      This gave another sub heading but resulted in headings being scrambled if I tried any more than 2. I got very lost trying “else if” etc statements but again no success.
      Is there was a way to create multiple separators with this code snippet?

      • April 25, 2017 at 9:23 pm #12883
        Chad Butler
        Keymaster

        To answer the question “Is there was a way to create multiple separators with this code snippet?” – Yes. You can add additional blocks within the loop.

        I understand that can be complicated if you don’t know what you’re doing. But it was the best option when I wrote this article originally.

        Now, however, there’s a new API function in the plugin that actually makes this process easier. I will need to rewrite the article to take advantage of this.

        The API function wpmem_array_insert() allows you to insert an array element into an existing array either before or after a specific key. There’s no need to loop through the array and rebuild it, no need for complicated if/then statements in the loop.

        wpmem_array_insert() works like this: You give it the array you want to insert something into (in the case, $rows), the item you want to insert (which in this example is “$new_row”), and the array key in the original array that you want to insert the new item after.

        The example from the article using wpmem_array_insert() instead could be done like this:

        add_filter( 'wpmem_register_form_rows', 'my_field_separator_alternate', 10, 2 );
        function my_field_separator_alternate( $rows, $toggle ) {
        	
        	// put together an array for the heading/separator that 
        	// includes *all* of the possible keys so that you don't
        	// get errors. Any keys you don't use should be empty ('')
        	$new_rows['address_heading'] = array(
        		'order' => '',
        		'meta' => '',
        		'type' => '',
        		'value' => '',
        		'row_before' => '',
        		'label' => '<label class="text"></label>',
        		'field_before' => '<div class="div_text">',
        		'field' => '<h3>Please include your address information</h3>',
        		'field_after' => '</div>',
        		'row_after' => ''
        	); // end of address_heading row array
        	
        	// Insert new row into existing rows after "last_name"
        	$rows = wpmem_array_insert( $rows, $new_rows, 'last_name' );
        	
        	return $rows;
        }

        (Note I simplified a little farther by putting the heading directly in the array – in the previous example is was in a variable so it would be set apart to be a little more obvious. But if you do multiple headings, it’s probably easier to just put it directly in the ‘field’ key for simplification.)

        So here’s an example with an additional heading using this process. Basically, the things you need to change as you add additional elements are the array key (i.e. $new_row[‘address_heading’] and $new_row[‘my_other_heading’]), the heading you have in the ‘label’ key, and lastly, the key that you’ll insert the item into the $rows array after (in this example, ‘last_name’ and ‘some_other_key’).

        add_filter( 'wpmem_register_form_rows', 'my_field_separator_alternate', 10, 2 );
        function my_field_separator_alternate( $rows, $toggle ) {
        	
        	$new_row['address_heading'] = array(
        		'order' => '',
        		'meta' => '',
        		'type' => '',
        		'value' => '',
        		'row_before' => '',
        		'label' => '<label class="text"></label>',
        		'field_before' => '<div class="div_text">',
        		'field' => '<h3>Please include your address information</h3>',
        		'field_after' => '</div>',
        		'row_after' => ''
        	);
        	$rows = wpmem_array_insert( $rows, $new_row, 'last_name' );
        	
        	
        	$new_row['my_other_heading'] = array(
        		'order' => '',
        		'meta' => '',
        		'type' => '',
        		'value' => '',
        		'row_before' => '',
        		'label' => '<label class="text"></label>',
        		'field_before' => '<div class="div_text">',
        		'field' => '<h3>Please include the following information</h3>',
        		'field_after' => '</div>',
        		'row_after' => ''
        	);
        	$rows = wpmem_array_insert( $rows, $new_row, 'some_other_key' );	
        	
        	
        	return $rows;
        }
        

        Hope that makes sense and makes it easier for you.

  • Author
    Posts
Viewing 4 reply threads
  • You must be logged in to reply to this topic.
Log In

Ready to get started?

Join Today!

© 2021 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Refund Policy