Skip to content

Instantly share code, notes, and snippets.

View JRyven's full-sized avatar

James Ryven Valeii JRyven

View GitHub Profile
@mizner
mizner / remote-images.php
Created September 15, 2019 21:03
MU Plugin: Remote Images
<?php
/**
* Plugin Name: Remote Images
*/
if(!in_array($_SERVER['SERVER_NAME'], ['EXAMPLELOCALDOMAIN.test', 'ANOTHEREXAMPLE.test'])) {
return;
}
@joshuacerbito
joshuacerbito / pre-fill-acf-repeater.php
Last active August 29, 2023 07:51
Pre-Fill Wordpress ACF Repeater Field
<?php
// Pre-fills a repeater field (and its sub-fields) with default values
// - assuming we have a Repeater field with the key "repeater_field_123"
// - with the sub-fields "sub_field_1" and "sub_field_2"
function prefill_repeater( $field ) {
if ($field['value'] === false) {
$field['value'] = array(
array(
@timothyjensen
timothyjensen / jquery.js
Last active November 3, 2020 10:01
Wrap sibling groups using jQuery.
$(document).ready(function() {
$(':not(.sibling-element) + .sibling-element, * > .sibling-element:first-of-type').
each(function() {
$(this).
nextUntil(':not(.sibling-element)').
addBack().
wrapAll('<div class="sibling-wrapper" />');
});
});
@hijonathan
hijonathan / form.html
Last active August 1, 2023 19:14
Submit a HubSpot form with AJAX without redirecting the user.
<form class='form-inline' id='my-custom-form'>
<div class="form-group">
<input type='email' class='form-control' placeholder='Your email address' required>
</div>
<button class="btn btn-primary" type='submit'>Sign up</button>
</form>
<!-- Actual form that gets submitted to HubSpot -->
<div class="hidden" id='hubspot-form'>
<script charset="utf-8" src="//js.hsforms.net/forms/current.js"></script>
@codeguy
codeguy / slugify.js
Created September 24, 2013 13:19
Create slug from string in Javascript
function string_to_slug (str) {
str = str.replace(/^\s+|\s+$/g, ''); // trim
str = str.toLowerCase();
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñç·/_,:;";
var to = "aaaaeeeeiiiioooouuuunc------";
for (var i=0, l=from.length ; i<l ; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}