We're branching out this year, as well as Wordpress themes, we are now building custom plugins as well.
Although we've built a few plugins for customers sites, up until this point we haven't released anything into the Wordpress community, but all this is set to change with our first plugin.
Meantime, if you want to write Wordpress plugins, here's where you should start:
Creating Options Pages : Nearly all plugins will have some options. This page is also highly valuable if you want to add options to your themes.
Add a Widget : Your plugin may display data in a sidebar widget. Here's how!
Interact with the Database : Add your own tables to the Wordpress Database, or add/update/retrieve data that's already there.
Mostrando entradas con la etiqueta mySQL. Mostrar todas las entradas
Mostrando entradas con la etiqueta mySQL. Mostrar todas las entradas
martes, 12 de enero de 2010
martes, 17 de noviembre de 2009
List all blogs in a Wordpress MU installation
The African Travel Experts site has two dropdown lists of all the blogs on their WPMU installation sorted into two different categories. Here's how.
The way the site is set up is to have the African Travel Experts site as the main 'umbrella site' with sub-sites for each African country, which act as parent sites to sub-sites relating to the country. For example:
Master site: African Travel Experts
Country sub-site: South Africa
Child-site: Cape Town
Seeing as the standard WPMU installation doesn't provide for classifying blogs/sites in this way, a plugin and a bit of lateral thinking was required. I opted for the Blog Types plugin, which allows you to define your own categories for a blog. Once installed, I defined my categories in the config as follows:
// Blog types
// name and nicename are required
$blog_types = 'South Africa';
$blog_types = 'south_africa';
$blog_types = '';
$blog_types = 'no';
$blog_types = 'Botswana';
$blog_types = 'botswana';
$blog_types = '';
$blog_types = 'no';
//.... etc until all countries are defined
$blog_subtypes = 'Cape Town';
$blog_subtypes = 'cape_town';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
$blog_subtypes = 'Eastern Cape';
$blog_subtypes = 'eastern_cape';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
//.... etc until all areas are defined
// Allow users to select one or multiple blog types
// Note: If you allow users to select multiple blog types, they cannot select a subtype
$blog_types_selection = 'single'; //Options: 'single' or 'multiple'
// Allow users to select one or multiple blog subtypes
$blog_subtypes_selection = 'single'; //Options: 'single' or 'multiple'
// Branding singular
$blog_types_branding_singular = __('Country');
$blog_subtypes_branding_singular = __('Area');
// Branding plural
$blog_types_branding_plural = __('Countries');
$blog_subtypes_branding_plural = __('Areas');
// Display admin panel blog types page
$blog_types_display_admin_page = 'yes'; //Options: 'yes' or 'no'
// Display signup form blog types selection
$blog_types_display_signup_form = 'yes'; //Options: 'yes' or 'no'
// Enable subtypes
$blog_types_enable_subtypes = 'yes'; //Options: 'yes' or 'no'
The way the site is set up is to have the African Travel Experts site as the main 'umbrella site' with sub-sites for each African country, which act as parent sites to sub-sites relating to the country. For example:
Master site: African Travel Experts
Country sub-site: South Africa
Child-site: Cape Town
Seeing as the standard WPMU installation doesn't provide for classifying blogs/sites in this way, a plugin and a bit of lateral thinking was required. I opted for the Blog Types plugin, which allows you to define your own categories for a blog. Once installed, I defined my categories in the config as follows:
// Blog types
// name and nicename are required
$blog_types = 'South Africa';
$blog_types = 'south_africa';
$blog_types = '';
$blog_types = 'no';
$blog_types = 'Botswana';
$blog_types = 'botswana';
$blog_types = '';
$blog_types = 'no';
//.... etc until all countries are defined
$blog_subtypes = 'Cape Town';
$blog_subtypes = 'cape_town';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
$blog_subtypes = 'Eastern Cape';
$blog_subtypes = 'eastern_cape';
$blog_subtypes = 'south_africa';
$blog_subtypes = '';
//.... etc until all areas are defined
// Allow users to select one or multiple blog types
// Note: If you allow users to select multiple blog types, they cannot select a subtype
$blog_types_selection = 'single'; //Options: 'single' or 'multiple'
// Allow users to select one or multiple blog subtypes
$blog_subtypes_selection = 'single'; //Options: 'single' or 'multiple'
// Branding singular
$blog_types_branding_singular = __('Country');
$blog_subtypes_branding_singular = __('Area');
// Branding plural
$blog_types_branding_plural = __('Countries');
$blog_subtypes_branding_plural = __('Areas');
// Display admin panel blog types page
$blog_types_display_admin_page = 'yes'; //Options: 'yes' or 'no'
// Display signup form blog types selection
$blog_types_display_signup_form = 'yes'; //Options: 'yes' or 'no'
// Enable subtypes
$blog_types_enable_subtypes = 'yes'; //Options: 'yes' or 'no'
Etiquetas:
African Travel Experts,
Content Management System (CMS),
mySQL,
php,
Wordpress Multi User
lunes, 16 de noviembre de 2009
Auto-generating Community Builder profiles
For the AIRCO website, user profiles had to be auto-generated on admin approval, and a mail generated to the user.
The site was already running on a Joomla installation making use of the Community Builder suite, but some extra tweaking was needed to hook the site up to the member application backend.
The Process:
Potential member completes application form
Admin approves form
Profile is auto-generated and details are mailed to the member as follows:
1. Convert the member's name to a valid username (the member can always edit this if it isn't what they want)
$username = ereg_replace("", "", $name ); //convert to alphanumeric
$username = trim($username); // remove any unnecessary whitespace
$username = substr($username, 0, 24); //ensure the length of the username doesn't exceed 24 characters
2. Ensure that the email address used is unique (this is tested on initial registration, but we re-test to be safe)
$query = "SELECT * FROM jos_users WHERE email = '$email'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
if($check 0):
//flag as duplicate and exit
endif;
3. Check for duplicate username, and if one exists add a number on the end, retest and increment number until we get a unique value:
$n = 0;
$username_flag = '';
while($username_flag != 'set'):
$query = "SELECT * FROM jos_users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
$n++;
if($check 0):
$username = $username.$n;
else:
$username_flag = 'set';
endif;
endwhile;
4. Everything ok? Then we add the data:
a. Add
jos_users - name, username, email, password (remember to encrypt this with md5), usertype, gid, registerDate, params
jos_core_acl_aro - section_value = users, value = id of the record you inserted into jos_users, name = name of the member (as entered into jos_users)
jos_core_acl_groups_aro_map - group_id = id of the group your member belongs to, in my case 19 - Author, aro_id = id of the record you inserted into jos_core_acl_aro
jos_comprofiler id & user_id = id of the record you inserted into jos_users, then any other values captured for custom fields.
5. Finally email the member:
$to = $email;//captured from application form
$subject = "Your profile";
$body = "Dear ".$name."\n";
$body .= "You are now a full Member.\n\n";
$body .= "MEMBER'S AREA LOG-IN DETAILS\n";
$body .= "Username: ".$username."\n";
$body .= "Password: ".$password."\n\n";
$from = "FROM: ".$SENDERS_EMAIL_HERE;
mail($to, $subject, $body, $from);
The site was already running on a Joomla installation making use of the Community Builder suite, but some extra tweaking was needed to hook the site up to the member application backend.
The Process:
Potential member completes application form
Admin approves form
Profile is auto-generated and details are mailed to the member as follows:
1. Convert the member's name to a valid username (the member can always edit this if it isn't what they want)
$username = ereg_replace("", "", $name ); //convert to alphanumeric
$username = trim($username); // remove any unnecessary whitespace
$username = substr($username, 0, 24); //ensure the length of the username doesn't exceed 24 characters
2. Ensure that the email address used is unique (this is tested on initial registration, but we re-test to be safe)
$query = "SELECT * FROM jos_users WHERE email = '$email'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
if($check 0):
//flag as duplicate and exit
endif;
3. Check for duplicate username, and if one exists add a number on the end, retest and increment number until we get a unique value:
$n = 0;
$username_flag = '';
while($username_flag != 'set'):
$query = "SELECT * FROM jos_users WHERE username = '$username'";
$result = mysql_query($query) or die(mysql_error());
$check = mysql_num_rows($result);
$n++;
if($check 0):
$username = $username.$n;
else:
$username_flag = 'set';
endif;
endwhile;
4. Everything ok? Then we add the data:
a. Add
jos_users - name, username, email, password (remember to encrypt this with md5), usertype, gid, registerDate, params
jos_core_acl_aro - section_value = users, value = id of the record you inserted into jos_users, name = name of the member (as entered into jos_users)
jos_core_acl_groups_aro_map - group_id = id of the group your member belongs to, in my case 19 - Author, aro_id = id of the record you inserted into jos_core_acl_aro
jos_comprofiler id & user_id = id of the record you inserted into jos_users, then any other values captured for custom fields.
5. Finally email the member:
$to = $email;//captured from application form
$subject = "Your profile";
$body = "Dear ".$name."\n";
$body .= "You are now a full Member.\n\n";
$body .= "MEMBER'S AREA LOG-IN DETAILS\n";
$body .= "Username: ".$username."\n";
$body .= "Password: ".$password."\n\n";
$from = "FROM: ".$SENDERS_EMAIL_HERE;
mail($to, $subject, $body, $from);
Etiquetas:
Airco,
Content Management System (CMS),
joomla,
mySQL,
php
jueves, 12 de noviembre de 2009
Dynamic mp3 player
For the Elastic Artists website, a dynamic MP3 player was required that could be controlled and loaded from the backend.
I decided to go with a Flash based player and found a great tutorial for creating a flash MP3 player using XML. In order for the player layout to match the design called for by the client, a few tweaks were needed:
Original code:
_root._x = 5;
_root._y = 40 + (i*15);
_root.but_txt.text = songname;
if (i >= 3){
_root._x = 160
_root._y = -5 + (i*15);
}
My code:
_root._x = 0;
_root._y = 55+(i*30);
_root.but_txt.text.html = true;
_root.but_txt.htmlText = "Artist: "+songband+""+newline+"Track: "+songname;
The original produces two columns of 3 tracks side by side and just displays the song name. The amended code produces one list of tracks with font-color black (other font info was applied through flash) in the format:
Artist: artistname
Track: trackname
The amount of tracks returned will always be nine. This is controlled by the backend of the website.
Other than all the various original design elements, the only other change called for was for a playlist generated from a database table. While the tutorial makes use of a user-generated XML file, I used a php file that generates XML:
header("Content-type: text/xml");
$xml_output = '$xml_output .= '';
//connect and run query to return values for track title, artist and link to mp3 file
$title = $row;
$url = $row;
$artistName = $row;
$xml_output .= ' ';
$xml_output .= ' ';
echo $xml_output;
The client can then control the contents of the playlist via the site backend.
I decided to go with a Flash based player and found a great tutorial for creating a flash MP3 player using XML. In order for the player layout to match the design called for by the client, a few tweaks were needed:
Original code:
_root._x = 5;
_root._y = 40 + (i*15);
_root.but_txt.text = songname;
if (i >= 3){
_root._x = 160
_root._y = -5 + (i*15);
}
My code:
_root._x = 0;
_root._y = 55+(i*30);
_root.but_txt.text.html = true;
_root.but_txt.htmlText = "Artist: "+songband+""+newline+"Track: "+songname;
The original produces two columns of 3 tracks side by side and just displays the song name. The amended code produces one list of tracks with font-color black (other font info was applied through flash) in the format:
Artist: artistname
Track: trackname
The amount of tracks returned will always be nine. This is controlled by the backend of the website.
Other than all the various original design elements, the only other change called for was for a playlist generated from a database table. While the tutorial makes use of a user-generated XML file, I used a php file that generates XML:
header("Content-type: text/xml");
$xml_output = '$xml_output .= '
//connect and run query to return values for track title, artist and link to mp3 file
$title = $row;
$url = $row;
$artistName = $row;
$xml_output .= '
$xml_output .= '
echo $xml_output;
The client can then control the contents of the playlist via the site backend.
Suscribirse a:
Entradas (Atom)