Skip to content

Instantly share code, notes, and snippets.

@woodwardtw
woodwardtw / index.php
Created January 26, 2024 15:19
example helper plugin for Skidmore
<?php
/*
Plugin Name: Skidmore Multisite Helpers
Plugin URI: https://github.com/
Description: A network activated plugin used to house small functions that apply to all sites.
Version: 1.0
Author: Tom Woodward et al.
Author URI: https://tomwoodward.us
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
<?php
class td_block1_widget extends td_block_widget {
var $td_block_id = 'td_block_1'; // change only the block id, the rest is autogenerated
}
add_action('widgets_init', function (){
register_widget("td_block1_widget");
}
@woodwardtw
woodwardtw / import_pressbooks_glossary.php
Created April 18, 2023 12:19
Import Pressbooks Glossary Items from CSV. Doesn't do location currently, but could if the data structure gets shared.
function pb_add_glossary_item(){
if (($handle = fopen(plugin_dir_path(__FILE__) . "test.csv", "r")) !== FALSE) {
while (($data = fgetcsv($handle, 1000, "\t")) !== FALSE) {
ini_set('auto_detect_line_endings',TRUE);
foreach ($data as $key => $line) {
// code...
$data_array = explode(",", $line);
$args = array(
'post_title' => $data_array[0],
'post_content' => $data_array[1],
@woodwardtw
woodwardtw / gdp.py
Created March 31, 2023 13:37
China vs US GDP comparison from 2016-2020 generated by free version of ChatGPT in March 2023
import pandas as pd
import matplotlib.pyplot as plt
# Create a dictionary of GDP data for the USA and China from 2016 to 2020
data = {
'Country': ['USA', 'China'],
'2016': [18624475, 11233273],
'2017': [19542968, 12408149],
'2018': [20580518, 13608152],
'2019': [21433226, 14271038],
@woodwardtw
woodwardtw / wp-options-page-count-snippet.php
Last active February 23, 2023 17:45
set the page count in wp_options
<?php
//UPDATE wp_options with page count
function wmps_page_count(){
$page_count = wp_count_posts('page')->publish;
if ( get_option( 'wpms_data_pages_count' ) !== false ) {
update_option('wpms_data_pages_count', $page_count);
} else {
add_option('wpms_data_pages_count', $page_count);
}
}
@woodwardtw
woodwardtw / more-json-info.php
Created November 8, 2022 13:41
add useful usage data to the base JSON of the WordPress site
/*---------------------------------JSON MOD FOR ADDITIONAL SITE INFO----------------------------------*/
function extraJsonData($response){
$blog_id = get_current_blog_id();
$blog_details = get_blog_details($blog_id);
$data = $response->data;
$data['created'] =$blog_details->registered;
$data['last_updated'] =$blog_details->last_updated;
$data['post_count'] =$blog_details->post_count;
$data['page_count'] = wp_count_posts('page','publish');
@woodwardtw
woodwardtw / wp-config.php
Created October 13, 2022 12:48
wp config shush and show
/**
* these are two alternative settings for wp-config.php don't use both!
**/
/**
* super shush any errors or warnings
**/
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
@woodwardtw
woodwardtw / catalog.css
Last active January 27, 2023 13:08
Middlebury Canvas Catalog Custom CSS
h1,
h2,
h3,
h4,
h5,
.h1 {
font-family: Domine, georgia, serif;
}
#app-header {
@woodwardtw
woodwardtw / config.json
Last active August 16, 2023 12:37
IIIF manifest in themes > theme name > asset > universal viewer - update on Aug 16 to hide top bar tools (which failed)
{
"options": {
"bookmarkThumbHeight": 150,
"bookmarkThumbWidth": 90,
"leftPanelEnabled": true,
"limitLocales": true,
"minWidthBreakPoint": 610,
"navigatorEnabled": true,
"openTemplate": "http://universalviewer.io?manifest={0}",
"overrideFullScreen": false,
@woodwardtw
woodwardtw / example-pything-dooo.py
Created August 19, 2022 14:38
just a poc showing how the php stuff might get written around the csv data
# full path
data = open("../../test/test.php", "w")
phpheader = ["<?php \n", "defined( 'ABSPATH' ) || exit; \n", "$bar = '"]
data.writelines(phpheader)
# regular csv stuff to populate the variable