Skip to content

Instantly share code, notes, and snippets.

@bUxEE
bUxEE / associative_value_sort.php
Created March 26, 2017 14:09
Associative array sort by value
<?php
usort($array, function($a, $b) { if($a['key']==$b['key']) return 0; return $a['key'] > $b['key']?1:-1; });
?>
@bUxEE
bUxEE / auto-img-alt.php
Last active March 29, 2017 14:16
Automate images with missing alt tags using image filename - Wordpress
<?php
//////////////////////////////////////////////////////////////
///////// AUTOMATE ALT TAGS FOR IMAGES
//////////////////////////////////////////////////////////////
function image_alt_tag($content) {
global $post;
preg_match_all('/<img (.*?)\/>/', $content, $images);
if(!is_null($images)) {
foreach($images[1] as $index => $value) {
if(!preg_match('/alt=/', $value) && preg_match('/< *img[^>]*src *= *["\']?([^"\']*)/i', $value)) {
@bUxEE
bUxEE / find_string.php
Last active July 23, 2025 01:02
find string in file (search in directory and subdirectories) php
<?php
$string = 'stringToSearch';
$dir = new RecursiveDirectoryIterator('folder');
foreach (new RecursiveIteratorIterator($dir) as $filename => $file) {
//$thename = $file->getFilename(); //uncomment this line and next to print names of all files scanned
//echo $thename.'<br />';
$content = file_get_contents($file->getPathname());
if (strpos($content, $string) !== false) {
@bUxEE
bUxEE / wp-recursive-menu.php
Last active April 28, 2024 15:07
Recursive menu/submenu list from wp_get_nav_menu_items. Change menu name and style to your needs. Supports unlimited number of submenus.
<?php
$menu_name = 'menu-name';
$locations = get_nav_menu_locations();
$menu = wp_get_nav_menu_object( $locations[ $menu_name ] );
$menuitems = wp_get_nav_menu_items( $menu->term_id, array( 'order' => 'DESC' ) );
//echo '<pre>'.print_r($menuitems).'</pre>';
function buildTree( array &$elements, $parentId = 0 )
{
// consulente error checks
consulente_errors_list = [];
$('#detrazione-fiscale-consulente .consulente-checK input[type="checkbox"]').change(function () {
consulente_errors_list = $('#detrazione-fiscale-consulente .consulente-checK input[type="checkbox"]:checked').map(function (i) {
var classes = $(this).closest('.cmb-row').attr('class');
var error_el = '.' + classes.match("cmb2-id-([a-zA-Z\-]+)")[1];
//console.log(consulente_errors_list);
//console.log(error_el);
@bUxEE
bUxEE / inputGroupJson.js
Last active December 14, 2017 23:21
grouped inputs to json
var group_fields = [];
// Loop through the fields
theForm.serializeArray().forEach(function(entry,i) {
// Get the index and prop name from the entry name
var nameparts = /^([a-zA-Z0-9_]+)\[(.+)\]\[(.*)\]$/.exec(entry.name);
// Get the group entry if we already have it
var group = group_fields[nameparts[2]];
if (!group) {
// We don't, create and add it
group = group_fields[nameparts[2]] = {};
@bUxEE
bUxEE / htaccess-security.php
Created January 10, 2018 14:51
htaccess security settings
# START SECURITY
# Don't show errors which contain full path diclosure (FPD)
# Use that line only if PHP is installed as a module and not per CGI
# try using a php.ini in that case.
# Change mod_php5.c to mod_php7.c if you are running PHP7
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
# Don't list directories
<video controls width="100%" height="100%" preload="none" style="background-image:url('preview.jpg');">
<source src="video.mp4" type="video/mp4" />
<source src="video.webm" type="video/webm" />
<source src="video.ogg" type="video/ogg" />
<p>Il tuo browser non supporta questo video</p>
</video>
@bUxEE
bUxEE / jquery-plugin-function.js
Created January 19, 2018 08:06
jquery plugin example
(function($) {
$.fn.extend({
myPlugin: function(options) {
var defaults = {
something: 23,
otherThing: 'hello'
};
options = $.extend(defaults, options);
@bUxEE
bUxEE / elogp.php
Last active September 2, 2018 09:37
error_log
function elogp($var, $level="", $log="") {
$date = date("d-m-Y h:m:s");
$t = debug_backtrace();
$file = $t[0]['file'];
$level = $level == "" ? "info" : $level;
$log = $log == "" ? ABSPATH."/elogp.log" : $log;
$message = "[{$date}] [{$file}] [{$level}] ".print_r($var, true).PHP_EOL;
error_log($message, 3, $log);
}