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 / 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 / drupal7-add-user-role.php
Last active November 18, 2015 07:11
Drupal 7: add user's role to the body class of the page
<?php
function mytheme_responsive_preprocess_html(&$variables, $hook) {
$body_classes = array($variables['classes_array']);
// The body tag's classes are controlled by the $classes_array variable. To
// remove a class from $classes_array, use array_diff().
//$variables['classes_array'] = array_diff($variables['classes_array'], array('class-to-remove'));
if ($variables['user']) {
foreach ($variables['user']->roles as $key => $role) {
$role_class = 'role-' . str_replace(' ', '-', $role);
@makbeta
makbeta / d7-disable-wysiwyg-set-format.php
Created October 8, 2015 18:37
D7 modules that sets default format for a field; disables Wisiwyg editor on a set field & summary
<?php
/**
* Implement hook_element_info_alter()
* Enable custom processing of a field in authoring form before it is rendered to the user
*
* @param array $elements
*/
function my_module_element_info_alter(&$elements) {
array_unshift($elements['text_format']['#pre_render'], 'my_module_process_text_format');
}
@makbeta
makbeta / d7-submitted-info
Last active August 29, 2015 14:24
Change submitted info line that automatically appears on posts in Drupal 7
<?php
THEME_preprocess_node(&$variables, $hook) {
if ($variables['submitted']) {
$variables['submitted'] = t('Posted by !username !datetime', array('!username' => $variables['name'], '!datetime' => format_date($variables['node']->created, 'custom', 'F j, Y')));
}
}
?>
@makbeta
makbeta / ckeditor.styles.js
Last active August 29, 2015 14:04
Creating custom classes in CKEditor in Drupal
if(typeof(CKEDITOR) !== 'undefined') {
CKEDITOR.stylesSet.add( 'drupal', [
// Block-level styles
{ name: 'Float Left', element: 'p', attributes: { 'class': 'left'} },
{ name: 'Float Right' , element: 'p', attributes: { 'class': 'right'} },
// Inline styles
{ name: 'Small Text', element: 'small' }
] );
@makbeta
makbeta / wordpress-change-admin-title-text.php
Created October 29, 2013 20:14
CHANGE THE “ENTER TITLE HERE” TEXT IN WORDPRESS
<?php
function XXX_enter_title_here( $title ){
$screen = get_current_screen();
if ( 'custom_post_type' == $screen->post_type ) {
$title = 'Custom Post Type Title Text';
}
return $title;
}