Skip to content

Instantly share code, notes, and snippets.

View stevygee's full-sized avatar

Stefan Grassberger stevygee

View GitHub Profile
@stevygee
stevygee / wp-env-set-max-upload-size.txt
Created January 26, 2022 16:49
Increase the maximum upload size for WordPress using wp-env
wp-env run cli vi .htaccess
press "i"
add the following:
php_value memory_limit 128M
php_value post_max_size 128M
php_value upload_max_filesize 128M
press "ESC"
type :wq to save
@stevygee
stevygee / google-trends.php
Created November 4, 2021 19:17
x-fran/g-trends
@stevygee
stevygee / wp-list-enqueued-scripts-styles.php
Created March 4, 2021 11:07
List all enqueued scripts and styles on the current page. This won't work as an REST API endpoint, unfortunately. If that's your goal, use Frontity's head tags plugin and disable filtering of scripts and styles.
global $enqueued_scripts;
global $enqueued_styles;
function sg_format_asset_url( $src, $ver ) {
// Fallback to WP version, if not set
$ver = $ver ? $ver : get_bloginfo( 'version', 'display' );
// Append site root URL, if missing
$url = strpos( $src, get_home_url() ) !== false ? $src : get_home_url() . $src;
@stevygee
stevygee / sdm-group-logs-csv.php
Created April 22, 2020 12:34
Simple Download Monitor: Filter download logs by date range, group by download ID and count number of downloads
<?php
function sdm_export_download_logs_to_csv( $from, $to ) {
// Check for valid dates (yyyy-mm-dd)
$date_pattern = '/^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/';
if ( 1 !== preg_match( $date_pattern, $from ) || 1 !== preg_match( $date_pattern, $to ) ) {
return false;
}
// Check for valid date range
if( strtotime( $from ) > strtotime( $to ) ) {
@stevygee
stevygee / wp2static_v7_wpml.php
Last active May 10, 2022 10:04
Add WPML translations to WP2Static v7
<?php
function sg_get_translated_posts_urls() {
$default_lang = apply_filters( 'wpml_default_language', NULL );
$ids = get_posts( array(
'fields' => 'ids',
'post_type' => array( 'post', 'page' ),
'numberposts' => -1,
'suppress_filters' => true, // Get posts in all languages
) );
@stevygee
stevygee / translation-localize-to-wpml.py
Last active August 28, 2019 12:30
Process Localise XLIFF exports for importing back into WPML by inserting translation job IDs from source files
# coding=utf-8
import os
import argparse
from glob import glob
import xml.etree.ElementTree as ET
import zipfile
namespace = 'urn:oasis:names:tc:xliff:document:1.2'
namespaces = {'xliff': namespace}
@stevygee
stevygee / the-events-calendar-import-match-custom-field.php
Created September 12, 2018 16:22
The Events Calendar CSV import: Find matching event solely by a custom field. Replace the function match_existing_post() in src\Tribe\Importer\File_Importer_Events.php. In the importer you need to select the column to match by as 'Cost'.
<?php
protected function match_existing_post( array $record ) {
global $post;
$import_id = $this->get_value_by_key( $record, 'event_cost' );
if ( ! empty( $import_id ) && is_numeric( $import_id ) ) {
$args = array(
'post_status' => 'any',
'post_type' => 'any', // circumvent tribe_events filtering of past events
'posts_per_page' => 1,
@stevygee
stevygee / the-events-calendar-import-match-venue.php
Created March 26, 2018 13:29
The Events Calendar CSV import: Find matching event with same venue by adding this to src\Tribe\Importer\File_Importer_Events.php on line 56.
// ...
// Match venue
$meta_query[] = array(
'key' => '_EventVenueID',
'value' => $this->find_matching_venue_id( $record ),
);
// ...
@stevygee
stevygee / phombie-flow-notification.json
Last active March 25, 2018 15:08
Data format for in-game notifications in Phombie Flow
{
"notifications": [
{
"service": "email",
"subject": "International Lotterie",
"content": "Offizieller Benachricht: Sie habe 1 Millon gewonnen!",
"onDelete": "0",
"onRead": "2"
}
]
@stevygee
stevygee / draw-video-game-loop.js
Last active March 25, 2018 14:54
Two approaches to draw the current frame from video element on a canvas in regular intervals
function draw() { // Global function for displaying the game, this is called in a game loop
drawVideo(currentVideo);
// ... display other elements ...
}