Tag: PHP
-
How Frontenberg Works
How does Frontenberg work? I’m going to walk through what I did to build a frontend Gutenberg site, the problems encountered, and the fixes
-
Writing a WP REST API endpoint in 2 minutes
I need to write a REST API endpoint, but lets assume we know nothing about REST APIs.
-
The Correct Way to Build Plugins – The Bitter Truth
What is the correct way to build a WordPress plugin, the official, recommended way that was always intended? The idealised standard? The Problem Plugins are not discrete modules in the WordPress world. Their isolation exists only on the filesystem, but once that code is loaded into memory it shares the same space as Core itself.…
-
Embedding PHP in Content
Would you like to embed and run some PHP code in a blog post? Need to include a PHP file in a sidebar widget? Recently discovered this curious plugin? Don’t, you’re about to make an awful mistake. Lets walk through why it’s bad, and what you should be doing instead. Why Might Somebody Embed PHP? Perhaps you…
-
WordPress and Composer TLDR
There’s a few questions I’m commonly asked about using composer + WordPress. Here they are in a super short form FAQ: To install a composer project, run: composer install To update a composer project, run: composer update Install WordPress in a folder composer require johnpbloch/wordpress @stable or in your composer.json add: { “require” : { “johnpbloch/wordpress”: “@stable”…
-
Root Composition in WordPress Plugins
When I build a WordPress plugin, I use several methods to structure things that help me greatly, all of which stem from root composition. I’m going to expand on what that is and how I use it. Every plugin has a root file that contains the plugin header comment, and gets loaded by WordPress. This…
-
WordPress Bash Magic
I’ve been doing a lot of bash scripting with WordPress, especially with WP CLI. Here are some snippets I found useful. All my scripts assume a standard wp-config.php with DEFINE() statements and no unusual logic structures. A rogue constant with the name DB_NAME may throw things off without some modification. Getting the Database table prefix If you…
-
Calling Constructors
Take a look at this code, found inside the Jetpack Post Views plugin: function Jetpack_Post_Views() { $this->__construct(); } Here an object is calling its own constructor. But what’s wrong with it? The General rule for calling __construct: The only occasion it is okay to call a constructor method directly, is in a child class that…
-
Use of mysql_connect in WordPress
-
&$this
Take a look at this code, found inside a PHP class or object: add_action( &$this, ‘functionname’ ); This looks familiar, and can be found in many themes and plugins. But what’s wrong with it? It’s PHP4 code in a PHP5 world. General PHP rule for add_action: When creating a callable, never use &$this, use $this instead…
-
ComposerPress
Curious about Composer but already have a WordPress site? Not to worry, I have you covered. Presenting Composerpress: Composerpress is a plugin that analyses your WordPress install, and generates a composer.json file you can then use retro-actively. This file acts as an inventory of dependencies, plugins, etc that are needed to set up a site, and…
-
add_action considered harmful
I’m going to argue that add_action is actually a more elaborate version of goto hidden in plain sight, an anti-pattern, that it encourages unstructured programming, and obscures dependencies between code by providing the illusion of structured code, and encouraging spaghetti architecture. The Dangers of Goto Firstly what is a goto statement? goto (GOTO, GO TO or other case combinations,…
-
Alternative Post Loops
We all know the standard post loop in every template, but what if we did something slightly different? Lets begin with the standard main loop we all know: View the code on Gist. There’s a lot of boilerplate there, what if we could reduce it down? Lets try using a feature of PHP 5 called…
-
Bulk Entry Plugin Release
I’ve released a new plugin for bulk creation of posts! Other plugins on the wordpress.org repository handled a strict subset of functionality such as posts and categories ( but not pages or tags), while others simply didn’t work. I set out to build an alternative that was extendable, reliable, and could handle custom post types…
-
Clients Who Upload Huge Photos & Decompression Bombs
Sometimes a client makes a blog post, and puts a photo in the middle. All good so far, until you realise the client has dragged an image from their brand new camera expecting a 10 Megapixel image to work. This is usually when people start talking about upload max file size limits, but this is…
-
Realisations
Some pretty simple things people don’t realise when dealing with WordPress Nobody Remembers the API A lot of people worry that they don’t know the API, that it will take them a long time to memorise everything. Nobody memorises the API. It changes too fast, it’s too big, and it’s a waste of time when…
-
WordPress: Necessary Reading
WordPress APIs In brief, WordPress hooks enable you to change how WordPress behaves without editing any core files. Because you leave the WordPress files untouched, you can painlessly upgrade your blog with each new version of WordPress. It’s this hooks architecture that makes WordPress the best blogging solution. – Adam Brown Adam Browns Hooks &…
-
Auto-Grabbing Order Data From SellWire
I’m going to demonstrate how to access order data programmatically from SellWire for a product. I’m going to be using this for building automation. Why Not Use SellWire APIs? At the moment SellWire provides no APIs, but they are planned. Until they are, some method of building automation is needed. To do this, I’ve programmed…