Skip to content

Instantly share code, notes, and snippets.

@jlleblanc
jlleblanc / gist:2926803
Created June 13, 2012 22:09
Using JImage to create square profile pictures in two sizes, regardless of the original's orientation
<?php
$image = new JImage('/path/to/original.jpg');
$height = $image->getHeight();
$width = $image->getWidth();
if ($height > $width) {
$crop_square = $width;
$crop_top = ($height - $width) / 2;
@yojance
yojance / functions.php
Created January 31, 2015 18:51
Removing a Product From The Cart Programatically In WooCommerce
<?php
add_action( 'template_redirect', 'remove_product_from_cart' );
function remove_product_from_cart() {
// Run only in the Cart or Checkout Page
if( is_cart() || is_checkout() ) {
// Set the product ID to remove
$prod_to_remove = 56;
// Cycle through each product in the cart
foreach( WC()->cart->cart_contents as $prod_in_cart ) {
@marsjaninzmarsa
marsjaninzmarsa / version-string.php
Created January 2, 2020 05:53
My solution for cache busting in WordPress (drop-in to `/mu-plugins/` in Bedrock).
<?php
/**
* Replaces query version in registered scripts or styles with file modified time
*
* @link https://wordpress.stackexchange.com/a/346024/51130 based on
*
* @param $src
*
* @return string
// gulpfile.js
// Initialize modules
const gulp = require('gulp');
// Importing all the Gulp-related packages we want to use
const concat = require('gulp-concat');
const sourcemaps = require('gulp-sourcemaps');
const sass = require('gulp-sass');
//const browserSync = require('browser-sync');
//const server = browserSync.create();
const child = require('child_process');
<?php
function renderForm ($endpoint) {
// get the data from the API and convert it to a PHP object
$formResult = file_get_contents($endpoint);
$formContent = json_decode($formResult);
$formFields = $formContent->fields;
// start building the DOM
$dom = new DOMDocument();
$form = $dom->createElement('form');
{
"alignleft": {
"selector": "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",
"classes": "left"
},
"aligncenter": {
"selector": "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",
"classes": "center"
},
"alignright": {
@nternetinspired
nternetinspired / gist:7482445
Last active February 24, 2022 17:20
Load Disqus comments only on demand if you give a shit about page weight and your visitors. Even with no comments, i.e. an empty comment form, calling Disqus will load an extra 226Kb. If your page has comments this can be far higher. This Gist accompanies my blog post: http://internet-inspired.com/wrote/load-disqus-on-demand/
// Requires jQuery of course.
$(document).ready(function() {
$('.show-comments').on('click', function(){
var disqus_shortname = 'YOUR-DISQUS-USERNAME'; // Replace this value with *your* username.
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
@alexandreelise
alexandreelise / htmlhelper-select-options-with-empty-default.php
Created September 26, 2020 01:03
Code snippet for HTMLHelper select options with empty default value
<label for="demo">Demo</label>
<select id="demo" name="demo">
<?php array_unshift($this->myExampleOptionsArray, null); ?>
<?php echo HTMLHelper::_('select.options', $this->myExampleOptionsArray, 'value', 'text', $this->selectedOptionValue ?? '');?>
</select>
@alexandreelise
alexandreelise / add-custom-fields-to-core-modules-j3x.php
Created November 26, 2019 09:23
Add custom fields to core modules in Joomla! 3
<?php
defined('_JEXEC') or die;
?>
<div class="latestnews">
<ul class="list-group list-group-flush">
<?php foreach ($list as $item) : $image = json_decode($item->images); ?>
<?php
// most important part
// context:
// for articles: com_content.article
@jakebathman
jakebathman / jsonToCsv.php
Last active June 5, 2022 21:02 — forked from Kostanos/json-to-csv.php
A function to convert a JSON string (or a PHP array) to a CSV file or CSV string echoed to the browser
<?php
/*
*
* Based on (forked from) the work by https://gist.github.com/Kostanos
*
* This revision allows the PHP file to be included/required in another PHP file and called as a function, rather than focusing on command line usage.
*
* Convert JSON file to CSV and output it.
*
* JSON should be an array of objects, dictionaries with simple data structure