Skip to content

Instantly share code, notes, and snippets.

View EdwardBock's full-sized avatar
🚒

Edward EdwardBock

🚒
View GitHub Profile
# First, install all of the things
sudo su
apt-get update
apt-get install nginx
/etc/init.d/nginx start
apt-get install python-dev
apt-get install python-pip
apt-get install libjpeg-dev libpng-dev libtiff-dev libjasper-dev libgtk2.0-dev python-numpy python-pycurl libwebp-dev python-opencv libjpeg-progs
ln -s /usr/lib/x86_64-linux-gnu/libjpeg.so /usr/lib
@EdwardBock
EdwardBock / reading-time-database.php
Last active November 26, 2021 06:05
ReadingTime Database Class
<?php
namespace PublicFunctionOrg\WordPress\ReadingTime;
class Database {
public function __construct(){
global $wpdb;
$this->wpdb = $wpdb;
$this->table = $this->wpdb->prefix."posts_reading_time";
}
@EdwardBock
EdwardBock / reading-time-wp-query-extension.php
Last active October 15, 2021 01:06
ReadingTime WP_Query Extension
<?php
namespace PublicFunctionOrg/WordPress/ReadingTime;
add_filter('posts_where', function($where, $wp_query){
$readingTime = $wp_query->get("reading_time", false);
if(is_array($readingTime) && isset($readingTime["compare"]) && isset($readingTime["value"]) ){
$db = new Database();
$value = intval($readingTime["value"]);
$compare = $readingTime["compare"]; // should be sanitized
<?php
namespace PublicFunctionOrg\WordPress\Schedule;
const SCHEDULE_ACTION = "public_function_org_schedule";
function init(){
if(!wp_next_scheduled(SCHEDULE_ACTION)){
wp_schedule_event(time(), 'hourly', SCHEDULE_ACTION);
}
@EdwardBock
EdwardBock / wp-dont-add-gutenberg-script-like-this.php
Last active May 18, 2021 12:37
DON'T: Gutenberg add script
<?php
namespace PublicFunctionOrg\WordPress\Gutenberg;
const HANDLE = "my-gutenberg-script";
add_action( 'enqueue_block_editor_assets', function () {
wp_enqueue_script(
HANDLE,
plugin_dir_url(__FILE__) . "/js/my-gutenberg-script.js",
<?php
namespace PublicFunctionOrg\WordPress\Gutenberg;
const HANDLE = "my-gutenberg-script";
add_action( 'enqueue_block_editor_assets', function () {
$info = include plugin_dir_path(__FILE__) . "/js/my-gutenberg-script.asset.php";
wp_enqueue_script(
HANDLE,
@EdwardBock
EdwardBock / Repository.php
Last active May 18, 2021 12:36
Repository for a service that fetches additional data to a post
<?php
namespace PublicFunctionOrg\WordPress;
class Repsitory {
public function __construct($service){
$this->service = $service; // service api implementation class
}
@EdwardBock
EdwardBock / Templates.php
Last active July 22, 2021 20:25
Locate theme template path
<?php
namespace PublicFunctionOrg\WordPress;
class Templates {
private $theme_dir = "/my-plugin-templates/";
public function get_template_path($template){
if ( $overridden_template = locate_template( $this->theme_dir.$template ) ) {
return $overridden_template;
}
return false;
@EdwardBock
EdwardBock / Templates.php
Last active July 22, 2021 14:11
Parent theme template path
<?php
namespace PublicFunctionOrg\WordPress;
class Templates {
private $theme_dir = "/my-plugin-templates/";
public function get_template_path($template){
$path = $this->theme_dir.$template;
if( is_file( get_template_directory().$path)){
return get_template_directory().$path;
}
@EdwardBock
EdwardBock / Templates.php
Last active July 22, 2021 20:19
Provide template paths by filter
<?php
namespace PublicFunctionOrg\WordPress;
class Templates {
public function get_template_path($template){
$paths = apply_filters("my_plugin_add_template_paths", []);
foreach ($paths as $path){
if(is_file("$path/$template")){
return "$path/$template";
}
}