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
<?php
/* Get the Page Slug to Use as a Body Class, this will only return a value on pages! */
$class = '';
/* is it a page */
if( is_page() ) {
global $post;
/* Get an array of Ancestors and Parents if they exist */
$parents = wp_get_post_parent_id( $post->ID );
$id = ($parents) ? $parents: $post->ID;
@Soullighter
Soullighter / Lightbox image centering
Last active June 28, 2016 04:14
How to center image vertically in lightbox
// STEP 1:
// Inside the start function, at around line 170 I commented out the assignation of the 'top' property, like this:
// Position Lightbox
var top = $window.scrollTop() + this.options.positionFromTop;
var left = $window.scrollLeft();
this.$lightbox.css({
// top: top + 'px', // comment out this line
left: left + 'px'
}).fadeIn(this.options.fadeDuration);
@Soullighter
Soullighter / Terminal
Last active September 13, 2018 09:01
Importing large SQL in MAMP, Apple macOS
/Applications/MAMP/Library/bin/mysql --host=localhost -uroot -proot DB-Name < /your/data/base/path.sql
@Soullighter
Soullighter / Wordpress gitignore default
Last active June 16, 2016 14:19
Wordpress gitignore default
*~
.DS_Store
.svn
.cvs
*.bak
*.swp
Thumbs.db
wp-config.php
wp-content/uploads/
wp-content/blogs.dir/
@Soullighter
Soullighter / Browser detect
Created April 4, 2017 07:28
Browser detect
$(document).ready(function(){
/* Get browser */
$.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
/* Detect Chrome */
if($.browser.chrome){
/* Do something for Chrome at this point */
alert("You are using Chrome!");
@Soullighter
Soullighter / gist:cff5b5cf557aa324f3dcd211cb22c9a2
Last active October 7, 2019 13:08
Parse Vimeo or YouTube url to get ID. ACF and Get thumbnail from video using vimeo API
// VIMEO
<?php
$url = get_field( 'full_video' );
preg_match('%^https?:\/\/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)(?:[?]?.*)$%im', $url, $match);
$vimeo_id = $match[3];
$data = file_get_contents("http://vimeo.com/api/v2/video/$vimeo_id.json");
$data = json_decode($data);
?>
<img src="<?php echo $data[0]->thumbnail_large; ?>">
@Soullighter
Soullighter / SQL
Last active September 25, 2019 09:26
Create user from SQL database WordPress
****
* BEFORE COPY CODE
* Change this line with your desire values
* VALUES ('admin999', MD5('password999'), 'firstname lastname', 'email@example.com', '0');
****
INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `user_email`,
`user_status`,`user_registered`)
VALUES ('admin999', MD5('password999'), 'firstname lastname', 'email@example.com', '0', '2019-06-17 11:25:03');
@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 / gist:f9685f0ad016aefc0d2886c1d3725645
Created January 28, 2019 13:27
Changing PHP version in SiteGround with .htaccess
https://www.reviewplan.com/wp-content/uploads/2018/07/Siteground-php-version-change-edit.jpg
If you want to update to PHP 7.2– AddHandler application/x-httpd-php72 .php .php5 .php4 .php3
For PHP 7.1– AddHandler application/x-httpd-php71 .php .php5 .php4 .php3
For PHP 7.0– AddHandler application/x-httpd-php70 .php .php5 .php4 .php3
For PHP 5.6– AddHandler application/x-httpd-php56 .php .php5 .php4 .php3
For PHP 5.5– AddHandler application/x-httpd-php55 .php .php5 .php4 .php3
So, copy and paste one of the lines from above to change the PHP version of your website.
For example, we have pasted the line‘AddHandler application/x-httpd-php72 .php .php5 .php4 .php3’ as we wanted to switch to PHP version 7.2
@Soullighter
Soullighter / Function to Convert stdClass Objects to Multidimensional Arrays
Created March 27, 2019 11:29
Function to Convert stdClass Objects to Multidimensional Arrays
function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object