Setting user-agent in curl or wget

$ wget --user-agent="User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0" -c

$ curl -A "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0" -O

Sketch of the Life of George Sparling of Senachwine Lake

I was born in county Limerick, Ireland, November 29, 1819, son of James and
Mary Atkins Sparling. Our forefathers in Ireland were called Palatines,
being Germans from the Palatinate on the Rhine. One hundred and ten families
of them who had started to seek homes in the new world were shipwrecked on
the coast of Ireland, in the reign of Queen Anne, who gave them homes at
Pallas, Court Mattress, and adjacent hamlets in County Limerick. The
Sparling family being carpenters, were awarded the job of making spinning
wheels for the government, who had them distributed to the poor people every
fall, who were unable to buy their own wheels to spin flax, with. Hundreds
of these wheels were made each year, and I worked in the same shop where my
father and grandfather and their fathers had worked for years. When I left
Ireland, Uncle William Sparling was still carrying on the business. But the
most notable fact, respecting this German colony is that they furnished the
first Methodist preacher to these United States, Philip Embery, who was
first cousin to Betty Song, a grandmother of mine. For particulars of these
people see History of Methodism, page 332. Father died when I was two years
old, and one sister six months old. He died from exposure while serving his
country as a soldier in the rebellion in Ireland of 1822-3. My mother had
three brothers in America, one living in upper Canada, 40 miles north of
Toronto, Robert Atkins; another living near Montreal, Lower Canada, Philip
Atkins; the other living in Clark County, Indiana, James Atkins.

Uncle Robert wrote several times requesting mother to come to America.
Finally in 1832, when I was twelve years old, we left Ireland in the Harey
of Newcastle, a ship of 700 tons burden, on the 4th day of April, with some
400 passengers. We reached our destination, it being Quebec. Nothing worthy
of note transpired during the passage, with the exception of being detained
some two or three days passing through large fields of floating ice. Saw
three icebergs which seemed to be 100 feet above the water, and some miles
in length. Arrived in Quebec about the middle of May. Found 24 ships with
their passengers yet on board at quarantine, having the cholera on board,
and were not allowed to land. Our vessel not having any sickness on board
was allowed to pass up to the city and land her passengers. The first night
after landing I was taken down with ship fever and became delirious, in
which state I remained for over a month, supposing I was still on board the
ship. I had to be taken to the hospital the next morning and remained there
nearly three months. During our passage we fared better than most of the
passengers, the captain being first cousin to mother, and he supplied us
with everything that we needed to make us comfortable during the trip.
Mother was allowed to visit me two days in the week. Owing to my sickness
she could not continue her journey, and that fearful scourge, the cholera,
increasing as the warm season advanced, she fell a victim to its ravages. I
knew nothing of the death when it happened. The officials gave the nurses
strict orders to say nothing about it until I got well. A short time after I
became conscious, I overheard the nurse conversing in Irish, they not
thinking that I understood the language, saying, “that the mother of the boy
yonder-naming my number -died some three weeks ago.” At this announcement I
made a great effort and jumped out of bed, and the stairs being close by I
started to go down, but not being able to walk, fell to the foot of the
stairs, which mishap caused me several days of severe suffering, caused in a
great degree by the terrible news of the death of my mother. After I got
over my shocks and was able to comprehend my situation, though only a boy, a
stranger in a strange land, with none to care for me, it seemed as if I
never could be reconciled, but mourning continually for my mother. She had
rented a room in the city, and when she died her effects were stolen, so my
sister says, with the exception of a few articles of clothing and five or
six English sovereigns, about $30.00. The beds and bedding were burned for
sanitary purposes, and the Church of England Bishop had my sister sent to
Uncle Philip, near Montreal. At the hospital where I was, no one was able to
tell me what had become of my sister. When I was able to walk, I was
permitted to go through the building and hospital yards, and the sights I
saw there that summer were terrible. The hospital was crowded with cholera
patients, and some days a corpse was taken to the dead house every ten
minutes. On the Plains of Abraham, near the city, were miles of tents
erected to accommodate the sick, and report says that some 35,000 were sick
with the disease in Quebec that season. We chose a fatal season for our
trip, after contemplating coming several years before. When able to get
about Dr. Marsden, the hospital physician took me home with him, and I
worked in his dispensary, when able, for about two months. I requested the
doctor several times to try and find out what had become of my sister, but,
he seemed to make no effort to discover her whereabouts, and said I had
better conclude to stay with him, and he would give me all the opportunity
necessary to make a good physician, but nothing short of finding my sister
and going to my people, would satisfy me.

I told my troubles to the stewardess of the hospital, who was interested in
my lonely condition during my stay in that institution and she told me I had
better see the Bishop of Quebec, as he had the care of all Protestant orphan
children entrusted to him. I did so and learned that he had sent my sister
to her uncle’s near Montreal, and if I wished to go to my friends he would
furnish me money and means to get there. I thanked him kindly for his
generous offer, and the next day I was on my way to Montreal with a letter
of introduction to the Bishop there, who kindly received me and had me sent
to my Uncle Philip. My sister, on seeing me coming into the house fainted,
thinking I was a spirit raised from the dead; they all thought I had died
three months before. After staying there a short time -my uncle having a
large family of his own could not keep us very well, he not being the
brother my mother had started to go to, he living in upper Canada and having
only two children -we were found homes, my sister with a family named Odell,
and I with Captain Williams. We had excellent homes and were well treated.
We lived with these people about two years when my uncle from Upper Canada
came after us. When he made his business known to the captain, he said he
could not take me away under any consideration; that he could do as well by
me as he could; that he liked me and could not get along very well without
me now, as he was an old man and his family had all set up for themselves,
and if my uncle had thought very much of us he would not have left us two
years without coming after us. My uncle told him that his sister had started
his place, and misfortune had overtaken her, and now he had come after us
and was going to take us home with him, and if he did not give me up
peaceably he should try the law for it. The captain told him to go ahead, as
that would be his only chance of getting me. The next morning I was sent to
the mill in Naperville, two or three miles from where we lived. On the road
I came up with both my uncles, and they got in and rode with me to town.
They said they were going to get counsel in regard to what course to pursue
to get me from Captain Williams. I told them that I was well treated and had
no desire to leave them. I drove to the mill and left the grist and boy, and
fed the horses under the shed. My uncles wanted I should go with them to the
attorney’s office, and on the road there they urged and finally persuaded me
to save trouble by starting for Upper Canada then and there. I did so, but
always regretted leaving such good people in that way. My uncle had made
satisfactory arrangements with the people my sister was living with to give
her up. We went and got her, and made tracks in a hurry, hiring a guide to
take us a short cut through the woods to a distant relative of my uncle’s,
where we stopped all night. By doing this all track of us was lost for we
were sure that search would be made for us, which we afterward learned from
uncle was the case. The next morning we started on foot and traveled 24
miles, and in the afternoon we hired a team to take us 24 miles more to a
stage station. Got there about ten o’clock that night, and the stage started
at 12 and took us 20 miles before daylight. We had to walk six miles more
before seven o’clock that morning to reach the steamboat landing on the St.
Lawrence River, as the boat left at that hour and would not leave again for
three days, and so we did some fast walking, but the boat left the landing
as we came in sight. Some men on the wharf seeing us running supposed we
wanted to get on board, and hailing her she came back, and we jumped aboard.
We felt very thankful, for we were almost exhausted, having traveled in the
past 24 hours: 24 miles on foot, 24 in a wagon without springs, 20 miles by
stage, and 6 more on foot, making the first day 74 miles. Once on the steam
boat, Blackhawk, we felt all right and safe from further pursuit. We stopped
at several landings on our way up the river, and had a lively race part of
the time with the steamer, Red Jacket. In the evening reached Kingston, got
on board the United Kingdom, and immediately started for Toronto, where we
arrived the next evening, making the trip of 500 miles in three days and
three nights, feeling that with the same facilities for traveling few could
beat it. Stayed in Toronto all night, and the next morning we started for
Bradford, 40 miles north of Toronto, where my uncle lived. We went in
company with a loaded team, the owner letting my sister ride part of the
way, he being paid for it. I had to foot it all the way, and I think it was
the hardest day’s work I ever did. Arrived at uncle’s and rested one day,
and the next day had to go to work. This was the beginning of the first hard
work that we ever had to do. At first it went rather hard and tough with us.
My sister as well as myself had to work out-of-doors all of the time, at
such work as threshing grain with horses, hauling wood, clearing land,
planting and plowing. The first three weeks I was there I helped the hired
men thresh with the flail. One morning uncle says “Boys, you have done well;
now I am going to give you a rest, get your axes.” And he showed us ten
acres of heavy timber he wanted chopped and cleared. That “rest” will never
be forgotten by me while I live. We had to chop in the cold all winter, and
in the spring cleared it up ready for seeding, and I had to work hard all
summer. That fall I told my uncle I thought I had worked enough to pay him
for what trouble and expense he had been to in bringing me from Lower
Canada, and wanted him to some place where I could learn the carpenter
trade. He objected to my leaving at first, but seeing I was determined, he
finally consented.

We made a contract with Joshua Harrison for me to work four years for him.
$40.00 a year for the first two years, and $80.00 a year for the last two. I
was 16 years old when I commenced with him. He was very kind, and we got
along nicely while I lived with him. Was with him two years, when the
rebellion of ’37 broke out in Canada, and he took part in it. Being defeated
he had to leave the country or suffer the penalty, which was death to some
and transportation to others. I stayed home that winter and cared for his
stock and worked at repairing and making sleds. In the spring he wrote me
from Niagara Falls to fetch the tools and come over there, as he had taken a
barn to build for General Whitney, proprietor of the Cataract and the Eagle
Hotel at that place. Left Canada on the 24th of April, 1838, and did not go
back again for 25 years. After completing the job for General Whitney, we
went to Tonawanda at the mouth of the Erie Canal, and built a house for Mr.
Sherman, brother to the Sherman of Chicago. After finishing the job we left
for the west, spending July 4th in Buffalo, and started up the lake the next
day on the steamer Wisconsin, with five other refugees. On the way up the
lake we stopped at Erie, Dunkirk, Cleveland and Sandusky. Run on a sand bar
in the Detroit River, which caused some funny mishaps. We were close to the
Canada shore, where some British soldiers were stationed and it made some of
the refugees feel rather scared -afraid the soldiers would come aboard and
take them prisoners; but a small steamer passing came to our assistance. She
took with her all the passengers that boarded her from our boat, some of
them being glad to get away, while others had left their families- husbands
parted from wives and parents from their children; but the next day came and
we were pulled off, soon after reaching Detroit, where we found our friends
all right. Captain MacIntosh, a refugee was at Detroit with his schooner,
his friends having brought her through the Welland Canal for him from
Toronto, with some sixty barrels of flour and pork on board. He proposed
that we get on board with him, and help him man his vessel, and he would
take us up the lakes, and board us and charge us nothing for the trip. Seven
of us accepted the proposition, and had a fine trip to Mackinaw, staying
there four days. The Indians, at that time were paid by the government at
that place, and it made lively times for the saloons. Getting the poor
Indians drunk and cheating them was the order of the day. From Mackinaw we
sailed up the lake, and a severe storm coming on, we tried to land at
Milwaukee, but could not, and laid too all night in the lake. Next morning
we made Grand River, Michigan, and there we parted company with Captain
MacIntosh, he going into the lumber barging trade. We stayed here a few
days, when all hands hired out to a Philadelphia company who were building a
new town some twelve miles south of this place, on Pigeon River. We worked
there two weeks when the fever and ague made its appearance, and twelve
workmen were laid up with it. We expected it would be our turn next, and we
wanted to get out of there, but the company’s foremen did not want to part
with us. We had to wait a few days before we got an opportunity to go but
finally a small vessel stopped at the mouth of the creek, and we made a
bargain with the captain to take us away from there. Next morning we were
landed in Chicago, the first time I had ever heard of the place. After
leaving the boat we went to the hotel to get breakfast, and learned that Mr.
Sherman was the proprietor, and that he was a brother to the Sherman we
built a house for in Tonawanda. My boss handed him the letter from his
brother, and he received us very kindly. Said times were dull and work
scarce, but he had a small job he would let us have-finishing the upper
rooms of his hotel-a small wooden house-at that time the Sherman of today
was not dreamed of. I worked there but a few days, when I left with one of
our men, and went to Widow Berry’s, 12 miles from Chicago, where I got $1.00
a day for harvesting. I stayed there until after harvest when I went back to
town. My boss having got through with his job concluded to go west as far as
Geneseo, Whiteside County, to see a friend, which took him four weeks.
During that time I hired to Ryan of the Vermont house to do some carpenter
work. While working for him he laid out forty acres in town lots not far
from where the courthouse now stands and he told me for every month’s work I
would do for him he would deed one of those lots to me. I told him I
couldn’t see it, as the lots were nothing but mud holes, for such was
Chicago at that time. When Mr. Harrison returned he said he liked the
country very well; why, he said, you can take your plow and turn over the
wild prairie so that it looks like weather boarding on a large scale. He
said he was bound to go back there as soon as he could go back to Canada and
get his family. He told me to take my tools and go to Dixon and stay there
until he returned, which would not be longer than three months. I gave him
all the money I had earned while he was gone, and he started for Canada the
next morning. I worked for Ryan a month longer in order to get money enough
to take me to Dixon In company with Dr. Bixkness we hired a man to take a
chest of tools for each of us to Dixon, we going on foot, the team being to
heavily loaded for us to ride. On the way I was taken with a severe attack
of bilious fever, and was obliged to ride part of the way until we got to
the end of the journey. I only recollect seeing four houses on our trip to
Dixon. One of these was on the banks of the fox river where Aurora now
stands, the team stopping here two days waiting for me to get able to walk.
I stopped one mile south of Dixon with a Mr. Talmage, who kept a sort of
hotel. The business of Dixon was done by the McHenry brothers in a double
log cabin, which answered for dwelling house and store. A small distillery
and ferry were the main attractions of the place at that time. Mr. Dixon
lived on the west side of the river, about one mile below town. In about a
month I recovered from my sickness, and shortly after the ague, that I fled
from Michigan to escape, over- took me, and hung on for six years before I
was able to get rid of it. About the middle of November I was able to work
some, and took a small job of carpentering for Mr. Talmage, being in debt to
him sixty dollars for board. A few weeks before that I overheard him and his
wife speaking about it, saying I could not get well, and that the only
chance for them to get their pay when I died was to take my tools and rifle,
worth at that time $150. I thought that was rather rough considering the
care I had received. When I had the fever and could not help myself I asked
for a drink in the forenoon and did not get it until 10 o’clock that night.
I give this as a specimen of how they treated me. Had it not been for Mr.
Sweeney and wife, neighbors, who nursed me, I think I would have died. When
I got his job done he was indebted to me $60, after paying my board bill,
and I could not refrain from saying to Mr. Talmage that I did not think it
would yet be necessary to dispose of my tools now in order to get their pay,
when the sixty dollars was on the other side. I took up a claim that winter
and did some work on it in the spring; when I left it and bought another in
East Grove, with some improvements. I built a log house, stable and
corn-crib, and raised ten acres of corn that year. When not employed on the
claim I worked for Mr. Talmage building some houses on the Illinois Central
railroad, that was in progress at that time, but soon afterward was
abandoned. In the fall of ’39 I contracted to build two houses for a Mr.
Denolf, agent for a Rhode Island company, who had bought a large tract of
land some five miles east of Dixon, and finished there that fall. In January
I came to Crow Meadow, Putnam County, to help John Harrison, younger brother
to my former master, Joshua Harrison, who, on going back to Canada, found
the Queen had issued a proclamation that all engaged in the rebellion could
return to their homes by complying with the rules expressed therein, and he
concluded to remain, and in a letter asked me to come back, but at that time
I was sick and without means. I never saw him again. Twenty-five years later
I made a visit to that country, but he had died some years before. John
Harrison bought the place I now live on from Josiah Hayes, and I helped him
build a log house on it that winter. In the spring I returned to East Grove
and worked on my claim, part of the time helping Squire Welty build his log
tavern at Inlet Grove. In the fall I sold my claim and came back to Putnam
County, and helped John Harrison with several jobs of carpenter work he had
contracted to do. I worked for him nearly all through the summer of “41.
That fall I helped build the Bradley store in Henry, the first frame house
in that place. Harrison did not have the money to pay me for my labor that
summer, about $200 and I took his place, the farm I now live on. Harrison
went to East Grove to settle some business, and was killed by James Bell,
with whom he had some difficulty.

Spent the summer of ’42 breaking prairie for R. Taliferro, S.C. Bacon,
Philip Reed and James Buchanan, and improving my own farm. On January 12,
1843, I married Adaline Morgan, born in Connecticut, daughter of Alanson and
Melinda Morgan, natives of that state. I commenced farming, living near
Senachwine Lake. It was one of the best fisheries in this part of the
country, and the demand for fish large, people coming twenty miles for them.
The only way catching them at the time was with a spear or hook and line,
but in the fall of ’43 a Mr. Goodrich, a missionary from the Sandwich
Islands, came here with a seine, and wanted to try fishing with it. On
November 3, we tried the net, and caught 2500 fish, averaging 10 pounds
each. Mr. Goodrich sold his seine to Mr. Hunt. I bought one of my own, and
Commenced the Senachwine Lake Fishery, buying the most valuable tracts for
fishing purposes, until I had purchased some 800 acres, and for 35 years, in
connection with farming, carried on the fishing business, the fishery
proving more profitable than farming. We sometimes caught as high as 150
barrels at a haul, and the demand was as great as the supply, one season
averaging 45 teams a day for three weeks. I sold one haul for $243, and for
ten years previous to the building of the Henry Dam our receipts were $3000
a year, but since then it has been utterly worthless caused by the raising
of the water, flooding our lands and destroying the banks of the lake.
Thinking I had a good thing in the fishery for all time to come, I refused
$100 per acre for a large tract of land and lake. Now it is worth nothing,
and seemingly there is no redress from the state. Such is fate, and at the
age of 56 I was compelled to commence life over again. April 13, 1857, my
wife died, at the age of 35, leaving eight children, the last, a pair of
twins eight months old, the others being George Edward, born November 1,
1842; James Alanson, born May 26, 1846; Mary Melinda, born February 22,
1848; Helen Elizabeth, born January 27, 1850; William Henry, born January
15, 1856; John Stanley, born December 10, 1853; the twins Adaline and Albert
were born August 15, 1856; Albert died August 25, 1857, aged one year; James
Alanson, died May 10, 1863, aged 16 years.

Married again August 8, 1858, to Sarah M. Clung, daughter of Harvey and
Sarah Bird McClung, her father a native of Ohio and her mother of Kentucky.
She died February 8, 1871, at the age of 35 years, leaving six children,
Martha Jane, born May 2, 1859; Sarah Evaline, born September 1, 1860; Kate
Bird, born January 3, 1862; Samuel Martell, born June 8, 1864; Frederick
Lincoln, born December 25, 1865; Embery Harrison, born September 27, 1867.

August 18, 1874, married Margaret McElroy, widow of James Sparling, my
cousin, she having four children by her first marriage; Charlotta, Violet,
Nettie, and Annie. The result of this union is two children, Susan Mabel
Atkins, born January 3, 1876; Homer Ldeis, born January 19, 1878. In 1844 a
two year old daughter of Lewis Thompson being deserted by its mother, I
adopted and raised her until she was 14 years old making in all twenty-one
children whom I have cared for, nine boys and twelve girls. Seven of the
girls are school teachers. With the exception of four dead and one living in
Iowa, they are all residents of Senachwine Township, Putnam County, with the
addition of ten grandchildren.

Install the current version of Go in Ubuntu

After running:

$ sudo apt-get install golang

I ended up with an older version of Go than I needed:

$ go version
go version go1

Wanting to use scanner from bufio, I needed Go 1.1. Fortunately, you can get the latest version from

Simply run the following:

$ sudo add-apt-repository ppa:duh/golang
$ sudo apt-get update
$ sudo apt-get install golang

Now verify that you’ve got Go updated:

$ go version
go version go1.1.1 linux/amd64

Install PHP mcrypt extension in MacOSX

In an earlier post, Installing Multiple Versions of PHP on Mac OS X with Homebrew-PHP,  I mentioned using Homebrew-PHP to install multiple versions of PHP. I ran into an issue installing Magento due to the mcrypt extension not being loaded.

PHP extension “mcrypt” must be loaded.

Note: I’m assuming here that you have already checked your php.ini file and uncommented the appropriate line that loads the mcrypt extension.

Using Homebrew, it’s a simple process to get mcrypt added to PHP.

First, tap (which may be unnecessary if you used Homebrew-PHP):

$ brew tap josegonzalez/php

And then do the install:

$ brew install PHP53-mcrypt

This also works with PHP 5.4 (PHP54-mcrypt) and PHP 5.5 (PHP55-mcrypt).

You may be prompted to link:

Error: You must `brew link php53' before php53-mcrypt can be installed

You may also get another error, something like:

Error: Could not symlink file: /usr/local/Cellar/php53/5.3.26/bin/phpize
Target /usr/local/bin/phpize already exists. You may need to delete it.
To force the link and overwrite all other conflicting files, do:
brew link --overwrite formula_name

To list all files that would be deleted:
brew link --overwrite --dry-run formula_name

I didn’t have any issues with this and simply ran:

$ brew link --overwrite php53

If you get an error about not having zlib installed, they try:

$ brew tap homebrew/dupes

Restart Apache and with a little bit of luck you should have mcrypt loaded.

Using cURL to Test the WordPress Theme and Plugin APIs

Occasionally (rarely) when trying to search for a theme or plugin via the WordPress dashboard, you may see an error like this:

An unexpected error occurred. Something may be wrong with or this server’s configuration. If you continue to have problems, please try the support forums.

This means that the request WordPress has made to the theme or plugins api has failed, or that the body of the response is bad or empty. Often web hosts will turn off outbound http requests and this will be the source of your problem. However, there can be a myriad of other issues that may cause this error. WordPress will use one of three “transports” and search for them on your server in this order: curl, streams, and fsockopen. Since the focus of this article is on using cURL, that’s what will use at the command line.

To check if cURL is installed on your server, use the Unix ‘which’ command to find it’s install location.

$ which curl

and you should get a response something like this (your path may vary):


To simply check connectivity with the WordPress theme and plugin apis, you can make an http HEAD request with cURL:

$ curl -I


$ curl -I

You should see output something like this:

<br />HTTP/1.1 200 OK<br />Server: nginx<br />Date: Tue, 15 Oct 2013 14:06:36 GMT<br />Content-Type: text/html; charset=utf-8<br />Connection: close<br />Vary: Accept-Encoding<br />

If you don’t have connectivity, you may see something like this:

<br />curl: (6) Could not resolve host:; nodename nor servname provided, or not known<br />

If you want to duplicate the request made when you’re actually on the WordPress dashboard, you’ll have to make a POST request with serialized data parameters. To mimic a search for a “blue” theme, use this cURL command:

$ curl --data 'action=query_themes&amp;request=O:8:"stdClass":4:{s:4:"page";i:1;s:8:"per_page";i:36;s:6:"fields";N;s:6:"search";s:4:"blue";}'

To mimic a search for a “cache” plugin, use this command:

$ curl --data 'action=query_plugins&amp;request=O:8:"stdClass":3:{s:4:"page";i:1;s:8:"per_page";i:30;s:6:"search";s:5:"cache";}'

A successful request will return quite a bit of HTML and serialized data (which I won’t post here).

Contributing to WordPress

Contributing to an Open Source project is fun. (and it’s good for you!) Not only that it’s educational. I can’t tell you how much I’ve learned by answering questions in the Support Forums (you can find me here), doing an occasional bit of work on the WordPress Documentation Team, and writing and releasing a handful of WordPress plugins.

As you can see, there are many ways to get involved and contribute to WordPress. (and I’ve just done a few of them) Whether you’re a WordPress developer, theme author, or just simply a fan or user of WordPress, there’s probably a way you can contribute.

And one important point I’ve neglected to mention…you’ll be helping others and you’ll be helping WordPress! And I don’t have to tell you, but by giving back to the fabulous WordPress community you’ll make the world just a little better place than it was before.

If you’re interested (and I hope you are), I’ve curated a few links to help you get started. – Codex

Make WordPress –  Make WordPress Core






If you got any additional resources, don’t hesitate to send them my way.

Moderate Use of Shortcodes in WordPress

In a recent question on the forums a user wanted to know if there was a way to prevent non-admins from using shortcodes when creating/editing posts.

The solution I came up won’t prevent non-admin users from entering shortcodes, but it will prevent WordPress from saving them.

Add this to your theme’s functions.php:

function filter_handler( $data , $postarr ) {
    if ( !current_user_can( 'manage_options' ) ) {
        $data['post_content'] = preg_replace( "/\[([^\[\]]++|(?R))*+\]/", "", $data['post_content'] );
    return $data;
add_filter( 'wp_insert_post_data', 'filter_handler', '99', 2 );

This will prevent anyone other than admin/superadmin from inserting shortcodes (well, it will delete a pair of square brackets and anything in between when a non-admin inserts or updates a page/post – if there’s a better way I haven’t found it yet).

WordPress Posts Page ID

To find the ID of the page that contains the posts (the listing of posts), you use the WordPress function:


The caveat is that this value will only be set if you assign a static page as your front page and assign another page as your posts page (via Settings->Reading). When you run WordPress where the front page displays your blogs posts, that’s a special case and there is no “posts page” id. (actually, it comes back as 0).

$posts_page_id = get_option( 'page_for_posts' );
echo "page id: " . $posts_page_id;

WordPress 3.6.1: How To Upload swf Files

If you have tried to upload a swf (or exe) file and gotten an error message something like this:

“filename.swf” has failed to upload due to an error
Sorry, this file type is not permitted for security reasons.

That’s because WordPress 3.6.1 has added some new security restrictions in regards to file uploads (

Additional security hardening:

Updated security restrictions around file uploads to mitigate the potential for cross-site scripting. The extensions .swf and .exe are no longer allowed by default, and .htm and .html are only allowed if the user has the ability to use unfiltered HTML.

And while it’s best to take these security changes seriously, in come cases you may need to upload a swf file (or an exe, but I’d never see a need to do that). So if you’d like to allow uploading of a swf file via the Media Manager in WordPress 3.6.1, just add this code to your theme’s functions.php file:

function add_upload_mime_types( $mimes ) {
    if ( function_exists( 'current_user_can' ) )
        $unfiltered = $user ? user_can( $user, 'unfiltered_html' ) : current_user_can( 'unfiltered_html' );
    if ( !empty( $unfiltered ) ) {
        $mimes['swf'] = 'application/x-shockwave-flash';
    return $mimes;
add_filter( 'upload_mimes', 'add_upload_mime_types' );

Installing Multiple Versions of PHP on Mac OS X with Homebrew-PHP

When developing WordPress plugins I always test with different versions of WordPress, but I generally just use my default version of PHP (5.3.26 in my case). I had a case where a PHP function had been deprecated in PHP 5.3 and removed from PHP 5.4, so I wanted to test my plugin with PHP 5.3, 5.4, and 5.6. Homebrew-PHP by Jose Diaz-Gonzalez and other contributors couldn’t make it any easier. Just follow the link for some Homebrew goodness: