Skip to content

Instantly share code, notes, and snippets.

View sectsect's full-sized avatar
💭

sect sectsect

💭
View GitHub Profile
@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& $2$3\n
@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 / 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 / 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 / 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 / functions.php
Created May 11, 2016 19:50
Wordpress: Sort users by numeric value in Users Screen @ https://foxland.fi/sort-users-by-numeric-value-in-users-screen/
<?php
/**
* Add new user column: Expire Date.
*
* @since 1.0.0
* @return array $columns
*/
function prefix_expire_date_column( $columns ) {
$columns['expire_date'] = __( 'Expire Date', 'text-domain' );
return $columns;
@sectsect
sectsect / index.php
Created April 2, 2016 14:43
Japanese Settings For jQuery-Form-Validator
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.2.43/jquery.form-validator.min.js"></script>
<script>
var japanese = {
errorTitle: 'フォームの送信に失敗しました',
requiredFields: 'すべての必須フィールドに答えていません',
badTime: '時間が正しくありません',
badEmail: 'メールアドレスが正しくありません',
badTelephone: '電話番号が正しくありません',
badSecurityAnswer: 'セキュリティの質問の答えが正しくありません',
@sectsect
sectsect / functions.php
Last active March 20, 2016 19:27
Wordpress: Split the single page for each array without "<!--nextpage-->" on the template. Supported the preview page.
<?php
function is_single_paged($page){
global $wp_query;
if(!is_preview()){
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
}else{
$pagenum = $_GET['paged'];
$paged = ($pagenum) ? $pagenum : 1;
$wp_query->query = array('p' => $post->ID, 'page' => $paged, 'preview' => true, 'post_type' => get_post_type() );
$wp_query->set('paged', $paged);
@sectsect
sectsect / functions.php
Last active February 12, 2016 10:14
Remove "administrator" user from "get_users()" on wordpress.
<?php
function remove_administrator($users)
{
foreach ($users as $key => $user) {
$cap = reset($user->roles);
if ($cap === 'administrator') {
unset($users[$key]);
}
}
return $users;
@sectsect
sectsect / get_the_terms_orderby_termorder.php
Last active December 9, 2016 17:34
"get_the_terms" to the order of the "term_order". (order by ASC.)
<?php
/*==================================================
"get_the_terms" to the order of the "term_order". (order by ASC.)
================================================== */
function get_the_terms_orderby_termorder($taxonomy){
global $post;
$terms = get_the_terms($post->ID, $taxonomy);
$array = array();
foreach($terms as $term){
$array[$term->term_order] = (object)array(