International Travel With An Infant

August turned six months old today. My wife and I had planned a European backpacking trip about 2 years ago for our honeymoon. We were just about to get married but knew we needed to save for a proper honeymoon.

Well August surprised us when my wife found out she was pregnant about 7 months before we were scheduled to leave. So I pushed the plane tickets back 5 months from the original date and we decided we’d just take him with us, so we did! We decided to stay in Norway instead of country hopping, but there was a lot to see there so we were very happy with the trip.

Here he is after 23 hours of straight traveling on the way home by trains, buses and planes!

Preparation

We wanted to travel light, no checked luggage if possible. Our carry ons were pushing it but they let us take them. They were the rolling luggage with pop up handle that is iffy size for carry on. We were prepared to pay and check them but were seriously hoping to save those funds. They did not let us bring them back, they told us at the gate they had to be checked but they let us do it for free since we were that far along. Also, I think having a cute baby strapped to you gets you some favors.

We used a baby carrier, an ergo. Babies do really well in these things for extended periods of time, for the most part, I know all babies are different so take all our tips with a grain of salt.

We packed enough diapers & wipes to get there plus a couple days. Check out your destination before hand. If it’s a 1st world country, diapers are fairly abundant.

We took 3 bottles, he uses a special kind that simulates the boob flow as he nurses most of the time. We do supplement with formula so we brought some formula as well, enough for 3 or 4 days. We didn’t research this well and should’ve seen what brands are available in Norway. Some babies are fickle about their formula. We were fortunate he liked what we found there just fine.

RESEARCH store hours. Norway has some odd hours for their stores and we didn’t even think about the fact we were travelling over Easter and they shut DOWN on Easter big time. For days… (google booze laws too if you want to have some drinks on your trip, Norway surprised us with the crazy nanny state alcohol laws).

All the main grocery chains there (rema 1000, kiwi, etc.) carried baby supplies.

Bring any meds you might need… we didn’t. My wife caught an awful cold towards the end of our trip and we super lucked out that neither August nor I got sick as well cause we’d have no idea what meds a baby could have and finding an open pharmacy on Good Friday was a royal pain in the ass.

Challenges

Our son has been a bit spoiled with co-sleeping. We used airbnb’s for the most part and a hotel in one location. We brought a small packable walled baby bed that folds up. In the airbnb’s we left it in the bedroom and put him to bed so we could hang out in the living area.

The first night in a new place was always the same, he took and extra hour or more to get to sleep. But after that he adjusted well. In the hotel we put him in the bathroom… was quite funny sneaking in to take a pee as quiet as possible (my wife got good at toilet gymnastics to get the right angles for no splashing).

You can’t ride in cars without a car seat, don’t even think about how you can pull that off just plan around using busses, trains and plains. And babies ride for free! At least with Norwegian Air he did, I know some international make you buy them a seat.

I’m not sure if this is normal but our boy hates when you sit down with him in the carrier, so if it’s a 20-30 minute ride you will probably be standing in the train… which brings me to this point as well, you will be walking a LOT, like a whole lot, so make sure you are physically ready for that. And take a fitbit, you’ll be crushing all your friends on it.

Planes are the obvious big & scary challenge with an infant. We made a bit of a game plan and it worked well. We had a bottle full and ready for him to take right during take off as their ears can pop and chewing on something comforting helps them a lot.

We also kept him awake from his naps before the flight. He got pretty fussy but it paid off as he slept for the majority of the flights. Also, learn to relax. People expect babies to cry, it might be annoying but it’s going to happen so just do your best to keep them quiet and comforted but don’t lose your cool if the baby goes off some. Stay focused and do what you can to calm them down. If seat belts off, get up and walk around with them. Every tends to smile at the cute baby.

The relax thing is super important. After tons of walking and traveling for hours at points, you will be exhausted… so is baby! Stay cool, do your best to just comfort the child. Focus on the child as much as possible and not your own tiredness. Once the baby is calm, it’s like a huge cloud is lifted and everything else is easy.

The HOLY SHIT Moment

My wife looked at me while we were in Bergen and said, “Huh, my throat just got scratchy out of no where.” We both blew it off as transitioning from hot humid Florida to dry cold mountain climate. But it only got worse. My wife has athletic asthma so it’s never really life threatening but if she runs for 20 minutes or so she has to have an inhaler or her throat constricts and breathing gets tough.

Well, she got bad… real bad. She was coughing like crazy and having trouble breathing just from picking up our son. We gave it a day to see if it was nothing serious but it only got worse. So the second night of it she reached a point where she was about to have a panic attack and at 11:00pm on Good Friday or maybe the night before (point is nothing was open and we knew no one) she made a trip to the E.R. in Norway.

Here’s what really makes us frustrated about the whole thing. They drew blood, listened to her lungs and kept here there for a couple hours just for the doctor to say she has the “Norwegian Cold” and time is all she needs to fix it. She can get some over the counter cough medicine for some relief and hit her inhaler once every four hours. Well she’d hit it and feel ok for about 45 mins to an hour then back to misery and trouble breathing and panic attacks, etc.

When we got back to the states she went to her doctor today and they said it was incredibly serious viral issues on top of her asthma and she needs to be having nebulizer sessions four times a day amongst some other treatments and a steroid. Very irritating how nonchalant the doctor was to her, almost making her feel stupid for even coming in. That said, they didn’t bill us a dime so that’s cool.

Deal With It

The impression we got was just to deal with it, so we did. We got on a regiment of cough drops, some weak cough syrup (the nation bans anything like mucinex completely) and a little whiskey/lemon/honey at night all topped with her inhaler once every four hours.

I was stuck with full responsibility for our son. I carried him at all times, I changed him, she still nursed though but doing anything physical at all would get her crazy winded, coughing and breathing issues. (So yea, thankfully we had some good “mom & dad” time at the beginning of the trip).

The last few days we didn’t much walking, we were very fortunate that we got to explore Oslo and Bergen a LOT before this got serious. We spent four nights in Flam near the end of our trip where everything was within 100 yards or so from the hotel. It’s a quaint mountain town with beautiful sites surrounding it, perfect for the situation.

Simply Amazing

We wouldn’t take the trip back for anything. I never knew I’d be bonding so much with my son, I feel like I know and understand him at a completely new level. He’s amazing and so is my wife. We went through heaven and hell together and we are only stronger as a family unit because of that. I highly recommend taking infants on adventures with you, just a bit more laid back adventures, but still a big time.

Here’s some family photos from the trip ūüôā

ALBUM: Visiting where they filmed Hoth on our way back to Oslo at end of trip

The Fear & Loathing of Internet Ad Networks is Ridiculous

Many of my blog posts begin from a discussion on reddit and this one is no different. ¬†Reddit users get upvoted for hoping internet ad companies have an “agonizing” starvation of revenue to put them out of business. ¬†I can’t even begin to explain how ludicrous this statement is without writing a full-on article, so here we go.

What Are Ad Networks

Let’s start by drawing a line in the sand. ¬†I need to make it very clear what I’m defending here is not the practice of stealing and selling user’s information in ways done by the NSA. ¬†I’m also going to avoid the new usage of this practice by ISPs, the people who sell you your connection to the internet¬†like Comcast or Verizon.

I’m strictly talking about company’s like adroll or google’s adwords or Facebook’s internal ad system. ¬†Let’s start small in explaining how these work.

Example Usage

Say your dad decided to take his lawn maintenance business of 20 years to the next level. ¬†Instead of the word of mouth around town that’s built his clientele he’s ready to add three new trucks, drivers and a half dozen team members. ¬†He wants to branch out into the surrounding counties and set the base to grow even bigger. ¬†Marketing is going to be key.

He hires a local agency, they set him up with a new logo, some branding standards, a website and… that’s right, digital ad management. ¬†This shit is vital to a business these days, small or large.

The agency will use their network or networks of choice to run your dad some advertisements. ¬†He has no fucking clue what’s happening but he’s seeing the results. ¬†Look at that, he’s got some “conversions” and starts generating new business.

Conversions: When a person visits a website, most websites have a conversion goal for that person.  This means, they want the user to do something.  This could be making a purchase, signing up for a newsletter, reading a certain amount of pages or anything they decide is the goal for their website.

The Ad Networks allow the agency, or even you if you want to do it yourself, to build out some ads, select the target audience, and press the start button.  Typically these ads have

  • A title: bolder, clickable headline ex: “Mac’s East Alabama Lawn Maintenance”
  • A description: Short two or three lines text describing the link “With 20 years of customer loyalty we branch out into the entire East Alabama region offering our services.”
  • Keywords: Some keywords you believe people might search that you’d like to see your ad show up on: “Lawn Maintenance, Grass Mowers, Established Businesses, Family Business” and so on.

Certain ads like banner ads let you have a picture attached and then there are far more options in the bigger providers like google adwords, stuff too complex to write out here.

The Ad Networks takes these ads and serve them through websites that CHOOSE to use that network to make money. ¬†These websites willingly install the ad network software to their website. ¬†Any website that has this ad network installed will have advertisements shown that the ad network thinks relate to their content and what their users would like to see. ¬†So Mac’s ad would maybe show up on a blog about lawn equipment or when people search google for “Lawn Service in East Alabama.”

Targeting

Now the part that people are getting pissed off about.  How the FUCK does Facebook know I love Bill Murray so much that they give me t-shirt ads with his face on them? Damn them sending me ads related to my interests!

Here’s how, it’s not complicated. ¬†It’s brilliant, but it’s not complicated. Simply put, you do things on the internet related to your interests. ¬†If the websites you visit use the same ad network that ad network records your interests. ¬†They then serve you ads based on those interests. ¬†You know that Bill Murray fan page you were on that had a big Facebook “LIKE THIS ARTICLE” button? Yea, they installed Facebook’s code there so Facebook knows you visited it. ¬†The website CHOSE to give Facebook access to it’s users. ¬†You CHOSE to visit that website AND have a Facebook account.

Your web browser, what you are reading this in right now (most likely), has a feature called cookies. ¬†Most of your favorite websites would not function correctly without cookies. ¬†They are a small text file that¬†your browser¬†creates. ¬†That’s right, YOUR browser creates it based on YOU requesting a website that sends instructions back to your browser. ¬†They say, “Hey, here’s our cookie recipe you should bake this so you can feed us these delicious information cookies next time you visit.” ¬†Your browser can say “fuck off, I’m not making your cookies” or it can make them. ¬†Let me draw that out more clearly:

THE REQUEST: You type in https://facebook.com into your web browser. ¬†This is called a request. ¬†You are REQUESTING Facebook to send you it’s website. ¬†Facebook doesn’t have to. ¬†It can see the request is coming from your computer and say, “Hey, fuck this guy, send him a big picture of a middle finger” and that’s their right! They can serve whatever the fuck they want to! But they wanna make money so they send back some really useful shit you wanna see.

THE RESPONSE: Say it’s your first time visiting Facebook, they notice they don’t have any records of you visiting before and so they send you the main registration/login page. ¬†You fill out the form with your information, click the I Agree to their terms and conditions (this is important), then click the register button. ¬†When you click this button you are making another request, this time it’s a request with information attached that YOU GAVE THEM.

This response sends your browser a bunch of code, code that developers like myself write. ¬†It says here’s all the stuff to show the user, here’s how to lay it out to look pretty and here’s some things to do behind the scenes to make it all work right. ¬†That behind the scenes stuff includes the cookie recipe. ¬†You don’t have to accept cookies, you can turn these off in any web browser’s settings. ¬†Maybe they should be opt-in (you must turn on instead of off) but that’s a different debate.

The cookie instructions tell your browser to create a text file containing this information and make sure it can only be read by this website that’s asking you to create it.

Typically the cookie says something like “This guy has logged in already don’t make him write his password and stuff again when he visits.” It will contain your unique user ID so it can log you in automatically. ¬†It does something else too …

Tracking! Spying! ESPIONAGE!

Some fucking reddit user actually said it’s espionage then copied the dictionary definition. ¬†What a blow-hard, entitled little shit. ¬†Let’s say you visit helpmylawnlookawesome.com and that website has installed google adwords so they can make some money serving ads to you. ¬†That website installs some cookies to your browser saying you’ve been there. ¬†Google Adwords makes a cookie too because that website installed them and said they could.

Then you find yourself on another website that also has google adwords installed so they can make some money, lawntips.com (Just the tips!). ¬†Well they both have google adwords so it can see that you’ve been to both websites and it might serve you an ad for helpmylawnlookawesome.com while you are on lawntips.com because it knows you’ve already been to that website once so you have some interest.

I’m in Europe on vacation right now and for some reason this is the ad I got on my own site while here… targeting at its finest lol

Your Address

Even if you don’t have cookies turned on, every connection to the internet has a publicly available IP Address. ¬†This is like your mailing address in real life. ¬†It’s public, it’s always public. ¬†If you browse through a service that offers to hide your IP Address, guess what? That service can see your IP Address cause it’s public and you gave it to them by requesting their service.

It’s just some numbers like this 111.22.33.4. ¬†If you browse any website, any website on the internet, that website can see the request is coming from that address. ¬†You can’t mail a letter without a return address.

So when you decide to go to a website you are actively saying “Hi, it’s me, here’s my address will you return some content to it?” ¬†That’s all they get. ¬†They don’t get your name, they don’t get your child’s school, they don’t rent you fucking shoes, dude.

But if you give a website some of your information, or things you are interested in, that website has every right to record your IP Address along with the things you told it about you.  If that website has an ad network installed, guess what.  Yep, that ad network can store you IP Address along with that information.  Then when you visit another site that has that network it has all your information from the other site because they BOTH USE THE SAME AD NETWORK.

This is how things magically appear relevant to you or from sites you visited on other websites. ¬†It’s not fucking espionage. ¬†It’s marketing, we’ve been doing it for centuries. ¬†If you collected all the mailed advertisements in the country you’d notice ads relevant to the population of a certain area are being sent. ¬†Old people neighborhoods get ads for hip replacements. ¬†That’s just how it works and has always worked. ¬†You wanna outlaw marketing? Be my guest but that’s gonna fuck up some serious balance of this day and age.

They Shouldn’t Share My Private Information

THEN STOP FUCKING GIVING IT TO THEM. ¬†You can turn off cookies, you can willingly not have a Facebook account, no one is making you create one! ¬†Also, no one fucking cares about you. ¬†They care about selling shit to you. ¬†It’s not like they are saying, “Oh, here’s Tom’s address, let’s go spy on his life and shit.” ¬†You’re not that important so get over yourself.

Free & Open

If you want to have a free and open internet that means people have the right to put ads on their website, they have the right to build systems that serve ads for the best return, they have the right to put whatever the FUCK they want on their websites.

And you have the right to block it! You can use an ad blocking system, though I think it kind of makes you an asshole, it’s your right! ¬†Hell, I use one for specific sites that bother the shit out of me with their ads (looking at you UltimateGuitar.com).

You also have the right to not use cookies or JavaScript though it’s going to make your web browsing experience a lot more boring.

You know what’s really incredible? Facebook is always listening to the microphone of your cell phone. ¬†You gave it permission to do that when you accepted its terms while installing its app. ¬†You can uninstall it though, isn’t that a novel idea? Oh wait, you deserve to use their multi billion dollar to develop app for free with no strings attached. (No you don’t).

At the end of the day, calling it espionage is dumber than shit.  You entitled little fuckers that do that are morons.  And wishing agony on a business for trying to make money is like wishing a rainbow not to be a rainbow any more (I am the mango!).

Update Your NativeScript Plugins

I have an app I’ve been developing for 10 months now. ¬†It’s been in the iTunes store since this past September. ¬†I’ve been rehashing how the photo capture and gallery system works for a couple of months now and kept having random crashes, or after releasing and testing the live version on my phone it would bugger out or act weird.

I noticed in the console I was getting a warning. ¬†It technically wasn’t breaking the app but I had a hunch it was causing the random freak outs.

CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.

I tried googling a solution but it was way over my head and not really related to coding in NativeScript.  So I google uncommitted CATransaction NativeScript.  I found a thread on a repo that dealt with using a background http thread.  My photo gallery was highly dependent on NativeScript Background HTTP plugin.

I tns plugin remove nativescript-background-http then tns add plugin nativescript-background-http and it installed version 2.5.1 which was released two weeks ago.  Instantly that issue was gone and the photo section was running so much smoother.

I’m not sure what changed, but these plugin devs (the good ones at least) are on top of it. ¬†Get the latest versions of your plugins!

Import Leads From WordPress to Insightly with Caldera Forms & Insight.ly API v2.2

Recently I had a client ask to take submissions from a formsite.com form into their Insight.ly account as soon as submitted from their WordPress site.  This was no easy task as formsite uses javascript embedded code to generate an iframe and load the form.  I pulled it off by interfacing both the formsite api and the insightly api on a thank you page redirect from formsite but it was gross code and had a moderate failure rate at importing correctly.

Remove The Middle Man

Don’t let its modern, sexy homepage fool you, Formsite is pretty archaic in methods and form generation. ¬†It’s a sad case a site and tool so large can be so crappy. ¬†I needed to just build a form that shot the info over to insightly while also looking nice and sending an email to the site owner.

I’ve done some work for Caldera and I can honestly say they have the best, easiest to use and easiest to extend form building system for WordPress… bar none. ¬†They also look gorgeous. ¬†The drag and drop interface is beautiful¬†and works flawlessly. ¬†The options and extensions vary from simple needs to extremely complex ones. ¬†What we are going to build here is somewhere in between.

Extending Caldera Forms

First build a form. ¬†The Insightly API has some requirements but they are not documented well. ¬†From trial and error I believe first name, last name and email are the main requirements… maybe phone. ¬†So create a simple form in Caldera with these and whatever else you need then let’s move on.

Add the official Caldera plugin Caldera Forms Run Action to your WordPress installation. ¬†This plugin allows you to to hook into the form data being processed before, during and after the processing. ¬†Before we start writing code, let’s set that up on our form.

Go to the “Processing” tab on the form editing page, add a processor of type “Run Action” and fill in details like this. ¬†You can use a different name for your filter/hook but just remember it when we start coding.

Run Action Processor Settings

We are saying we want to do some stuff with the form data after the user submits but BEFORE it gets processed.  This way if we have any trouble with the insightly api we can let the user know so they can fix their input.

Hooking Into Caldera

To do this, you need to put some code into WordPress. ¬†You can do this in your theme’s functions.php file but I recommend you create a very small plugin. ¬†To create this plugin you will add a folder to your wp-content/plugins directory called caldera-insightly. ¬†Inside that folder you will create a php file named caldera-insightly.php. ¬†That file will look like the below code. ¬†Don’t forget to go to “Plugins” in your admin and activate it.

This code is BARE BONES. ¬†I did not build this out like a big proper plugin but it’s simple in its functions and will work for the basics of interfacing the insightly API v2.2. ¬†I explain the code below.

The add_filter line is where we put in the hook that we registered on the Run Action processor on our caldera form. ¬†The second parameter ‘process_insightly_data’ tells it what function to perform on the data from the form. ¬†Remember this is all happening before Caldera processes the data so if we return anything at all from this function the processing fails and the user gets an error message.

$form_data[‘first_name’] is referencing the “slug” of the form field. ¬†You can see this when building your form in caldera. ¬†Each field input has a slug that is sent as the form data.

Insightly requires the data to be formatted in JSON with very specific keys. ¬†You can see a list of options here. ¬†The FIRST_NAME, LAST_NAME and so on are very straight forward. ¬†The complicated shit happens when you hit the LEAD_SOURCE or want to do CUSTOM_FIELDS. ¬†I’ve had a time and a half working with custom fields and got it to work once, so I just avoid it now if I can. ¬†The lead source requires you to already have lead sources setup in insightly. ¬†You need to get the ID’s of those sources and use them to create your lead source array.

Lead source is not required so you can delete that whole section if you want.

After building our array of data we json_encode it and send it on its merry way. ¬†Don’t forget to grab your API key and replace it in this code. ¬†To get that code once logged into insightly click your profile picture in the top right corner then hit User Settings. ¬†Scroll down on that page and you will see API KEY at the bottom.

I detect for “LEAD_ID” in the return string as this means a new lead was created and assigned an ID. ¬†If it’s not there then we return that an error has occurred. ¬†This could be handled better but I was in a hurry as the client wasn’t paying for a lot of hours.

Are You A Hack Developer?

I made a short comment while I was semi-drunk last night on a post in reddit’s r/personalfinance about my wake up call as a shitty developer. ¬†I started getting a lot of “hits close to home” comments and private messages. ¬†Surprised me, I thought it was just going to get buried.

I guess there’s a lot of us out there. ¬†Those of us that taught ourselves to code. ¬†Those of us that made/make a living developing by themselves. ¬†I figured I should share my story.

I’ve freelanced since I was 18. ¬†I went to undergrad for interactive design (no coding, all flash) and graduate school for Marketing and Management. ¬†I suck at both.

I got a job out of grad school as the Webmaster for a large hospital. ¬†After that I got $180k funding for a start up idea I had and I tried to build it by myself over the course of a year and a half… it failed. ¬†That’s a whole different story in itself. ¬†Then I got a job as a Webmaster for a University.

Notice a trend here? Coding solo.  No code reviews.  No requirements or standards.

The title “Webmaster” is so antiquated and seems to relate to public or government institutions. ¬†It also means coding¬†alone, typically.

Getting By

I had no problem with my work or how I did it. ¬†People needed shit built or managed and I did that. ¬†When I delivered it, it worked. ¬†But it also broke… all. the. time.

I’d patch shitty code with more shitty code. ¬†The source was disgusting. ¬†But I had no idea, I figured it was fine. ¬†Classes? git? An IDE? Local environment? Who needs that shit, I’m building stuff just fine in Notepad++ and a couple huge files with intense amounts of logic mixed into views and db calls. ¬†Hey, they shared a header file and sometimes a footer. ¬†I know how to INSERT and SELECT and UPDATE… who fucking needs a JOIN statement when I can just run 10 queries and a dozen for loops and nested if statements to get the data I need.

I Was Getting Paid

The hospital gig was $58k right out of grad school and rose to $70k over three years with insane benefits.  The University job was shit pay but the workload was so ridiculously light and the benefits were phenomenal.  I had so much time to freelance.

I regularly pulled in between 70-90k throughout my 20s. ¬†Why would I think I needed to learn how to do things better? ¬†I could pick up new languages or frameworks with ease. ¬†I was writing VB.NET and action script for the first five years, then oh, everyone’s using WordPress now? ¬†It’s php? Ok, I’ll learn php.

That was easy.  I mean, coding languages are all basically the same on the web, or so I thought.  You have variables, functions, you get the request variables, you go in and out of a database and you display your shit in html with, in my case, some nasty fucking javascript and inline styles.

WordPress was super easy.  Grab a free theme and some plugins.  Then I could just edit the plugin files to do what I wanted or hack through a themes templates and css.  Updates? Who needs updates, it works as is.

Chris Wiegman

Obviously, now, this is a problem. ¬†A big one. ¬†I hadn’t grown as a developer in ten years. ¬†I was building sites that were getting hacked like crazy. ¬†I always found a way to blame it on the client or WordPress and never myself. ¬†Clients believed me, I kept getting paid, but the nightmare situation of all going to hell was building up and I had no idea.

I decided wearing nice clothes to an office 35 minutes away every day just wasn’t for me. ¬†I was losing my mind, honestly. ¬†I’m extremely ADD and terrible at corporate environments. ¬†Then I met a guy. ¬†A WordPress guy.

My favorite pub in town is a craft beer bar called Mr. Beery’s. ¬†I met a guy there a couple years ago and we became friends. ¬†Found out we were both primarily working in WordPress and started talking about it a lot. ¬†He told me how he worked from home full time. ¬†I was like… that is what I want. ¬†No, that’s what I need.

Later on I found out Chris built a huge plugin and sold it.  iThemes Security is his work.  My mind was blown.  Dude who built one of, if not the biggest security plugins on WordPress, possibly on the web since WP is now 27% of it.  And he was my freaking neighbor.

I had talked myself up, very confidently to Chris. He told me to apply somewhere and that there are tons of agencies out there that hire remote WordPress devs.  So I submitted an application to 10up, the biggest WordPress agency out there (I think).

I was feeling good about it. ¬†I’m a very personable guy. ¬†Very social, good communicator and wrote great cover letters. ¬†I got hit up by 10up almost instantly. ¬†They wanted an interview. ¬†OH MY GOD IT’S COMING TRUE!

The Interview

I had a video chat with a lovely lady from 10up. ¬†We had a ¬†great time. ¬†Talking about culture, my family, my background, all my amazing¬†websites I’ve built and so on. ¬†They hit me up asking for another interview. ¬†At this point, I felt like I had this job in the bag.

We had a second interview.  Nailed it again.  Now came the code review.

I was supposed to submit some code samples to them.  They said send them links to git repos or just some files. I decided on files because I had no clue what git even did.

So I zipped up some stuff I’d built and sent it over. ¬†Kept telling my wife how excited I was, job was totally mine.

First reply was “hey, do you have any more code you could send over?” I didn’t know why they’d ask that. ¬†I sent my best stuff. ¬†So I scraped together some more code and sent it.

Then I got the email along these lines, “hey, we don’t think your coding level is where it should be for this position. ¬†We really like you and would love to have you at our company so please feel free to apply again when you level up.”

Motivation

I was depressed man.  That shit stung more than any break up, more than any shut down, more than anything.  I was distraught.  I felt like the biggest loser, faker on the planet.  I knew nothing.  My code was shit.  I should probably just switch careers.

But Chris wouldn’t let me stay down. ¬†He pushed me. ¬†He told me I could level up. ¬†He said explicitly, “let’s level you up.” I’d never had a mentor before, he didn’t even realize he was one.

Having someone believe in you is a big deal. ¬†I didn’t know that but now I was experiencing it.

I gathered a serious amount of motivation.  First goal: build a plugin for WordPress that can be released in the public repo.  You have to submit it for review, so your code has to be at least somewhat decent to get in.

Leveling Up

I made a people lister.  It had a custom post type for people.  You put in their name and some meta data like a position at a company.  You could sort them then use a short code to display the listing in a nicely laid out format.

I look back at that code now and it’s shit, but man, it was LIGHTYEARS better than anything I had written before and it got into the repo. ¬†I leveled up.

Next level was using a proper IDE, I got php storm and used it and only it.  I setup a git account and started making repos for every project.  I installed vagrant and VVV as a local environment.

I forced myself out of WordPress for a couple projects and learned about system architecture, routing, autoloading and so on. ¬†I was asked to contribute to a project with some new¬†friends I’d made in the WordPress world so I had to learn about npm and gulp and sass.

I threw myself at any opportunity to build with others.  I truly believe that was the #1 thing that has got me to where I am.

I learned NativeScript for building mobile apps. ¬†It’s such a small community right¬†now that when I started blogging on things I learned while developing in it I got a ton of traffic. ¬†I still do get loads of google traffic to NativeScript articles. ¬†I was discovering first time solutions and got indexed early.

I started applying to speak at WordCamps and surprisingly, I was accepted to five in 2016.  That was an amazing experience.

Don’t Give Up

As I grew confident in my skills and began building a small name for myself in the WordPress community I decided to give the job hunt another try.  I was told the Modern Tribe was hiring.  I redid the resume, I had this website up by then and I had a much better code catalog.

They contacted me fast and setup an interview.  I interviewed with two different people.  A culture person, then a code person.  Both interviews were awesome and they really enjoyed me as a person.

Code review was fine, they said I was moving to the final stage and they were going to give me a small 8 hour freelance project.  I was pumped, even more than last time.  I had confidence this time that was legit and founded.

I finished the project and handed it in.  A week later I had a video call with them.

I didn’t get it. ¬†They were upset as they really wanted me but they didn’t want to set me up for failure. ¬†They hiring a senior level developer that really needed to be a system architect at the same time. ¬†I just wasn’t there yet.

I wanted to give up, but again… I refocused and stayed motivated.

Still Growing

So here I am now, working from home.  Got a killer full time gig for a WordPress agency based out of Toronto.  I love my team and truly love my job.  I barely freelance anymore, just a couple long term clients that I help out a few hours a month for some extra cash.

I’m a good developer now and I can say that with earned confidence. ¬†I still have a lot to learn and I’m leveling up regularly. ¬†I want to be the best. ¬†I want to write the best code. ¬†The motivation has gone no where.

Are You A Hack?

I wrote this to hopefully motivate some others out there that were the same as me. ¬†I’m 33 now and try not to think about it, but I probably could’ve been doing this 7 or 8 years ago if I’d started the process. ¬†But I’m happy where I am and you can be too.

P.S. If you want a code review, hit me up.  Ready to pay it forward!

Yoast Primary Category Endpoint for the WP REST API

I had a special case today where I needed to pull in posts specifically from a Yoast SEO Plugin‘s primary category. ¬†Yoast SEO allows you to set a single, primary category for a post in WordPress. ¬†This is an awesome feature and very useful.

A site I’m building right now uses the API to pull in the latest articles of a category in a big drop down hero navigation system. ¬†The thing is, just pulling from a category gets a lot of the same articles when clicking around the different category options. ¬†We wanted to pull by primary category so each click gives a unique set of posts that are very relevant to the category option.

The Struggle

There may be a super simple way to do this already but I was seriously struggling googling for the answer. ¬†I’ve done some extending of the WP REST API but I’m still a novice so I was hoping to avoid it. ¬†But glad I didn’t because I learned a lot and I made a cool thing!

I couldn’t find a function in Yoast that pulled post IDs or anything based on a primary category. ¬†I needed to figure out how they assigned this. ¬†I dug through the database and found a post meta with the key ‘_yoast_wpseo_primary_category.’ ¬†This is it, this is what I’ll use to build my end point.

The Code

First we need to register our endpoint/route.  I prefer building things in classes so I created a class:

<?php
class Rest_Api_Posts_By_Primary_Category {}

I register the endpoint in the __construct() as so:

SITE_PREFIX is something I set in my theme’s functions.php file. ¬†You need a namespace here so make it unique based on your plugin or theme or site in general.

The callback function is where the magic happens. ¬†In get_posts_by_primary_cat( $data ) we do a simple WP_Query that makes use of the meta_query ability. ¬†The thing is, I need the children of categories too. ¬†Here’s an example similar to what I’m dealing with.

Let’s say we have three categories and these categories are what we see in our navigation menu: Math, Reading, History

Then those categories each have two children: ###-Lessons, ###-Research

So our final category structure looks like

Math
 РMath-Lessons
 РMath-Research
Reading
 РReading-Lessons
 РReading-Research
History
 РHistory-Lessons
 РHistory-Research

If someone clicks Reading I want to load all posts that have a primary category of Reading, Reading-Lessons or Reading-Research… so I need the children.

In the function below you can see I run get_categories on the selected category withe parent argument assigned.  This gets me all the children.  I just need their ids and I need them in string format so I run a quick foreach loop.   I make sure to add the original parent id back to the new array too.  Then I run the WP_Query.

At this point you could just return $posts->posts but I needed the featured image and only a few of the pieces like title, time and a link.  So I built out what I need and return that.

Conclusion

Now to use this we simply visit http://yoursite.com/wp-json/SITE_PREFIX/v1/yoastprimary/##-catid-## and replace ##-catid-## with the actual category number. ¬†I could’ve just made this a static class now that I think about it but whatever, you must remember to initiate it to work. ¬†So in your functions.php of the theme or somewhere in your plugin call $rest_api_primary_cat = new Rest_Api_Posts_By_Primary_Category();

This was easy to parse in my javascript and is running great. ¬†Hope it helps someone! Here’s the full code:

Remove the +Add New Category / Custom Taxonomy Link in WordPress

This post is more about custom taxonomies than it is adjusting category capabilities, but it’s ¬†probably resolved the same way. ¬† So i mention how I’d go about it after I explain what I’ve been doing.

I have a theme that has a custom post type called Members.  These members need to be attached to posts at the authors choice.  For instance, an admin is adding a new blog post.  There are three posts in the custom post type Members: John, Jack & Jill.  This post should be attached a Jill taxonomy/category.

I could solve this with a custom taxonomy, but I want the term options to be only what posts are made in Members. ¬†Problem is, I don’t want the admin to be able to add new terms here. ¬†So that big +Add New Category/Member link has to go.

I could do it with CSS but then someone smart could get around that.  I need it done server side.

Removing the Functionality

As far as I can tell there’s no filter to hook into and remove that feature. ¬†It’s not an argument when registering a taxonomy so you can’t just re-register category or set it when creating a custom tax.

What you can set is what users are allowed to edit/add terms. ¬†The long route would be creating a custom user role and assigning only them. ¬†But I thought to myself, what would WordPress do if I just used a user role that doesn’t exists? ¬†So I did this:

I set edit_terms and manage_terms to ‘god’ and voila! The option is gone!

Add Variation To Cart in WooCommerce: Don’t Forget The Attributes!

The point of this post is to help others that are having a problem dynamically adding a variation of a product (or subscription product in my case) to cart.  I get to that at the bottom of this post if you want to skip the story.

The Problem

I have a pretty high up there client in the box subscription world. ¬†I’ve been brought in to do some WooCommerce functionality with WooSubscriptions and everything else involved.

The checkout process is pretty customized. ¬†We have a page that displays all the attributes available for the subscription variable product. ¬†There’s a bunch of fancy selection boxes and lists and gift inputs and so on. ¬†It’s front end heavy but communicates with a custom endpoint through the REST API that I wrote to add the item to cart. ¬†Problem is, the sub form doesn’t give me a variation id, only the variable subscription product id and all the selected attribute values.

Finding the Variation

The first step is to find which variation they’ve selected. ¬†Someone long before me went through the rigorous process of creating some 50-60 variations of this variable subscription product to match all the different options a user could select.

So I use a WP_Query search the for any post id that has all the meta_key/meta_value matches and select it.  It was a bit of a pain to figure out the best process here but this works.

Adding the Variation to Cart

Took me a few to find the right parameters for adding a variation to cart.  Now that I had the post id of that variation it looked pretty simple from what I found online:

$added = WC()->cart->add_to_cart( $query->post->post_parent, 1, $data['variation_id'] );

This did the trick.  Since I used a WP_Query to get the post I could select the parent (which is the main subscription variable product) needed for first parameter.  Then the quantity, then the variation id.  Which was $query->post->ID but I assigned it to some data my API was returning.

The user checked out and the variation was in the order.  A day after pushing this code the site owner asked where the order details went.  Turns out it original showed the selected attributes in the admin order panel.  I spent a couple hours figuring this out, which I feel dumb now, but going in blind what can you expect.

You have a fourth parameter you can for $variation_data. ¬†This gives it the attribute love it wants and adds it to the order. ¬†Why woo doesn’t just do this automatically if a variation is added? Beats me. ¬†But here’s how you do it using a nice woo provided function for variations.

$added = WC()->cart->add_to_cart( $query->post->post_parent, 1, $data['variation_id'], wc_get_product_variation_attributes( $data['variation_id'] ) );