Skip to content

Instantly share code, notes, and snippets.

@k1sul1
k1sul1 / README.md
Last active December 12, 2019 15:16
CircleCI pipeline for WordPress projects running on Seravo/wordpress project template

CircleCI pipeline for WordPress projects running on Seravo/wordpress project template

Builds your theme, installs composer dependencies and deploys it to production / staging.

How?

Create .circleci folder in project root, and add config.yml in it. Edit the config a bit. Use search & replace to substitute $PROD_SSH_PORT to the SSH port number and $THEMENAME to the folder name of your theme.

Login to CircleCI and add a project using the menu in the sidebar. Click "Set Up Project" on the project you want to setup CI for.

@k1sul1
k1sul1 / index.php
Created August 30, 2018 16:36
WordPress: Block plugin activation if PHP or WordPress version is too low
<?php
register_activation_hook(__FILE__, function () {
$php_version = phpversion();
$wp_version = $GLOBALS["wp_version"];
$is_56 = version_compare($php_version, 5.6, ">=");
$is_70 = version_compare($php_version, 7.0, ">=");
$php_ok = $is_56 || $is_70;
$wp_ok = version_compare($wp_version, 4.7, ">=");
$message = "";
@k1sul1
k1sul1 / routeWatcher.js
Created January 1, 2018 12:26
node script that watches a directory and marks whether the files listed exist or not, conditional component loading
const fs = require('fs')
const watch = require('node-watch')
const routes = require('./routes.json')
const route = {
write(type, name) {
const types = ['enable', 'disable']
const state = types.indexOf(type) > -1 ? [true, false][types.indexOf(type)] : new Error('Wat?')
const fresh = require('./routes.json')
@k1sul1
k1sul1 / WP Libre Form ohjeistus.html
Created June 6, 2017 08:42
Ohjeet lomakkeiden hallintaan.
<!-- Tämä on HTML kommentti, se ei näy sivustolla.
Input-elementeillä (<input>, <select></select>, <textarea></textarea>) on muutama attribuutti jotka vaikuttavat siihen miten elementti käyttäytyy.
Type-attribuutti nimensä mukaisesti vaikuttaa elementin tyyppiin. Yleisimmät tyypit ja mitä ne tekevät:
text: Oletus, tavallinen tekstikenttä, esimerkiksi nimeä varten.
email: Sähköpostikenttä, jos haluat vastaajan sähköpostiosoitteen, käytä tätä. Yhdistettynä required attribuutin kanssa validoi että kentässä on sähköpostiosoite ennen lomakkeen tallentamista.
checkbox: Rasti ruutuun kenttä. Jos vastaaja voi valita monta vaihtoehtoa, käytä tätä. Huomaa että tämän tyypin kanssa name-attribuutissa pitää olla arvon jälkeen [] jotta kaikki vastaukset tallentuvat.
radio: Valitse yksi kenttä. Antaa käyttäjän valita vain yhden vaihtoehdon monesta.
@k1sul1
k1sul1 / plugin-cpt-with-templates.php
Created May 30, 2017 14:09
Way to add custom post types with template support directly from plugin
<?php
/*
Plugin Name: Plugin cpt with templates
Author: Christian Nikkanen
*/
defined("ABSPATH") or die("Wat r u doing?");
add_action("init", function() {
register_post_type("blog", [
@k1sul1
k1sul1 / after_install.js
Created November 30, 2016 15:27
Script to run after npm install, sets variables to .env file, and the variables can be later utilized.
const fs = require('fs');
const nl = require('os').EOL;
const LineByLineReader = require('line-by-line');
const cp = require('child_process');
afterInstall('.env', 'utf8');
function afterInstall(filename, encoding) {
const envVars = {
'GIT_COMMIT_HASH': {
@k1sul1
k1sul1 / recursive-link-box.php
Last active November 17, 2016 17:44
Recursive PHP function that eats through links and creates a box with them.
@k1sul1
k1sul1 / compile-stylus-in-admin.php
Last active October 31, 2016 13:05
Compile Stylus at runtime
<?php
add_action('admin_footer', function() {
$screen = get_current_screen();
if ($screen->base === 'post') {
?>
<script src="http://stylus-lang.com/try/stylus.min.js"></script>
<!-- Please DO NOT hotlink to the file in your code.
Instead, save it locally and refer to the local file instead. -->
@k1sul1
k1sul1 / inherit-parent-page-template.php
Last active October 23, 2017 07:38
Filter to allow subpages to inherit parent page template
<?php
add_filter('page_template', function(){
$page = get_queried_object();
$parent_id = $page->post_parent;
$templates = array();
$template = get_post_meta($page->ID, "_wp_page_template", true);
if (!empty($template) && $template !== "default") {
// If the page has a page template set, use that and return immediately.
return locate_template($template);
@k1sul1
k1sul1 / wp-cli-vagrant.bash
Created October 17, 2016 11:08
Vagrant enabled wp-cli in bash
# Add to your .bashrc or whatever.
# Use wp-cli like you normally would: wp plugin activate duplicate-post
function wp {
if [ -f Vagrantfile ]; then
echo "Running wp-cli in Vagrant..."
vagrant ssh --command "wp $(echo $@)"
fi
}