Skip to content

Instantly share code, notes, and snippets.

View sectsect's full-sized avatar
💭

sect sectsect

💭
View GitHub Profile
@sectsect
sectsect / functions.php
Last active October 7, 2023 21:34
Wordpress: Get the Deepest Terms. Supports Term order and Multiple Categories in Deepest hierarchy.
<?php
function get_the_terms_deepest($taxonomies, $term_order = false) {
$categories = get_the_terms(get_the_ID(), $taxonomies); // get all product cats for the current post
if($categories && !is_wp_error($categories)){ // wrapper to hide any errors from top level categories or products without category
if(count($categories) == 1){ // Case: Select only Category of Top Level. (Required: Activate Plugin Parent Category Toggler)
$return = $categories;
}elseif(count($categories) > 1){
$return = array();
foreach($categories as $category){ // loop through each cat
$children = get_categories(array('taxonomy' => $taxonomies, 'parent' => $category->term_id)); // get the children (if any) of the current cat
@sectsect
sectsect / laravel-controller.md
Last active February 1, 2017 17:30
Cotroller for Laravel

Basic Controller for Laravel

1. Define the Route in routes/web.php

<?php
Route::get('test/', 'TestController@show');
@sectsect
sectsect / is_array_empty.php
Created August 29, 2017 15:35
The strict empty check for PHP array
<?php
function array_remove_empty( $array ) {
foreach ( $array as $key => $value ) {
if ( is_array($value) ) {
$array[$key] = array_remove_empty( $array[$key] );
}
if ( empty( $array[$key] ) ) {
unset( $array[$key] );
}
@sectsect
sectsect / get_token.php
Created February 9, 2018 16:59
Create Ramdom Tokens with PHP
<?PHP
function get_token($length = 32) {
if ( ! isset($length) || intval($length) <= 8 ) {
$length = 32;
}
// PHP 7.0+
if ( function_exists('random_bytes') ) {
return bin2hex(random_bytes($length));
}
// PHP 5.3+
@sectsect
sectsect / Find-Replace.md
Last active November 28, 2019 11:58
Replace nesting in scss to nesting syntax for "postcss-nesting" with Regex

⚠️ Precondition: formatting with stylelint

Find

^([\s]{2,})(?!.*[&@])(.*?)([,{])\n

Replace

$1&amp; $2$3\n