Skip to content

Instantly share code, notes, and snippets.

@jordymeow
jordymeow / sse.php
Created May 27, 2023 01:28
SSE (Server-Sent Events) with PHP and JS / Streaming with PHP
<?php
// Various links
// https://serverfault.com/questions/488767/how-do-i-enable-php-s-flush-with-nginxphp-fpm
// https://stackoverflow.com/questions/72394213/nginx-configuration-for-server-sent-event
// https://serverfault.com/questions/801628/for-server-sent-events-sse-what-nginx-proxy-configuration-is-appropriate
// https://qiita.com/okumurakengo/items/cbe6b3717b95944083a1 (in Japanese)
// If '?SSE' is set, send Server-Sent events, otherwise we'll display the page.
if ( isset( $_GET['SSE'] ) ) {
@BruceMcKinnon
BruceMcKinnon / functions.php
Created July 30, 2020 03:57
Gravity Forms - Button to delete file uploads for an entry
add_filter( 'gform_entry_detail_meta_boxes', 'add_delete_attachment_meta_box', 10, 3 );
function add_delete_attachment_meta_box( $meta_boxes, $entry, $form ) {
$my_form_id = 3;
if ( $form['id'] == $my_form_id ) {
if ( ! isset( $meta_boxes['payment'] ) ) {
$meta_boxes['payment'] = array(
'title' => esc_html__( 'Delete Attachments', 'gravityforms' ),
@zackkatz
zackkatz / edd-run-a-sale.php
Last active June 19, 2019 21:32
Easily run a sale in Easy Digital Downloads. This code applies a coupon globally.
<?php
// When not running a sale, just RETURN here. (but if you forget, no problem...)
# return;
// Pass the coupon code that you want applied as the global sale coupon
new GV_Theme_Sale( 'SOLSTICE2019' );
class GV_Theme_Sale {
@jazzsequence
jazzsequence / how-i-work-template.md
Created October 30, 2018 18:20
Template for How I Like to Work posts

How I work

This is my own interpretation of how I like to work, feedback welcome! Especially if my own view of how I think I like to work doesn't match your experience of how it seems I like to work!

When I work

@bradyvercher
bradyvercher / register-plugin-icons.php
Created October 4, 2017 22:30
Register icons to display on the Manage Plugins screen for plugins that aren't in the WordPress.org directory.
<?php
/**
* Register plugin icons.
*
* WordPress 4.9 introduced icons in the list table on the Manage Plugins
* screen. The icons are pulled from the W.org update API. If an icon isn't
* available, a generic plugin Dashicon is shown instead.
*
* @param array $value Plugin update data.
* @return array
@thierrypigot
thierrypigot / gravity-forms.php
Last active November 8, 2024 11:28
Permet d'interpréter les caractères html dans le label des fields.
<?php
// [update : sécurité des sorties]
add_filter( 'gform_field_content', 'tp_subsection_field', 10, 5 );
function tp_subsection_field( $content, $field, $value, $lead_id, $form_id )
{
// Limiter les balises HTML autorisées dans les labels (gras, images, etc.)
$allowed_html = array(
'strong' => array(),
'em' => array(),
'b' => array(),
@dbspringer
dbspringer / plugin.php
Created May 7, 2015 21:33
Front-end Media Example plugin
<?php
/**
* Plugin Name: Front-end Media Example
* Plugin URI: http://derekspringer.wordpress.com
* Description: An example of adding the media loader on the front-end.
* Version: 0.1
* Author: Derek Springer
* Author URI: http://derekspringer.wordpress.com
* License: GPL-2.0+
@mcaskill
mcaskill / Function.Date-Format-Conversion.php
Last active February 6, 2024 11:22
PHP : Translate date/time format between `date()` and `strftime()`
<?php
/**
* Convert date/time format between `date()` and `strftime()`
*
* Timezone conversion is done for Unix. Windows users must exchange %z and %Z.
*
* Unsupported date formats : S, n, t, L, B, G, u, e, I, P, Z, c, r
* Unsupported strftime formats : %U, %W, %C, %g, %r, %R, %T, %X, %c, %D, %F, %x
*
@vanbernaert
vanbernaert / gist:cfc80b5d702c5d290658
Last active August 29, 2015 14:17
Gravity forms, replace <input type="submit> element with a <button> element
// credits: https://github.com/CFXd
function gf_make_submit_input_into_a_button_element($button_input, $form) {
//save attribute string to $button_match[1]
preg_match("/<input([^\/>]*)(\s\/)*>/", $button_input, $button_match);
//remove value attribute
$button_atts = str_replace("value='".$form['button']['text']."' ", "", $button_match[1]);
return '<button '.$button_atts.'>'.$form['button']['text'].'<i class="fa fa-refresh"></i></button>';