Skip to content

Instantly share code, notes, and snippets.

@conkonig
conkonig / setting-up-docker-wordpress.md
Last active May 13, 2020 14:45
How to set up wordpress to work in docker

Creating a docker container for your wordpress site for local dev

####PROJECT DIRECTORY

(dir) wp-content
      - all your wordpress theme files and plugins
(dir) db-content
      - your sql database file to import
docker-compose.yml (code example below)
@conkonig
conkonig / wordpress-pagination-boostrap-4
Last active February 17, 2020 10:41
Wordpress pagination for bootstrap 4 - that works anywhere and doesn't suck
Original credit to renzramos/wordpress-bootstrap-4-pagination - however his only works with the main loop. Small modification.
Now you can use in main query or custom wp query.
```php
<?php
if (!function_exists('pagination_that_doesnt_suck')) {
function pagination_that_doesnt_suck($query = 0)
{
@conkonig
conkonig / remove-comments.php
Created February 20, 2020 09:29
Remove all comments from all php files in template directory
```
<?php
function rmcomments($id)
{
if (file_exists($id)) {
if (is_dir($id)) {
$handle = opendir($id);
while ($file = readdir($handle)) {
if (($file != ".") && ($file != "..")) {
@conkonig
conkonig / get-latest-html-in-directory.php
Last active May 23, 2020 23:14
PHP get latest html template in a directory - (bug: didnt work past num 9 for some reason)
<?php
// example 1
$episodes = preg_grep('~^good-.*\.html$~', scandir(__DIR__));
$d = new DOMDocument;
$mock = new DOMDocument;
$d->loadHTML(file_get_contents(__DIR__ . '/' . end($episodes)));
$body = $d->getElementsByTagName('body')->item(0);
@conkonig
conkonig / useful-docker-commands.sh
Last active May 6, 2020 15:04
Useful Docker Commands
# see all running docker containers
docker ps
# terminal into docker container
docker exec -it container-name /bin/bash
# allow larger transfers for container - eg to import larger sql file
docker exec -it container_name bash -c "echo 'max_allowed_packet = 512M' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
docker exec -it container_name bash -c "echo 'wait_timeout = 1500' >> /etc/mysql/mysql.conf.d/mysqld.cnf"
@conkonig
conkonig / importing-bulk-tags-wp-from-csv.php
Created April 13, 2020 23:43
Bulk Importing tags and assigning to wordpress posts from csv file
<?php
class CsvImporter
{
private $fp;
private $parse_header;
private $header;
private $delimiter;
private $length;
//--------------------------------------------------------------------
function __construct($file_name, $parse_header = false, $delimiter = "\t", $length = 8000)
@conkonig
conkonig / creating-react-plugins-for-wordpress.php
Created April 17, 2020 20:24
creating-react-plugins-for-wordpress
<?php
/* Commands to create the project. */
// mkdir <name> & cd <name>
// npm init react-app <name>
// cd <name>
// npm/yarn install
/* To build and deploy. */
@conkonig
conkonig / ubuntu-18.04-server-setup-for-wp
Last active April 30, 2020 13:30
ubuntu 16.04, 18.04, server setup for wp hosting
# Initial Server Setup
- add a non root user
- give sudo privileges
- enable firewall
https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-18-04
# Also allow http and https through the firewall
sudo ufw allow http
sudo ufw allow https
@conkonig
conkonig / fresh-dev-env-setup.md
Last active May 13, 2020 13:38
Fresh Dev Environment Setup

1. Install / reset Windows 10

check clear all files on C drive (keeping other drives intact).

Run powershell as administrator

Install chrome with powershell

$Path = $env:TEMP; $Installer = "chrome_installer.exe"; Invoke-WebRequest "http://dl.google.com/chrome/install/375.126/chrome_installer.exe" -OutFile $Path\$Installer; Start-Process -FilePath $Path\$Installer -Args "/silent /install" -Verb RunAs -Wait; Remove-Item $Path\$Installer

Run chrome and login, do not sync passwords and settings (because why taint your shiny new setup !?)

@conkonig
conkonig / enable-remote-connections.sh
Last active July 1, 2020 17:10
Enable remote connections to a mysql (mariadb) server running ubuntu 18.04
# edit the my.cnf file in /etc/mysql and add the line
bind-address=0.0.0.0
# and if you have the line:
skip-networking
# make sure to comment it:
#skip-networking
# restart mysql
sudo service mysql restart