Skip to content

Instantly share code, notes, and snippets.

View dinuionut's full-sized avatar

Dinu Ionut dinuionut

View GitHub Profile
@dinuionut
dinuionut / wordpress-enqueue-async-defer.php
Last active August 9, 2019 07:53
wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/js/custom.js#deferload', array( 'jquery' ), '1.0', true );
<?php
// wp_enqueue_script( 'custom-js', get_template_directory_uri() . '/js/custom.js#deferload', array( 'jquery' ), '1.0', true );
// Async Script Load
function wxpd_async_scripts( $url ) {
if ( strpos( $url, '#asyncload') === false )
return $url;
else if ( is_admin() )
return str_replace( '#asyncload', '', $url );
@dinuionut
dinuionut / clean_code.md
Created May 25, 2019 10:07 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@dinuionut
dinuionut / wpdb-transactions
Created July 3, 2018 00:40 — forked from nciske/wpdb-transactions
MySQL database transaction, using the WordPress database object $wpdb. Requires the InnoDB table format.
<?php
global $wpdb;
// Start Transaction
$wpdb->query( "START TRANSACTION" );
// Do some expensive/related queries here
//$wpdb->query("DELETE FROM table WHERE form_id = '1' ");
//$wpdb->query("DELETE FROM data WHERE form_id = '1' ");
// set $error variable value in error handling after $wpdb modifications
@dinuionut
dinuionut / wordpress-hook-sequence.php
Created May 26, 2017 12:27
Display WordPress Hook Sequence
add_action( 'shutdown', function(){
foreach( $GLOBALS['wp_actions'] as $action => $count )
printf( '%s (%d) <br/>' . PHP_EOL, $action, $count );
});
@dinuionut
dinuionut / import-github-labels.js
Last active September 22, 2019 13:42 — forked from Isaddo/import-github-labels.js
import github labels via console command
/*
Go on your labels page (https://github.com/user/repo/labels)
Edit the following label array
or
Use this snippet to export github labels (https://gist.github.com/MoOx/93c2853fee760f42d97f)
and replace it
Paste this script in your console
Press Enter!!
@dinuionut
dinuionut / index.js
Created February 13, 2017 08:17 — forked from MoOx/index.js
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),