colin

Sep 232014
 

I found a small problem with the way I was generating the membership number, the solution I documented on this post works BUT if a member registers but then fails to activate their membership before another person registers they both have the same membership number and user name. WordPress, rightly, does not allow two members to have the same user name.

I therefore created a custom table in the WordPress database called membership. It has two fields ID and member, ID is set to 1 and the member field is set to one less than whatever you want the starting membership number to be. The code in functions.php therefore needs to be changed to read and write the membership number to the custom table. Rather than use a custom table I could have used the options table but I thought it better to have the custom table so that it is easier to edit with phpmyadmin if necessary. The code now looks like:

add_action('gform_pre_validation', 'pre_validation_handler');
function pre_validation_handler($form){
	if ( 2 == $form['id'] ) {
		global $wpdb;
        $myrows = $wpdb->get_row("SELECT * FROM membership WHERE ID = 1" );
        $member = $myrows->member;
        $member ++;
        $wpdb->update('membership',array('member' => $member),array('ID'=> 1));
        $_POST["input_5"] = $member;
		}
// have to return the form either way
	return $form;
}

This now works correctly but it does mean there may be gaps in membership numbers should members who register not activate their accounts.

 Posted by at 5:59 pm
Sep 192014
 

I have a requirement to build a WordPress sites for an organisation that wants to charge members to belong to the organisation. I looked at the membership plugins that are available currently and they are all geared to making members pay for access to content rather than for the simpler needs of a club or organisation that wants some of their website pages available to non-members and the remainder of the site only available to members. As a result of nothing being available off the shelf as a plugin I decided to build my own functionality to deliver what this organisation wants.

I have built this functionality using three plugins and a small amount of custom code in functions.php. The plugins that I used are Gravity Forms from Rocketgenius an addon for Gravity Forms User Registration and this is also available from Rocketgenius as part of their developer licencing and finally Extra User Details from Vadym Khukhrianskyi which is available in the WordPress repository. I used this plugin as it writes the additional user data to the WordPress usermeta table rather than a bespoke table as other plugins of this type do. This, in my opinion, makes for easier integration with WordPress and easier data retrieval.

The requirement I had was to create a membership number for each new user and to assign that as the WordPress username (which cannot be changed by the user through the WordPress interface). I achieved this by looking at the last user registration ID in the users table and adding 1001 to it as I needed to have 4 digit membership numbers. The username is a required field by WordPress for user registration and so needs to be populated onto the Gravity Form before it is submitted. It is therefore necessary to use the gform_ pre_validation hook in Gravity forms. The id for my form is 2 and so this is the code I added to my child themes functions.php

//Assign membership number to user
add_action('gform_pre_validation', 'pre_validation_handler');
function pre_validation_handler($form){
	if ( 2 == $form['id'] ) {
		global $wpdb;
		$result = $wpdb->get_results("SELECT ID FROM $wpdb->users ORDER BY ID DESC LIMIT 1");
		$mem_no = $result[0]->ID;
		$new_mem = 1001 + $mem_no;
		$_POST["input_5"] = $new_mem;
		}
// have to return the form either way
	return $form;
}

*********** I have now changed this code due to an unforeseen problem. Please read this post too. ***********

The hidden field on the form is field 5

This is my Gravity form

mem4
The additional fields that I required were the users postal address. I therefore created the additional fields in the Extra User Fields plugin as below:

mem2

I finally mapped those additional fields to the fields in the Gravity Form as below:mem1
You will see that I have also mapped the Biography field from the Gravity Form to the standard WordPress Biography field.

Finally below you will see how the new fields are displayed at the bottom of the User Profile page:

mem3
The final part of the equation is to sort out the PayPal payment for the users membership fee. I will be using another Gravity Forms addon PayPal Payments Pro to do this when the PayPal details are made available to me. If there is anything tricky with this functionality addition to my home grown membership functionality I will add it here.

 Posted by at 3:07 pm
Mar 252014
 
php

Hopefully when WordPress 3.9 is available next month with the new editor the stripping of formatting from uploaded content will be a thing of the past. Until then the way I have overcome the problem is with a small piece of additional code in functions.php.

//Retain formatting in posts
//move wpautop filter to AFTER shortcode is processed
remove_filter( 'the_content', 'wpautop' );
add_filter( 'the_content', 'wpautop' , 99);
add_filter( 'the_content', 'shortcode_unautop',100 );

Hopefully this will help someone else

 Posted by at 11:11 am
Mar 202014
 

Daniel LeFever 1838-1906I recently found out some more information about my 2x Great Grandfather Daniel Lefever (abt 1838 – 1906).  I found him in the 1851 and 1871 census’ at home in Bethnal Green but could not find him in the 1861 census. I eventually tracked him down as a sailor on-board HMS Queen berthed in Beyrout (sic) Syria. I knew that his wife Isabella McGowan was born in Ireland but could not find details of their marriage in England. I eventually traced the details of their marriage to Ireland in 1868 when Daniel was serving on-board HMS Trafalgar. I then started looking for more details about Daniel’s naval service. I tracked down a record of his service on the National Archives website.

The record was available as a digital download for £3.36. Great I thought, but what does it contain? There was no real clue see the search results, no indication of how many pages or further details so I decided to pay the money for the record by PayPal and promptly downloaded the PDF file. I opened it and to say I was disappointed is putting it mildly. It was 10 pages long. The first was the National archives cover, page 2 was his personal details, page 3 his service record which was blank, page 4 was a copy of page 2, page 5 his certificate of fitness to serve, page 6 blank, page 7 a copy of page 5, page 8 blank and finally pages 9 & 10 copies of page 3 a blank service record.

How someone can serve on the Royal Navy aboard at least three ships and not have any sort of service record I do not understand.

So for my £3.36 I got one page of useful information, his service number, his date of birth, his description, date of enlistment, period of service and his first ship. Not particularly good value for money in my opinion.

I emailed the National Archives to ask them to check the original record to ensure that I received everything I paid for and am still awaiting a response.

It would be nice if they could give some indication of what is in the document you are going to download or even thumbnails of the pages so that you can make an informed decision.

 Posted by at 10:09 am
Mar 142014
 
Family Historian

I use Family Historian V5 to record my research for both my personal genealogy and my one-name study. Family Historian is only available to run on a PC with XP or later operating systems, for me this was OK until I wanted to take my research with me as I use a MacBook Air as my laptop of choice for when I am away from my desktop.

To run Family Historian on my MacBook meant that I would have to use an emulator of some sort to allow it to run. There is a choice either to run Windows as a virtual operating system within the Mac environment using the free Virtual Box or similar. The disadvantage of this approach is that you must have a copy of Windows that you can run in the virtual machine. The other choice is to use an emulator that packages the Windows application to run under OSX. I chose this latter approach and used Crossover from Codeweavers to create a version of Family Historian that would run on my Mac.

The installation of Crossover on the MAC is straightforward and I won’t go into that here. The installation of Family Historian, however, requires a couple of tweaks to get it running properly and these are detailed here.

Installation

In Crossover create a new application ‘Bottle’ as usual.

To ensure that plug-ins work correctly a line needs to be added to the Family Historian bottle.

Open Crossover as usual in the Configure menu select Manage Bottles, select the Family Historian bottle, then in the dialog box that opens select Open C:drive. Finder will now open go up one level in finder and select the cxbottle.conf file and open it in a plain text editor. Scroll to the bottom of the file and you will find a section that starts after [EnvironmentVariables] at the bottom of this section add a new line:

“COMPUTERNAME”=”YOURNAME”

Replace YOURNAME with your computer name.

Ensure that the quotes are normal ones and NOT smart quotes.

Save the file.

Installation of Add-Ons for Family Historian

Before attempting to install any add-ons at all to Family Historian check the file associations in your browser. Ensure that the file extension .fh_lua is associated with Family Historian. All other associations should be fine but if you have any problems installing any downloaded add-ons check the file associations in your browser.

If you have any problems installing plug-ins as a web download just save the plug-in in your download folder. The in Family Historian go to Tools > Plug-ins > More > Import and browse to your download folder and import them.

If you have problems installing Fact Sets, Queries or Property Box Tabs then go to File > Import and select the appropriate file type there.

Plug-in known not to work

  • Backup and Restore Family Historian Settings – This plug-in cannot access the registry and therefore cannot save the Family Historian settings.

Non-functional Issues

  • The in-built Family Historian PDF printer does not work. If you need a PDF printer that does work with Family Historian running on the MAC then use the free PDFWriter application. This installs at the MAC OS level and is available as a printer within Family Historian.
  • Reports from the Publish menu do not display correctly on screen, they only show multimedia items and not the text. However, if you print to a printer or PDFWriter then both text and images are displayed.

Examples of Family Historian screens on the MAC.

In a later post I will cover how to get Ancestral Sources, a popular companion application for Family Historian, running on a MAC too.

 Posted by at 9:40 am
Mar 122014
 
Gravity

I am currently developing a WordPress website for a genealogical organisation. One of the things they wanted was for any website visitor to be able to complete a contact form and for the content of the form to go direct to their member and not to the WordPress Admin email address.

The first thing to do was to create the contact form in Gravity Forms. This was just a simple form requiring first and last names, email address and message text. To this form I added a hidden field to store the email address that the form should be submitted to. I also created a custom notification to go along with this form. I called the notification ‘Profile Contact’. It does not matter which of the ‘Send To’ options you choose in this notification.

The next thing was a bit more complicated and it caused me to have an email exchange with Chris and Richard at Gravity forms support to get this up and running.

The page that accesses this contact form is based on a customised page template. This is the relevant piece of code that calls the contact form

<div class="cs_detail">		
<div class="cs_detail_header">Contact Details:</div><!--/cs_detail_header-->
<div class="cs_detail_content">
For more information please contact: 
<?php
$_SESSION['member'] = $study_member;
$contact = $wpdb->get_row("SELECT * FROM members WHERE number = '$study_member'");
$details = $contact->title." ".$contact->firstname." ".$contact->surname;								
echo " <b>". $details."</b>  ";
?>
<button class="eModal-1">Send Email</button>
</div><!--/cs_detail_content-->
</div><!--/cs_detail-->

This code needs a little explanation, the session variable is used to pass the result of another query on another custom table over to the custom Gravity Forms function.  The button is provided by the Easy Modal plugin that I use to display the contact form as a modal window over the page.

Two functions need to be added to the Themes functions.php file.

The first one is:

/** Set the email to address on the contact form **/
add_filter('gform_notification', 'change_autoresponder_email', 10, 3);
function change_autoresponder_email( $notification, $form, $entry ) {

    // There is no concept of user notifications anymore, so 
    // we will need to target notifications based on other 
    // criteria, such as name
    if($notification["name"] == "Profile Contact"){

        // toType can be routing or email
        $notification['toType'] = "email"; 
        // change the "to" email address
        $notification['to'] = $entry["4"];

    }

    return $notification;
}

The code is copied straight from the Gravity Forms documentation here. I used the code in Example 2 and just changed the value of the $entry to 4 as this was the field number of the  hidden field. I also changed the $notification to reflect the name of my custom notification form. (Don’t forget to delete the default notification or you will still get emails to the WordPress Admin account too).

The code for the second custom function is

// will populate a field in your form which has a parameter name of 'email_to'
add_filter("gform_field_value_email_to", "populate_email_address");
function populate_email_address($value){
	global $wpdb;
	$study_member = $_SESSION['member'];
	$contact = $wpdb->get_row("SELECT * FROM members WHERE number = '$study_member'");
	$email = $contact->studyalias1."@mydomain.org";
	return $email;
}

There is some explanation of this code required. As I am connecting to the WordPress database to get the email address from a custom table the global $wpdb variable needs to be added to the code. The membership number variable ($study_member) is populated from the session variable and then used in the query. The email address is constructed and then passed back to the Gravity Form in the hidden field. To prove this you can put it in a visible field on the form for testing purposes.

This works exactly as required by my organisation and shows the versatility of Gravity Forms.

Other useful links relevant to this post

Easy Modal plug-in.

Gravity Forms plug-in.

Gravity Forms documentation on the entry object.

 Posted by at 5:08 pm
Mar 102014
 
php

Rather than adding the bloat of one of the php plug-ins to your WordPress site you can just add a small piece of code to your functions.php.

 /** Execute PHP code in a standard text widget **/
 add_filter('widget_text','execute_php',100);
function execute_php($html){
     if(strpos($html,"<"."?php")!==false){
          ob_start();
          eval("?".">".$html);
          $html=ob_get_contents();
          ob_end_clean();
     }
     return $html;
}

You should really create a child theme and put this code in there rather than in your theme’s functions.php as if you upgrade your theme you will lose the custom code.

 Posted by at 2:43 pm
Apr 042012
 

Photo from Glyn Dewis

Have you ever wanted to achieve the look above demonstrated in this photo by Glyn Dewis?

If so please read about his technique on his blog here.

 Posted by at 1:23 pm
Apr 032012
 

I have a camera mount that I bought cheaply of eBay some while ago for the mounting of a camera (still or video providing it has a standard tripod mount thread) on a motorbike or bicycle. It doesn’t have quite enough range of movement to suit my current motorcycle, a Honda Valkyrie, with all the other things that I have mounted on the handlebars.

Existing mount

Existing mount

I therefore went looking for a now one with more range of movement. I found one that had much more movement and looked very flexible as it would fit onto tubes of up to 40mm in diameter and so would be suitable for mounting on handlebars, risers or engine bars.

New mount

I mounted it onto the risers to get a lower view of the road ahead and it looked great, locked on easily and didn’t mark the chrome.

Video camera mounted right side

Video camera from rear

 

Unfortunately this mounting was not very successful as it was too flexible in one of the joints and it did not keep the camera still. The joint in question is shown in the photo below, there is no way to tighten this joint as it is spring loaded and the spring tension is too light to dampen any vibrations.

Joint highlighted

This is an example of the video shot with this mount (it is low quality on purpose) and it has had YouTubes’ image stabiliser setting applied.  I hope that it doesn’t make you feel too queasy watching it.

This is an example of a video shot with the old mount.

I have not singled out the eBay supplier of this new mount as I don’t think that it is fair as there are many suppliers on eBay offering this mount.  My advice would be not to buy this type of mount for a video camera if you want to mount it on a motorcycle. It may be suitable for mounting on a car or bicycle but I haven’t tested it.

 Posted by at 12:11 pm
Mar 012012
 

580EX-IIHere is a free video that I can recommend that you watch if you are interested in taking photographs using Canon Speedlites.

Syl Arena the author of the Speedliters Handbook recently ran a tutorial session at  B&H Photo‘s event space in New York. The event was videoed and B&H have made the entire 1 hour 43 minute presentation available to watch online for free.  You can watch it below.

 Posted by at 1:11 pm