Bugs in my Member List

My task was pretty straight forward. The client wanted a solution where they could create a list of members to display in a particular page. The spanner was they wanted to create multiple member lists that they could easily reorder.

At quick glance I could have just created them a solution that allows a new listing of members each time. But that would have been horrendous to manage in the wordpress backend, seeing that the would be duplicate of the same members per list.

My solution was to create a plugin. In the plugin I would create a list of all the members with their details, stored on a custom post type. A page in the backend that will list all the members and allow simple drag and drop ordering.
Depending on what the check, that would be added in the list after giving the list a name and creating it. Then from there another custom post type would be the one that lists all the shortcodes.

Sounded easy enough. The first challenge was having to use jQuery to get the list of members then find a way to send them off to PHP, so that wordpress could be used to create the particular item saved in the post type. I used sent a post request on the wordpress ajax call after getting the list of ID’s. It took me hours to establish that I needed to add a site url variable in my wp_localize_script function.


 wp_localize_script('admin-reorder', 'LISTOBJECT', array(
            'secureCode' => wp_create_nonce('members-secret'),
            'siteURL'  => bloginfo('url')
         ));

I made this mistake because I was not aware that it wasn’t finding the ajax.php directory. Once that was handled my ajax call worked like a charm and I was even ready to go live after testing things out on my staging site.


  var ajaxurl = LISTOBJECT.siteURL + "/wp-admin/admin-ajax.php";
            $.ajax({
                url: ajaxurl,
                type: 'POST',
                dataTye: 'json',
                data:{
                    action: 'save_mymembers',
                    list: lichecks.toString(),
                    name: name,
                    security: LISTOBJECT.secureCode
                },
                success: function (response){
                    if(true === response.success){
                        pgtitle.html('
Successfully saved your members list!
'); } else { pgtitle.html('
Something went wrong trying to save. Server orientated
'); } }, error: function (error){ pgtitle.html('
Something went wrong trying to save.
'); console.log(error); } });

To my suprise once I was live the member list shortcodes where not getting created. How could the same code that was working on my staging site, not work on the live site. After going through tunds of unnecessary if found out the following. The get_site_url functions retrieves the site url of any site but most of all it includes the appropriate ‘https’ or ‘http’ scheme. Which made the difference. The bloginfo(‘url’) that I was using using ws bringing me back an ‘http’ scheme and thats why it didn’t work.

And just like that my lady bug was working beautifully again.

To see the working functionality click through to Button