Skip to content

Instantly share code, notes, and snippets.

View makbeta's full-sized avatar

makbeta makbeta

View GitHub Profile
@makbeta
makbeta / jquery-wrap-text-nodes.js
Created January 16, 2024 19:40
Wrap DOM text nodes into spans
const $element = $('#my-element');
const $nodes = $element.contents();
$nodes.each(function(index, element) {
const $el = $(element);
if(element.nodeType === 3 && $.trim($el.text())) {
$el.wrap('<span class="orphan" />');
}
});
@makbeta
makbeta / wordpress-security-headers-2023.php
Last active December 22, 2023 22:12
WordPress security header settings for 2023
<?php
// Define helper functions
/**
* Changes default WordPress headers to a custom ones
*/
function change_cors_headers() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', 'send_cors_headers' );
}
@makbeta
makbeta / move-rename.sh
Last active November 18, 2023 20:22
Organize files with date name format into subfolders
# Handy script to help move images created with a phone camera into date-based folders
# Accepts files in the format yyyymmddhhjjss.*
# creates subdirectories yyyy-mm-dd
# moves files into subdirectories renames them to yyyy-mm-dd-hh-jj-ss.* (extension is preserved)
# Tested against Bash v3.2.57, the expressions are overly verbose as the compact expressions
# do not produce the same results, in this environment
if [[ $(ls | grep -E "[0-9]{8}_.*") ]]; then
for name in [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]_*.*; do
echo "$name"
new_dir=$(echo $name | sed -e 's/\([0-9][0-9][0-9][0-9]\)\([0-9][0-9]\)\([0-9][0-9]\)_\(.*\)/\1-\2-\3/g')
@makbeta
makbeta / wp-tml-custom-field-registration.php
Created June 24, 2013 20:19
WordPress: Add custom profile fields to a Theme My Login registration form
/*
1. create custom user fields with wordpress (see https://gist.github.com/makbeta/5851535 )
2. clone `register-form.php` from /wp-content/plugins/theme-my-login/templates to your theme
3. Add your new field to the registration template
*/
<p>
<label for="subscription">Customer ID</label>
<input type="text" name="subscription" id="subscription<?php $template->the_instance(); ?>" class="input" value="<?php $template->the_posted_value( 'subscription' ); ?>" size="20" /><br />
<span class="description">Please enter your customer ID.</span>
@makbeta
makbeta / d8-strip-version-from-info-yml.php
Last active August 26, 2019 15:29
Drupal 8: Strip hard-set version number from core modules and themes
<?php
/**
* Quick script for stripping drupal hard set version number in .info.yml files that cause
* Drupal to incorrectly show status updates.
* Script is based on https://gist.github.com/joshkoenig/2588420
*
* Run in the drupal root, or specify the root as an argument. E.g.:
*
* php d8-strip-version-from-info-yml.php path/to/drupal
*
@makbeta
makbeta / country-code-top-level-domains.json
Last active October 23, 2018 21:50
A list of country code top-level domains and country names. Information is taken from https://icannwiki.org/Country_code_top-level_domain
let countryCodeTopLevelDomains=[
{
"code": ".ac",
"country": "Ascension Island"
},
{
"code": ".ad",
"country": "Andorra"
},
{
@makbeta
makbeta / clo-body-class.html
Last active October 18, 2018 14:33
Luminate Online: body class based on application
class="[[T9:
[[?x[[S4]]x::x41x::ecards::]]
[[?x[[S4]]x::x81x::profile::]]
[[?x[[S4]]x::x82x::interests::]]
[[?x[[S4]]x::x83x::unsubscribe::]]
[[?x[[S4]]x::x85x::preferences::]]
[[?x[[S4]]x::x5x::tell-a-friend::]]
[[?x[[S4]]x::x186x::service-center::]]
[[?x[[S4]]x::x10x::user-login [[?x[[S334:CMD]]x::xForgotPasswordx::password-recovery ::]][[?x[[S334:CMD]]x::xForgotLoginx::user-name-recovery ::]]::]]
@makbeta
makbeta / wp-profile-fields.php
Last active December 16, 2017 10:47
WordPress: Adding custom user/profile fields manually
function my_show_extra_profile_fields( $user ) { ?>
<div class="subscription-info">
<h3>Subscription Information</h3>
<table class="form-table">
<tr>
<th><label for="subscription">Customer ID</label></th>
<td>
<input type="text" name="subscription" id="subscription" value="<?php echo esc_attr( get_user_meta( $user->ID, 'subscription', 1) ); ?>" class="regular-text" /><br />
<span class="description">Please enter your customer ID.</span>
@makbeta
makbeta / reading-a-cookie.html
Created November 30, 2012 02:11
Luminate CMS: Reading a cookie server-side
@makbeta
makbeta / three-random-items-list.html
Created November 30, 2012 02:08
Luminate CMS: Display 3 random items from the list
<t:if test="length > 0"><!-- is there a list? -->
<t:set id="iRandom" value="random(length)+1" /><!-- set a variable equal to a number between 1 and the length of the list -->
<!-- if random number is within 2 of the last item in the list, subtract 2 -->
<t:if test="iRandom >= (length-2) && iRandom <= length">
<t:set id="iRandom" value="iRandom-2" />
</t:if>
<!-- if the variable is now negative due to the subtraction above, reset it to 1 (the first list item) -->
<t:if test="iRandom <= 0">