Skip to content

Instantly share code, notes, and snippets.

View Soullighter's full-sized avatar
Fast forward

Stefan Repac Soullighter

Fast forward
  • Novi Sad, Serbia
View GitHub Profile
@Soullighter
Soullighter / SQL
Last active March 8, 2024 13:27
How to delete all Media Files / Gallery from Database SQL in WordPress
Using FTP/SSH & Database
This method allows you to delete all items in your media library at once. Be sure to backup your database prior to doing this.
Each file in your media library has one row in the `wp_posts` table and two rows in the `wp_postmeta` table. Learn more about how WordPress stores media library entries in the database here. You can delete them all in bulk using these commands:
DELETE FROM `wp_posts` WHERE `post_type` = "attachment";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attached_file";
DELETE FROM `wp_postmeta` WHERE `meta_key` = "_wp_attachment_metadata";
@Soullighter
Soullighter / function.php
Created September 13, 2023 08:09
ACF WYSIWYG Editor add underline option
##-- ACF WYSIWYG Editor add underline option
add_filter( 'acf/fields/wysiwyg/toolbars', 'my_toolbars' );
function my_toolbars( $toolbars ) {
$toolbars['Full'][1][3] = 'underline';
return $toolbars;
}
@Soullighter
Soullighter / function.php
Created August 29, 2023 11:14
Check UserAgent if it's mobile in PHP
function isMobileDevice2() {
return preg_match("/(android|avantgo|blackberry|bolt|boost|cricket|docomo|fone|hiptop|mini|mobi|palm|phone|pie|tablet|up\.browser|up\.link|webos|wos)/i", $_SERVER["HTTP_USER_AGENT"]);
}
if( isMobileDevice2() === 1 || isMobileDevice2() === false) {
// Magic
}
@Soullighter
Soullighter / style.css
Created June 7, 2023 13:19
Gradient border with border radius
.btn-gradient-2 {
background: linear-gradient(white, white) padding-box,
linear-gradient(to right, darkblue, darkorchid) border-box;
border-radius: 30px;
border: 4px solid transparent;
}
@Soullighter
Soullighter / function.php
Created February 21, 2023 14:32
Remove <p> Paragraph around <img> image in Advanced Custom Field ( ACF ) WYSIWYG editor
<?php
// In this example we are adding <div> with class Figure around <img>
// If you want to remove <div> just simple delete open/close tag and leave $1 between ''
function img_unautop($pee) {
$pee = preg_replace('/<p>\\s*?(<a .*?><img.*?><\\/a>|<img.*?>)?\\s*<\\/p>/s', '<div class="figure">$1</div>', $pee);
return $pee;
}
add_filter( 'acf_the_content', 'img_unautop', 30 );
@Soullighter
Soullighter / insta-oembed.php
Last active October 10, 2021 07:42
Get Instagram API SINGLE Post with OEmbed in PHP
<!-- IMPORTANT!!! If you want to use OEmbed like this your Instagram profile MUST BE PUBLIC -->
<?php
// Using curl because if you use file_get_contents() it need more then 10s page to be loaded...
function curl_get_contents($url) {
// Initiate the curl session
$ch = curl_init();
// Set the URL
curl_setopt($ch, CURLOPT_URL, $url);
// Removes the headers from the output
curl_setopt($ch, CURLOPT_HEADER, 0);
/*
+append will put images side by side, i.e. horizontally instead of vertically (with -append)
*/
// Terminal part
convert in.pdf +append out%d.png
@Soullighter
Soullighter / git-command.txt
Last active March 1, 2021 09:51
Exclude file to be tracked from Git
// Most important thing is to enter full path to the file from root directory path
git update-index --assume-unchanged rootFullPathToTheFile/file.extension
<?php
const CYR = array('а','б','в','г','д','ђ','е','ж','з','и','ј','к','л','љ','м','н','њ','о','п','р','с','т','ћ','у','ф','х','ц','ч','џ','ш','А','Б','В','Г','Д','Ђ','Е','Ж','З','И','Ј','К','Л','Љ','М','Н','Њ','О','П','Р','С','Т','Ћ','У','Ф','Х','Ц','Ч','Џ','Ш');
const LAT = array('a','b','v','g','d','đ','e','ž','z','i','j','k','l','lj','m','n','nj','o','p','r','s','t','ć','u','f','h','c','č','dž','š','A','B','V','G','D','Đ','E','Ž','Z','I','J','K','L','LJ','M','N','NJ','O','P','R','S','T','Ć','U','F','H','C','Č','DŽ','Š');
function cyr_to_latin( $string ) {
return str_replace(CYR, LAT, $string);
}
function latin_to_cyr( $string ) {
@Soullighter
Soullighter / states-cities-zip-all.json
Created November 18, 2020 09:04
List of cities with states and zip codes
This file has been truncated, but you can view the full file.
[
{
"max_zip": 99403,
"state_code": "WA",
"name": "Washington",
"cities": [
{
"zips": [
98360,
98321,