Circumventing ACF’s get_field issue in wordpress functions.php

Technical topic ahoy!

But seriously, this issue has been bugging me all day. I’m using ACF Pro so I’m not sure if this issue also applies to the free version or not, but hey, I’m gonna lay it out anyway.

 

THE REQUIREMENT

I’d created a simple little checkbox in the options page of a WordPress installation so that, if checked as True, I would be able to display a second custom options page in the Dashboard menu. It was for a multisite installation where some sub-sites needed a special options page and some did not.

So far so simple? Not quite. Turns out that trying to use Advanced Custom Field’s native function to retrieve field values, ‘get_field()‘, wasn’t going to work in functions.php. At least, not in the way I wanted.

 

THE INITIAL SETUP

To add the options page, I call the following function inside my init class:

public static function add_options_page()
    {
        if( function_exists('acf_add_my_custom_options_page') ) {
            acf_add_options_page(array(
                'page_title' => 'Custom Options',
                'menu_title' => 'Custom Options',
                'menu_slug' => 'custom-options',
                'capability' => 'edit_posts',
                'redirect' => false
            ));
        }
    }

But, to ensure it only comes up for subsites that have the checkbox selected, I have to do an extra check. Initially, I had something that seems legit and like it should work:

if ( get_field('display_custom_options_page', 'options') == 1 ) {
    self::add_options_page();
    //we use self:: to reference the init class it's within
}

Simple. If the field equals true, call the function that adds the options page.

But this didn’t work. Or rather, it did display the new options page, however the checkbox on the first options page disappeared from view every time get_field was used in functions.php.

So wait, that means every time I decide a subsite needs to have this extra options page, my opportunity to reverse the decision is taken away? Bad user design, no thank you!

 

THE REASON

After some hunting around online, it turns out that ACF’s get_field() function doesn’t play too nicely with WordPress’s init() function if you want to use it before admin headers are set. It has to be called after init().

I could add it later on, sure, but while I could now retrieve the field, going on to add the custom options page still needed to be done in init.

 

THE FIRST (MESSY) SOLUTION

At first I just thought, well, can I just include the custom options page as normal, without the checkbox conditional, and then hide it after initialisation?

So I had:

class MyClass {
    public static function init()
    {
        self::add_options_page();
    }

    public static function add_options_page()
    {
        if( function_exists('acf_add_my_custom_options_page') ) {
            acf_add_options_page(array(
                'page_title' => 'Custom Options',
                'menu_title' => 'Custom Options',
                'menu_slug' => 'custom-options',
                'capability' => 'edit_posts',
                'redirect' => false
            ));
        }
    }
}
MyClass::init();

$is_custom = get_field('display_custom_options_page', 'options');

if ( $is_custom != 1 ) { // if is_custom ISN'T checked
    // a quick and cute function to remove the specified menu page
    function remove_menus(){
        remove_menu_page( 'custom-options.php' );
    }
    add_action( 'admin_menu', 'remove_menus', 999 );
}

This works. BUT this is roundabout, first adding the page then employing the get_field after to cross-check and then remove the page again.

 

THE FINAL SOLUTION

At this point I thought why not just talk to the database myself instead of using ACF’s functions? Everything ACF creates for options pages gets saved in the wp_options table in wordpress databases, so I simply ended up using the $wpdb class to write an SQL request, and grab the display_custom_options_page field from this, all within init() itself.

Here’s the final code:

class MyClass {

    public static function init()
    {
        self::add_options_page();
    }

    public static function add_options_page()
    {
        // retrieves ocustom options field
        // uses $wpdb sql query rather than ACF get_field

        //set global wpdb, get all from options table
        global $wpdb;
        $results = $wpdb->get_results( "SELECT * FROM $wpdb->options" );

        foreach ($results as $option) {
            // if option has correct name and value, add custom option page
            if ($option->option_name == 'display_custom_options_page' && $option->option_value == 1) {
                if( function_exists('acf_add_options_page') ) {
                    acf_add_options_page(array(
                        'page_title' => 'Custom Options',
                        'menu_title' => 'Custom Options',
                        'menu_slug' => 'custom-options',
                        'capability' => 'edit_posts',
                        'redirect' => false
                    ));
                }
            }
        }

    }
}
MyClass::init();

This is a very specific case – most custom options fields aren’t created as conditionals that govern the inclusion of other options pages. For the vast majority, it makes more sense to just use get_field(). But for those times when something needs to be initialised earlier, just sql it.

A tribute to Chris Squire

One year since Chris Squire passed away. Not just one of the founding members of Yes, but the only member to stay in the band throughout their entire 60-year run until last year, his own death being the only reason for ever missing a gig. A beautiful and inspirational person who never stopped writing wondrous stories… Chris Squire, your music was a shining light in the darkest points of my childhood, you were my biggest bass inspiration, and you will always be missed.

prog-cover-chris-squire

Seriously, look at this fabulous, talented man and his multiple amazing bass guitars.

The video below is one of the few examples where he sang lead in addition to playing bass.

Can you imagine what it’s like seeing life
From the other side
Do you imagine darkened light, starless night
You might need a guide

And will the illusion confuse you, play with your thoughts
And alter your mind
Or become a delusion, include you
Change your existence for another kind

See what you see for yourself
‘Til your heart is open wide
Wish what you wish for yourself, and you’ll find it there
And you’ll believe it, and you’ll believe it

A releasekonsert with OAK and Airbag in Oslo

Last night I spent a fantastic evening watching prog band OAK perform for the second time. Since I saw them at Kolbotn’s ‘Progbotn’ festival back in January, they’ve been signed to Bergen-based record label Apollon Records, which is truly fantastic news. OAk have just released their first album, Lighthouse – and you can watch the trailer for it below.

Okay, so OAK are officially called an art rock band, but I digress… it’s amazing music, truly enrapturing and innovative. The lead singer also plays the keyboard, and has a beauty of a KORG that looks very much like a Stage Vintage (correct me if I’m wrong). What’s nice about this is being able to see the keyboard action more closely, as too often keyboardists are relegated to the sidelines.

This time they brought on a saxophonist for a few tracks, and the feel immediately plunged into something akin to the solemn atmospheric work of electro jazz groups like Hidden Orchestra. It was great to hear their new stuff, along with some of the classics from the first set I heard of theirs. The singer truly has a stupendous voice, and I got chills on more than one occasion during their set.

I really want to see this band evolve further and produce ever more work. For now, I’m just basking in the release of Lighthouse, which can be heard on Spotify in its entirety:

SUPPORT THESE GUYS, THEY ARE GREAT!

Also, at the end of their set: biggest applauding for a bass guitarist I’ve ever heard in my life! This makes me happy.

After OAK we had Airbag, a more established outfit who performed a very tight set with a more rocky vibe. They were celebrating the release of their fourth album, Disconnected, and performed a range of pieces from all their previous albums too.

While Airbag did not do anything overly structurally interesting to their pieces, they are a talented group of musicians and had a wonderful sound that was very immersive. A lot of their songs began in a dark and broody manner similar to that of Seigmen, rose to some rocking riffs, then descended into Pink Floyd style instrumentals. Oh, and also, their songs are looooong! Shine On eat your heart out! I feel as though I was listening to a lost Pink Floyd album, and with the moody and meditative, somewhat trancelike vibes, I know I need to listen to this music more when writing.

Missed Connections

Flash fiction for fickle folk.

Out of my left eye I see you waiting at the station. You’re on time, but the train is late, and you’re pacing. The seconds can’t tick by fast enough. There are places you need to be.

Out of my right eye I see him walking down the platform, with posture well rehearsed; an outer calm that belies inner worry. Be yourself but don’t get noticed. Can he get in to work and avoid balancing on the scales? Ma’at is hungry and Yahweh goads her on.

At first you think he’s attractive and your gaze quickens. But if something seems off, it is quickly forgotten as self-interest takes hold. Maybe he’ll notice how good you look if you stand just so. You’re a girl and he’s a boy so it’s only natural, right?

It’s a biting spring morning and you haven’t had enough coffee to deal with the others on the platform. Yahweh nestles into your soul and you wish, you long, to meet an angel. Something pure, devoid of the petty hang-ups and grievances of godless men.

The object of your attraction is looking up at the clouds, and his mind seems a million miles distant from the approaching train whistle. You get angered by a commuter brushing by, chewing loudly from a bag of greasy café food, and you start texting your friend. How rude some people are.

You almost miss the train, but the beautiful cloud-bound boy holds the door open, says, ‘Come on.’ You’re already bristly, and you notice it. His voice, too high in pitch. His clothes fitting slightly off, especially around the chest, his chin smooth and devoid of hair. He is far too old to be pre-puberty.

Words rise like soft, burning pumice. Unnatural. Disgusting. Liar. You were warned about people like him.

Your face starts to shift into brimstone as the crocodile god snaps him up on the scales, makes his heart heavier than a feather from your stony words.

Do you remember what you said to me when we both were young?

Today you met an angel. And you destroyed him.

—–

Many thanks to MJ Kobernus for your editing help!

Holy moly writing fest, Batman!

So it’s holy because, well, Easter, and there’s also been a ton of writing in the past few days. I am still healing from surgery but it’s going great, and am back at work, attending art class, and gaming nights round friends’ houses once again.

I lost the urge to write when I was stuck at home gaming on me tod, but then something interesting happened. I have been trying to write this time-travel short story for ages, and was getting hung up over the dénouement and the plot threads, when I played a videogame that pretty much used one of the story options I had (hint: it’s Fallout 4). And man, did it make me angry! Not because they used it instead of me, but because they managed to make me so caught up in the story that I properly took on the feelings of the main character. And main character was heartbroken, in denial, angry, and so was I. It fired me up to finish my time travel story, and I used one of the other story options instead (the depressing option instead of the anger-inducing option – not that either of them are that much better from each other, but hopefully will make people feel some kind of strong emotion). Nine thousand words later and the story’s submitted to an anthology. I wonder if it will get in.

But even if not, I feel pretty driven again.

This week art classes are back on, as is writing group, and we’re doing something pretty excited for the latter – I’ll be using my graphic design skills to assist the group in doing an on-the-fly cover design. Many of us in the group are interested in self-publishing at some point, so why not use a field of specialisation I already have to help them out? Plus it’ll be mega fun to experiment as a group and see what we come up with. I have no idea what the story we’ll be using as a basis will be, but I do know it’ll be something original from one of the members!

Finally, the Bath Novel Award deadline is coming up. I got my edits of City of Dis back from my old editor, so I’m polishing that to send in, and will probably send in Trees in November too if I feel I can get the writing quality up to scratch.

I may have to go and eat a ton of chocolate eggs now, because I ended up with far too many.

It’s Hypermobility Awareness Week!

Hypermobility - "You keep using that word. I do not think it means what you think it means."

The Hypermobility Syndrome Association is running an awareness week, so I thought I’d contribute.

To be hypermobile, at the core definition of the word, is to have a range of motion that exceeds ‘normal’ range. In clinical usage it describes having a wide range of joint movement. And more than that, it can refer to having a range of inherited connective tissue disorders which include Joint Hypermobility Syndrome, Ehlers Danlos Syndrome, and others such as Marfan’s Syndrome. In these latter cases it is never as simple as just ‘being that one kid in the class who can bend their thumb backwards’ – it comes combined with a range of symptoms that can interfere with daily life on a wide scale – from small troubles with minor dislocations and minor pain, to larger troubles with major dislocations and pain that impedes walking or driving ability, to gastric disorders or even spontaneous rupture of blood vessels, or spinal issues like scoliosis and Chiari Malformation. It’s a huge umbrella of various conditions that can be interconnected, and all of which affect each person with them differently.

I have EDS Hypermobility Type, which means I synthesise collagen badly and it primarily affects my joints and gastric system. My neck and back are bent out of shape, although you would never tell from the outside, and sometimes my head sinks into my neck enough to give me terrible headaches, particularly when lying down or using pillows / resting my neck on things. My blood vessels are extremely elastic (giving blood is difficult) and so is my stomach – it’s easy for me to get ulcers. The ligaments holding my eyes in place are too loose and it gives me double vision. But the main problem that affects daily functioning is the joint laxity and the daily dislocations. Every joint in my body does it, but particularly the feet, hips, shoulders and ribs. I used to use various walking aids – stick, wheelchair, crutches – but as my condition changes and adapts so do I – these days I mostly use shoe orthotics and stick to a specific exercise regimen to keep the muscles supporting the joints strong.

To get an idea of how different the disorder can be for different people, I have had friends with the disorder – one of whom was able to drive while I could not, but who struggled picking things up from the floor while I was fine with that, and another who got excruciating hip pain but was still able to wear high heels, which I cannot. And another still, whose main issue was preventing her blood vessels from rupturing from the smallest and most insignificant of tasks. Some of us can give birth easily, some cannot. It really depends on your personal makeup.

So that’s a general overview. I want to spend a bit of time looking at complications someone with hypermobility might encounter when having another medical issue or situation. In the past I’ve shattered bones easily, but luckily have not had to deal with plaster casts. It’s a relief, because the thought of dislocating while in a cast and being unable to set it back in myself while also having a broken bone scares me a little.

Therefore it’s topical that recently I elected to undergo surgery to remove breast tissue, which (among other reasons) I expect to lessen the number of rib and shoulder dislocations I currently experience per day. A quick note: this is not suitable for the majority of folk with EDS, because surgery is not a cure for the collagen problem, and it comes with many complications. However it was suitable for my particular case. For a non-EDS patient, undergoing this surgery forms about a few weeks of pain, the first three or so days being the most intense, and then mostly, things go fine with little complications other than potential infection.

For an EDS patient, the complications are somewhat different. My body fought off infection pretty well following the surgery, but having to not move much in the weeks following, combined with compression bandaging around the chest, meant that a lot of my joints fell out and I was unable to manoeuvre them back in properly. The shoulders and back have been the worst, but I’m actually quite happy to say that, barring the first three days of recovery, that’s where the most pain is actually coming from. It’s important to remember that hypermobile patients need to pay the most care and consideration to re-mobilisation techniques post-surgery. We cannot allow our ligaments or tendons (the connective tissue around the joints) to become too foreshortened, or we run the risk of joint issues complicating and lengthening the recovery period, and of muscle cramps and frozen nerves. But we also cannot move too much to relocate a dislocated joint if it runs the risk of reopening the surgery stitches, et cetera.

Because the surgery was largely to solve an EDS-related issue, I prepared well enough that I’m handling it okay, but it’s definitely one of those things, along with giving birth, or getting a plaster cast, that needs to be approached with extra attention for those with hypermobile conditions.

I would dearly love to write more on this, but I do need to take a break and heal up more – I have already spent too much time typing. Well, I hope I have educated you at least a small amount!

For more info do head on over to the Hypermobility Syndrome Association’s pages: http://hypermobility.org/hmsaware-week-is-here/

Hypermobility is only the tip of the iceberg

Gaming challenges: Mass Effect All-Engineer Playthrough

One fun thing I love doing is inventing my own video game challenges. In some games, they don’t provide enough endgame progression challenges, at least not for a completionist like me. I first saw this kind of behaviour in online forums for Final Fantasy X fans who, dissatisfied even with the epic endgame content, put together their own challenges of getting through the entire game using and levelling up only one character. Later I saw people do it with Fallout: trying to get through the entire game with zero kills. It’s the kind of idiosyncratic behaviour game testers try to replicate, and I love it. So I do it myself as much as possible.

My latest gaming challenge, while I lay in bed recovering from surgery and an just about able to grab a controller, is to replay the old Mass Effect series using a pure Engineer team. Mass Effect’s gameplay is designed to work best with cross skills from three main areas: solders, engineers and biotics. Most missions will be significantly harder of you’re lacking in skills from any sector, so whatever class I’m playing I usually bulk up my team with the classes in deficient in.

But there’s nothing to stop you using a mono-class team, as long as you distribute skills evenly within that team and plan well. So I’m doing an all – engineer team – my Shepard is an Infiltrator (so I can have medium armour and use all engineer skills) and I’m traveling with Garrus and Tali. They use sniper rifles and shotguns respectively, I only use pistols.

So far my strategies are working well. I’ve been mostly buffing my shields and weapon damage and managed to take down a Geth armature using only a pistol today, so it is working.

If it’s a success I’ll have to try it again, up the difficulty.

Midweek Music Picks: Pure Reason Revolution

Pure Reason Revolution are a band that caught my attention first as prog, but I soon realised they were inhabiting the prog genre at the most progressive, eclectic fringes of it – as you can tell upon listening to the song below, Blitzkrieg.

The music hovers between the electroclash rock of Justice, the fast-paced drum’n’bass rock fusion of Pendulum, and the chaotic soundscapes of electronica artist Hans Appelkvist: synthy guitar riffs and strong drumbeats are peppered with Eighties style Orchestra Hits, the odd house clap, before descending into broken rhythms and chopped-up blurts and bleeps, then building up again with polyphonic chorus into an insane fusion of sound, using noise as sculpture, painting crescendo onto seconds.

The slightly dystopian futuristic undertones of their themes (the intro samples of Blitzkrieg, for example, are from 1962 post-apocalyptic French film La Jetéesuggest something akin to Rush’s 2112, which makes sense considering the band’s first producer also produced Rush’s music.

Furthermore this band is from the town next to where I used to live in the UK (Reading – a wee bit north from the birthplace of Genesis). Nobody seems to know where to place them – they have been labelled prog, electronica, alt rock, new prog, and bizarrely ‘Astral Folk’, even garnering a good review from keyboard wizard Rick Wakeman. It’s a shame they’ve split up now, but one can always hope, because this music rocks.

 

The Watch plays Nursery Cryme

Italian prog rockers The Watch are the Genesis continuation we always wanted. Officially endorsed by ex-Genesis guitarist Steve Hackett, they do amazing covers of classic era Genesis songs. Their original albums, while having their own distinct flavour, are tantamount to the Genesis albums that never existed but that totally should have. Imagine, if you will, that Gabriel and Hackett never left and that classic era of music had been allowed to progress in that vein. This would doubtless be the result. I have so much love for this band, so you can imagine my excitement when I heard they were coming to Oslo.

The band kicking off the concert

The concert, held last Saturday the 30th January, was billed as ‘The Watch plays Nursery Cryme’, but what we got was so much more. Not only did we get plenty of The Watch’s own music, including a few wonderful songs inspired by the Italian Alps, but we also got a sly couple of songs from The Lamb Lies Down too. And, let me tell you, as soon as those gentle guitar strums and first Mellotron sweeps hit the air, the room was electric.

“There’s something solid forming in the air,

And the wall of death is lowered in Times Square…”

We could all feel it, and in that moment I knew we were enraptured, part of the show, the adventure. We were all Rael then.

The atmosphere electric continued on as they played through Nursery Cryme with stylised restraint. I loved this aspect of the band – it is clear that they are virtuosos, but they let out only as much as is needed for the song, giving the stark impression that they are holding back a powerful hurricane. The lead singer, in particular, Simone Rossetti, embodied the essence of Gabriel’s countenance in ‘Watcher of the Skies’ – a solitary, austere figure, voice tight as a tightrope walker, letting out just enough of the music to make the maximum impact. Less is more, in this case, and it was magical. It belonged to another universe.

Nursery Cryme was indeed played in its entirety, but not in order. This was a surprise for many in the audience, and by the time the album’s stellar track came out, The Musical Box, we were ecstatic, and more so from the unexpectedness. I was deeply happy with the guitarist, Giorgio Gabriel, and his ability to sound every inch as ethereal and heavenly as Steve Hackett. The sound of his guitar playing like waves lapping at the shore. Songs like Harlequin in particular, so dreamlike.

The keyboardist, Valerio De Vittorio, had amazing technique, using Moog and Mellotron to maximum Seventies effect. This really came into its own on the band’s original songs, where the keyboards seemed more striking than the soft waves of Genesis. And the bassist, Mattia Rossetti, impressed many by handling a multi-neck bass and 12-string guitar. Sometimes it amazes me all over again to witness how every single sound from these songs can be made with a group of just five people. Listening to the records, it is so layered that it always feels like it should be so much more.

Once the final song was over and the dust had settled, the encore came. I couldn’t believe my ears when the band announced they would be playing Supper’s Ready from the album Foxtrot. What a treat! This was so much more than I ever could have expected!

So the twenty-three minute epic journey of apocalypse, as envisioned by Peter Gabriel forty four years earlier. The dulcet tones of the intro began, and everything sounded perfect. The mood in this small blues bar, filled to the brim with fans, was like nothing ever experienced before. All of us, I would hazard to say, knew this song in particular, Genesis’s masterpiece, and united by a common love we all fell under the song’s sway. It would not be an exaggeration to say it was a religious experience.

I have to give particular kudos to the drummer, Marco Fabbri, who tackled the section ‘Apocalypse in 9/8’ with aplomb. I have to admit I’ve never heard someone drumming in this time signature before, and it was so well handled. I also really liked the Gretsch kit, a callback to the kits Phil Collins used in this era, and what was interesting and probably due to how small the venue was (and possibly the fact I was right at the front too), was the hard, punchy tones that resulted – it was quite different to the recordings, but made for a nice offset against the taut vocals and dreamy keyboards and guitars.

I also feel that Simone Rossetti flourished in this song. It felt like the entire concert was leading up to this point – the release of those slightly-off-kilter but perfectly placed vocals. I think Gabriel ought to be so proud.

The clock ticked well over midnight as Supper’s Ready, and the entire gig along with it, drew to a finish. I have heard that The Watch return to Oslo every year, so I am looking forward to next year’s show already. Every time I see such a large crowd coming to attend prog-related shows in Oslo I become ecstatic, almost with disbelief at the fact that there are so many others who share this obsession with the somewhat odd and niche music I listened to in my childhood. It’s a good thing, and this particular experience is one I will remember.

Here’s a link to their album ‘Tracks from the Alps’:

Chrysalis

I’m writing one-armed for fear of awakening the devil in my shoulder blade. Seriously, this devil wields my shoulder like a knife.

If I could harness this power, I’m sure I could have been a fantastic performer for Cirque du Soleil. But real life has other plans, it seems. Ehlers Danlos is not an appealing illness, unless you like pain. And not the fun kind.

It’s been a trying week. I’m sure that the cortisol produced by extra stress has a part to play in how cruddy my joints feel, and this week there has been a lot of that in the mix. I’ve counted a couple major dislocations and around twenty five minor, on the right shoulder, since Tuesday. Bra straps are killer.

This week the theme for the Oslo Writer’s League Anthology 2016 was announced. It’s an incredibly fitting theme for me right now: the journey of metamorphosis.

Our minds, our identities are always in a state of metamorphosis, as we find out who we really are inside. Our bodies we tend to assume only have two real states of metamorphosis: the pubescent transition from child to adult, and the process of ‘becoming old’. That whole life span in between is seen almost as a static state of ‘adult’, when, for the body, it is anything but.

I have always been aware of my mental state changing, but the real shock to the body system came in 2009 when my Ehlers Danlos syndrome ‘advanced’, and left me feeling like Sophie from Howl’s Moving Castle, an old ninety-year-old woman in a twenty-two year old’s body. I imagine that others who have had health issues thrust upon them early in life have felt similarly, have felt the change of body like the change of seasons.

And now the time for transition is upon me again.

I will be having surgery soon, to reduce breast tissue and decrease the pressure put on my shoulders and ribs. I’m getting tired of being unable to even run up a flight of stairs without my bra pulling my shoulder joint out, or my rib pinging apart. I have scars around my torso even from the most expensive and well-fitted, soft bras. It’s almost like God knew I was going to be born with EDS and decided to double the difficulty level.

The difficulty setting is more so unwelcome considering my identity lies somewhat between genders. I’ve never felt a strong association with having a body that’s easily gender-definable. It feels like never owning any pairs of shoes that fit, so you’re always uncomfortable and getting blisters.

So the imminent changes are exciting. I’m not naïve about what these changes entail: I’m aware that the entire process of metamorphosis is itself a journey, not an endpoint. Changing one thing doesn’t mean you’re ‘finished’ as a person. I don’t really think people have a Final Form (contrary to the meme). All we have are things that change and concepts that we align ourselves closer to, like satellites around planets, when those concepts make sense for our current situation.

My current situation is going to change. I am going to find relief, when my ribs don’t pop out with every step, and I am going to feel more comfortable in my skin. It’s not going to cure everything, but it will be an important lesson.