Category Archives: Other

Three resources for custom metadata in WordPress

When developing WordPress for use as a CMS one approach I have used is to create a custom post type for each type of resource and custom metadata boxes for relevant properties of those types.  I’ve used that approach when exploring the possibility of using WordPress as a semantic web platform to edit schema.org metadata, when building course information pages for students and am doing so again in updating some work I did on WordPress as a lightweight repository.  Registering a custom post type is pretty straightforward, follow the example in the codex page, I found handling custom metadata boxes a little more difficult. Here are three resources that helped.

Doing it long hand

It’s a few years old, but I found Justin Tadlock’s Smashing Magazine article How To Create Custom Post Meta Boxes In WordPress really useful as a clear and informative tutorial. It was invaluable in understanding how metaboxes work. If I had only wanted one or two simple text custom metadata fields then coding them myself would be an option, but I found a couple of problems. Firstly, I was repeating the same code too many times. Secondly when I thought about wanting to store dates or urls or links to other posts, with suitable user interface elements and data validation, I could see the amount of code needed was only going to increase. So I looked to see whether any better programmers than I had created anything I could use.

Using a helper plugin

I found two plugins that promised to provide a framework to simplify the creation of metaboxes. These are not plugins that provide anything that the end user can see directly, rather they provide functions that can be used in theme an plugin development. They both reduce the work of creating a metabox down to creating an array with the properties you want the metabox to have. They both introduce a dependency on code I cannot maintain, which is something I am always cautious about in using third-party plugins, but it’s much more viable than the alternative of creating such code from scratch and maintaining it myself.

CMB2 is “a metabox, custom fields, and forms library for WordPress that will blow your mind.” It is free and open source, with development hosted on GitHub.  It seems quite mature (version 1.0 was in Nov 2013), with a large installation base and decent amount of current activity on github.

Meta Box is “a powerful, professional developer toolkit to create custom meta boxes and custom fields for WordPress.” It too is free and released under GPL2 licence, but there are paid-for extensions (also GPL2 licensed) and I don’t see any open source development (I may not have looked in the right place).  Meta box has been around for a couple of years, is regularly updated and has a very large user base. The paid-for extensions give me some hope that the developers have a sustainable business model, but a worry that maybe ‘free’ doesn’t include the one function that at sometime I will really need. Well, developers cannot live on magic beans so I wouldn’t mind paying.

In the end both plugins worked well, but Meta Box allows the creation of custom fields for a link from one post to another, which I didn’t see in CMB2. That’s what I need for a metadata field to say that the author of the book described in one post is a person described in another.

Cloning WordPress sites for development

I do just enough theme and plugin development on WordPress to need an alternative to using a live WordPress site for development and testing, but at the same time I want to be testing on site as similar to the live site as possible. So I set up clones of WordPress sites either on my local machine or a server for development and testing. (Normally I have clones on the localhost server of couple of machines I use for development and another clone on a web accessible testing or staging server for other people to look at.) I don’t do this very often, but each time I do it I spend as much time trying to remember what it is I need to do as it actually takes to do it. So here, as much as an aide-memoire for myself as anything, else I’ve gathered it all in one place. What I do is largely based on the Moving WordPress information in the codex, but there are a couple of things that doesn’t cover and a couple of things I find it easier to do differently.

Assuming that the pre-requisites for WordPress are in place (i.e. MySQL, webserver, PHP), there are three stages to creating a clone. A. copy the WordPress files to the development site; B. clone the database; C. fix the links between WordPress and the database for the new site. A and B are basically creating backup copies of your site, but you will want to make sure that whatever routine backups you use are up to date and ready to restore in case something goes wrong. Also, this assumes that you are notwant to clone just one site on a WordPress Multisite installation.

Copying the WordPress files

Simply copy all the files from the folder you have WordPress installed in, and all the sub-folders to where you want the new site to be. This will mean that all the themes, plugins and uploaded media will be the same on both sites. Depending on whether the development site is on the same server as the main site I do this either with file manager or by making a compressed archive and ftp. Make sure the web server can read the files on the dev site (and write to the relevant folders if that is how you upload media, plugins and themes).

Cloning the database

First I create a new, blank database on for the new site, either from the command line or using something like MySQL Database Wizard which my hosting provider has on CPanel. I create a new user with full access to that data base–the username and password for this user will be needed to configure WordPress with access to this database. If you have complete control of over the database name and user name then use the same name username and password as is in the wp-config.php file of the site you are cloning. Otherwise you can change these later.

Second, I use PHP MyAdmin to export the data base from the original site and import it to the one on which you are making a clone.

phpMyAdmin Export screen

Fix all the bits that break

All that remains is to reconnect the PHP files to the database and fix a few other things that break. This is where it get fiddly. Also, from now on be really careful about which site you are working on: they look the same and you really don’t want to set up your public site as a development server. Make all these changes on the new development site.

In wp-config.html (it’s in the top of the WordPress folder hierarchy) find the following lines and change the values to be those for your new development server and database.

define( 'WP_CONTENT_URL', 'http://example.org/blog' );
define( 'WP_CONTENT_DIR', 'path/to/wp-content' );

define('DB_NAME', 'databaseName');

/** MySQL database username */
define('DB_USER', 'databaseUserName');

/** MySQL database password */
define('DB_PASSWORD', 'password');

You might also need to change the value for DB_HOST

Then you need to change the options that WordPress stores in the database. Normally you do this through the WordPress admin interface, but this is not yet available on your new site. There are various ways you can do this, I change the url directly in the data base with PHPMyAdmin, either by direct editing as described in the codex page or from the command line as described here.

mysql -u root -p

USE databaseName
SELECT * FROM wp_options WHERE option_name = 'home';
UPDATE wp_options SET option_value="http://example.org/blog" WHERE option_name = "home";
SELECT * FROM wp_options WHERE option_name = 'siteurl';
UPDATE wp_options SET option_value="http://example.org/blog" WHERE option_name = "siteurl";

You should now have access to the new cloned site, though some things will still be misbehaving.

You will probably have the old site’s URL in various posts and GUIDs. I use the better search replace plugin to fix these.

iesiesIf you do any fancy redirects with .htaccess, make sure that these are written in such a way that works for the new URL.

If you are using Jetpack you will need to use it in safe mode if the development server is connected to the web or development mode if running on localhost. (This is a bit of a pain if you want to test Jetpack settings.)

On a development site you’ll probably want to add this to wp-config.php:

define('WP_DEBUG', true);

If you are running a development or testing server on a web accessible site you probably want to restrict who has access to it. I use the My private site plugin so that only site admins have access.

Keeping in sync

While it’s not entirely necessary that a development or testing site be kept completely in sync with the main one, it is worth keeping them close so that you don’t get unexpected issues on the main site. You can manually update the plugins and themes, and use the wordpress export / import plugins to transfer new content from the live site to the clone. Every now and again you might want to re-clone the site afresh. Something I find useful for development and testing of new plugins and themes is to have the plugin or theme directory that I am developing in set up as a git repository linked to github and keep files in sync with git push and git pull.

Anything else?

I think that is it. If I have forgotten anything or if you have tips on making any of this easier please leave a comment.

Why is there no LearningResource type in schema.org?

A couple of times in the last month or so the question of why isn’t there a LearningResource type in schema.org as a subtype of CreativeWork. In case it comes up again, here’s my answer.

We took a deliberate decision way back at the start of LRMI not to define a LearningResource as a subtype of CreativeWork. Essentially the problem comes when you try to define what is a Learning Resource. Everyone who has tried so far has come up with something like “a resource which is used in learning, education or training”. That doesn’t rule out anything. Whether a magazine like Germany’s Spiegel is a learning resource depends on whether you are a German speaker or an American studying German. In presentations I have compared this problem to that of defining “what is a seat”. You can get seats in all shapes and forms with many different characteristics: chairs, sofas, saddles, stools; so in the end you just have to say a seat is something you sit on. Rather than rehash the problem of deciding what is and isn’t a learning resource, we took the approach of providing a way by which people can describe the educational properties of any Creative Work.

We recognised that there are some “types” of resource that are specific for learning. You can sensibly talk about textbooks and instructional videos as being are qualitatively different to novels and the movies people watch in the cinema, without denying that novels and movies are useful in education. That’s why we have the learningResourceType property. You can think of this as describing the educational genre of the resource.

In practice there are two choices for searching for learning resources. You can search those sites that are curated collections of what someone has decided are educational resources. Or you can search for the educational properties you want. So in our attempt at creating a Google Custom Search Engine we looked for the AlignmentObject. Looking for the presence of a learningResourceType would be another way. The educationalUse property should likewise be a good indicator.

On the first day of Christmas

Prompted by

and with apologies:

On the first day of Christmas
My true love gave to me
A testable hypoth-e-sis

On the second day of Christmas
My truelove gave to me
Two sample means
And a testable hypothesis

On the third day of Christmas
My true love gave to me
Three peer reviews
Two sample means
And a testable hypothesis

On the fourth day of Christmas
My true love gave to me
Four scatter plots
Three peer reviews
Two sample means
And a testable hypothesis

On the fifth day of Christmas
My true love gave to me
FIIIVE SIGMAA RuuuuLE

(I always thought the carol went down hill from there)

Using Garmin eTrex Vista HCx with Ubuntu 14.04LTS & QLandkarte GT

garminI have a rather old Garmin GPS eTrex that I use for GPS on walking holidays and cycle rides. I use it with OpenCycleMap contour maps downloaded from talkytoaster. To plan routes and manage the routes, tracks and maps on Ubuntu I use QLandkarte GT.  This summer was the first time I used this combination on my new PC, and I found some of the config difficult because the info I could find (e.g. this from GPS babel) related to old versions of Ubuntu (not surprising, this garmin is from the Ubuntu Feisty era). What needs doing seems similar but how you do it has changed.

I edited /etc/modprobe.d/blacklist to stop Ubuntu loading the garmin_gps module.  I don’t know if this is necessary, but everything I want seems to work with it there. That file now looks like:

# stop garmin_gps serial from loading for USB garmin devices

blacklist garmin_gps

The to make sure that the Garmin is automounted r/w for all users when plugged in to a USB post I created /etc/udev/rules.d/51-garmin.rules , with the content

SUBSYSTEM=="usb", ATTR{idVendor}=="091e", MODE="0666", GROUP="plugdev"

I found the lsusb and the gpsbabel utility  useful in testing the connexion. With it installed and the etrex plugged in I now see

phil@shuttle$ lsusb
Bus 002 Device 002: ID 8087:8001 Intel Corp. 
[...]
Bus 003 Device 004: ID 091e:0003 Garmin International GPS (various models)

phil@shuttle$ gpsbabel -i garmin -f usb:-1
0 3834401962 694 eTrex Vista HCx Software Version 3.40

And then in QLandkarte I can go to setup | general and under the “device and xfer” select Garmin in the main drop-down and EtrexVistaHCx in the Device Type (other Device options left blank) and happily transfer routes and tracks between the PC and the GPS.

Screenshot from 2015-08-07 09:11:51

RIP Yahoo Directory

Last Friday Yahoo announced that it will retire its original service, the Yahoo directory, at the end of 2014.  Perhaps the only surprise was that the Yahoo directory is still running. I don’t suppose it will be missed by many, but I noticed it going because the first article I ever wrote on learning technology was  Finding Information on WWWwhich I wrote for the CTI-Physics newsletter in Jun 1995. It was prompted by my boss at the time, Dick Bacon, saying that he thought there were lots of really useful resources on the web, but it was really difficult to find them. I suggested three approaches: social, organised collections and search, which I think stands up reasonably well today, though we’ve kind of moved on from mailbase to twitter. Search at the time was in its infancy, Lycos being the search engine of choice (yes, not only was this before Google, it was before Alta Vista). I still work on that question “how do you find information on the web?” Through LRMI and schema.org we are helping search engine providers improve their products, and one of my favourite initiatives of the last few years, the Learning Registry, and specifically the kritikos project has seen the coming together search and social, allowing students to share what they find to be useful for their courses.

In Roman times

A play-list for Roman History from the In Our Time archives.

I’ve become a bit of an addict of In Our Time since I was alerted to the archives available as podcasts by a tweet from someone, I can’t remember who. In Our Time is a Radio 4 programme where Melvyn Bragg discusses some topic with three academics. Whoever it was who sent that tweet said something along the lines of it possibly being the basis of  a University syllabus, which gave me the idea of putting together a playlist for one of the topics I’m interested in: Roman History.

Taken from various sections of the In Our Time archive, the descriptions are edited excerpts of those found on the BBC In Our Time site. The links are more or less chronological in order of Roman history; on left are links to discussions that relate directly to the story of the Roman Empire, on the right are discussions which relate to neighbours of the Empire and ideas that influenced the story.

All except one of the programme* are available for download from the BBC site, I’ve cobbled together this rss file will set up a podcasts play list. (*I can’t find The Roman Empire’s Decline and Fall for download.)

Praecursores

Thermopylae
For the historian Herodotus, the Battle of Thermopylae (480BC) was the defining clash between East and West, and allowed Western values to rise above Eastern.

The Phoenicians
People from the Levant who established a trading network across the Mediterranean linking many settlements, including Carthage.

The Etruscan Civilisation
   
Emerging ca.800 BC the Etruscans thrived for the next eight hundred years, extracting and trading copper and developing a sophisticated culture. Eventually the Etruscan civilisation was absorbed into that of Rome.

Romulus and Remus
According to tradition, the twins were abandoned by their parents as babies, but were saved by a she-wolf who found and nursed them. Romulus killed his brother after a vicious quarrel, and went on to found a city, which was named after him.

Res publica, 500-50BC

The Roman Republic
The rise and eventual downfall of the Roman Republic which survived for 500 years.

Hannibal
The Carthaginian general who led an entire army, complete with elephants, across the Alps in order to attack the Roman Republic during the Second Punic War which unfolded between 218 and 202 BC.

Carthage’s Destruction
Carthage and its destruction by the Romans in the 2nd Century BC, was a pivotal moment in world history that left Rome as the supreme power in the Mediterranean.

Judas Maccabeus
Born in the second century BC, Judas led his followers, the Maccabees, in a rebellion against the Seleucid Empire, which was attempting to impose the Greek culture and religion on the Jews

Spartacus
Slave revolts in the 1st century BC, especially the Roman gladiator and rebel leader Spartacus.

Cleopatra
The last pharaoh to rule Egypt, Cleopatra was a woman of intelligence and charisma, later celebrated as a great beauty. She was lover of Julius Caesar and Mark Antony.

Imperium

The Augustan Age
A golden age of literature with Virgil’s Aeneid and Ovid’s Metamorphosis among its treasures. But they were forged amidst creeping tyranny and the demands of literary propaganda.

Greek and Roman Love Poetry
Greek and Roman love poetry, from the Greek poet Sappho and her erotic descriptions of romance on Lesbos, to the love-hate poems of the Roman writer Catullus.

Roman Satire
Much of Roman culture was a development of their rich inheritance from the Greeks. But satire was a form the Romans could claim to have invented.

Metamorphosis
Melvyn Bragg and guests discuss the Roman poet Ovid and explore the theme of metamorphosis from the transformation of Narcissus to the bug of Kafka’s story, and beyond.

The Aeneid
Virgil’s Aeneid was the great epic poem that formed a founding narrative of Rome, written in Augustus’ reign at the start of the Imperial era and has been called an apologia for Roman domination; it has also been called the greatest work of literature ever written.

Vitruvius and De Architectura
Written almost exactly two thousand years ago, Vitruvius’ work is a ten-volume treatise on engineering and architecture, the only surviving work on the subject from the ancient world.

St Paul
Paul’s impact on Christianity is vast. Crucially, Paul is responsible for changing Christianity from a Jewish reform movement into a separate and universal religion.

Pliny’s Natural History
Some time in the first century AD, the Roman scholar Pliny the Elder published his Naturalis Historia, or Natural History, an enormous reference work which attempted to bring together knowledge on every subject under the sun.

Pliny the Younger
A prominent lawyer in Rome in the first century AD, Pliny later became governor of the province of Bithynia, on the Black Sea coast of modern Turkey. Throughout his career he was a prolific letter-writer, sharing his thoughts with great contemporaries including the historian Tacitus, and asking the advice of the Emperor Trajan.

Tacitus and the Decadence of Rome
Roman historian Tacitus chronicled some of Rome’s most notorious emperors, including Nero and Caligula, and whose portrayal of Roman decadence influences the way we see Rome today.

The Celts
The Greek historians who studied and recorded the Celts’ way of life deemed them to be one of the four great Barbarian peoples of the world. Perched on the North Western fringe  were the British who shared many of the religious, artistic and social customs of their European neighbours. 

Roman Britain
One backwater of the Empire noted for its wretched climate, gloomy atmosphere and uncouth inhabitants.

The Druids
Active in Ireland, Britain and Gaul, the Druids were first written about by Roman authors including Julius Caesar and Pliny. They were suspected of leading resistance to the Romans, a fact which eventually led to their eradication from ancient Britain.

Boudica
In 60AD, Boudica led an army of tribesmen and sacked Camulodunum, modern day Colchester, before marching on London. She came close to driving the Roman Imperial power out of Britain before she was finally defeated.

Hadrian’s Wall
Built in about 122 AD by the Emperor Hadrian, its construction must have entailed huge cost and labour. However, the Romans abandoned it within twenty years, deciding to build the Antonine Wall further north instead. 

The Cult of Mithras
A mystery religion that existed in the Roman Empire from the 1st to the 4th centuries AD.

Ptolemy and Ancient Astronomy
In the 2nd Century AD Ptolemy proposed that the Earth was at the centre of the universe and explained all the observed motions of the Sun, Moon, planets and stars with a system of uniform circular motions which he referred to as ‘epicycles’.

Decline and Fall, Byzantium

The Roman Empire’s Decline and Fall
How far is the growth of Christianity implicated in the destruction of the great culture of Rome? How critical were the bawdy incursions of the Ostrogoths, the Visigoths and the Vandals to the fall of the Roman Empire?

Queen Zenobia
Born in around 240 AD, Zenobia was Empress of the Palmyrene Empire in the Middle East. A highly educated, intelligent and militarily accomplished leader, she led a rebellion against the Roman Empire and conquered Egypt before being finally defeated by the Emperor Aurelian.

The Sassanid Empire
Founded around 226 AD, in Persia, the Sassanian Empire lasted over 400 years as a grand imperial rival to Rome. This super-power traded goods from Constantinople to Beijing, handed regular defeats to the Roman army and only fell to the Islamic conquests of the 7th century.

The Trinity
The idea that God is a single entity, but one known in three distinct forms – Father, Son and Holy Spirit – has been a central belief for most Christians since the earliest years of the religion. The doctrine was often controversial in the early years of the Church, until clarified by the Council of Nicaea in the late 4th century.

The Nicene Creed
The Nicene Creed which established the Divinity of Christ, written to counter the 4th Century Arian heresy

The Pelagian Controversy
 In the late 4th century a British monk, Pelagius, travelled to Rome where he preached a Christian doctrine which many regarded as heretical: that mankind was not inherently depraved.

The Roman Empire’s Collapse in the 5th century
Melvyn Bragg and guests discuss the causes of the fall of the Roman Empire (in the West, that is, the story continues).

Byzantium
In 453 with the Barbarians at the gate, through the gate and sacking the city of Rome “the wide arch of the ranged empire” finally began to fall…Or did it? In AD 395 the Emperor Theodosius had divided the vast Roman Empire between his two sons.How did the East survive when the West fell, were they really Romans and why do we know so little about one of the most successful and long lived Empires ever to straddle the globe?

The Arab Conquests
In 632 the prophet Muhammad died and left behind the nascent religion of Islam among a few tribes in the Arabian Desert. Within 100 years Arab armies controlled territory from Northern Spain to Southern Iran and Islamic ideas had begun to profoundly refashion the societies they touched.

The Abbasid Caliphs
From the mid eighth to the tenth century the Abbasid Caliphs headed a Muslim empire that extended from Tunisia through Egypt, Syria, Arabia, and Persia to Uzbekistan and the frontiers of India.

Muslim Spain
In 711 a small army of North African Berbers invaded Spain and established an Iberian Islamic culture that would last for over 700 years

The Battle of Tours
In 732 a large Arab army invaded Gaul from northern Spain, and travelled as far north as Poitiers. There they were defeated by Charles Martel, whose Frankish and Burgundian forces repelled the invaders.

The Carolingian Renaissance
In 800 AD on Christmas Day in Rome, Pope Leo III proclaimed Charlemagne Emperor, the first of the Holy Roman Emperors. A Frankish King who held more territory in Western Europe than any man since the Roman Emperor, Charlemagne’s lands extended from the Atlantic to Vienna and from Northern Germany to Rome.

Third Crusade
When Saladin, Sultan of Egypt and Syria, seized Jerusalem back in 1187 Pope Gregory VIII issued a Papal Bull for restoring the Holy City to Christian Rule.

Constantinople Siege and Fall
When Sultan Mehmet the Second rode into the city of Constantinople on a white horse in 1453, it marked the end of a thousand years of the Byzantine Empire.

Post Hoc

Rome and European Civilization
Melvyn Bragg assesses the role Rome has played in European civilization. Rome has meant Republicanism, as well as Imperialism; it has stood for Pax Romana and also for the machinery of war, it is an eternally pagan city that still beats as the Catholic Heart of the Christian Church.