Skip to content

Instantly share code, notes, and snippets.

Avatar

Denis Žoljom dingo-d

View GitHub Profile
@dingo-d
dingo-d / renameTests.php
Created May 25, 2020
Append Test to test file name script
View renameTests.php
#!/usr/bin/env php
<?php
function getDirs( $currentDir ) {
return array_filter( $currentDir, function ( $dir ) {
return is_dir( $dir ) && $dir !== '..' && $dir !== '.';
} );
}
@dingo-d
dingo-d / rename.php
Last active May 25, 2020
Simple php script to rename folder names to PascalCase from split-name. Doesn't go recursively in subfolders.
View rename.php
#!/usr/bin/env php
<?php
function getDirs( $currentDir ) {
return array_filter( $currentDir, function ( $dir ) {
return is_dir( $dir ) && $dir !== '..' && $dir !== '.';
} );
}
@dingo-d
dingo-d / ajax.js
Created Apr 17, 2020
Download users from WordPress admin
View ajax.js
export const ajaxFetch = (options, resolve, reject) => $.ajax(options)
.done(resolve)
.fail(reject);
@dingo-d
dingo-d / extract-versions.sh
Created Apr 7, 2020
A simple shell command script to extract packages and their versions from Gutenberg WP editor. Once in the 'packages' directory you can run this script
View extract-versions.sh
for package in $(ls -1); do echo $package; jq -r .version $package/package.json; done
@dingo-d
dingo-d / simple-vies-check.php
Created Oct 20, 2016
AJAX function for checking the VAT number based on country and VAT id
View simple-vies-check.php
<?php
add_action( 'wp_ajax_simple_vies_check', 'simple_vies_check' );
add_action( 'wp_ajax_nopriv_simple_vies_check', 'simple_vies_check' );
if ( ! function_exists( 'simple_vies_check' ) ) {
/**
* AJAX VIES check function for WooCommerce checkout
*
* @since 1.0.0
@dingo-d
dingo-d / phpcs-results.txt
Created Feb 16, 2020
The result of vendor/bin/phpcs --sniffs=WordPress.WP.i18n ../WordPress-Themes/themes/ --report-file=../phpcs-result.txt --error-severity=0 --extensions=php --report=code
View phpcs-results.txt
FILE: mnt/d/WordPress-Themes/themes/lightning/comments.php
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LINE 28: WARNING Mismatched placeholders is probably an error (WordPress.WP.I18n.MismatchedPlaceholders)
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
26: » » <h2·class="comments-title">
27: » <?php
>> 28: » printf(·_nx(·'One·thought·on·&ldquo;%2$s&rdquo;',·'%1$s·thoughts·on·&ldquo;%2$s&rdquo;',·get_comments_number(),·'comments·title',·'lightning'·),
View test-api-doc-response.php
<?php
/**
* Class Api_Docs_Page
*
* @package My_Plugin\Routes\Endpoints
*/
namespace My_Plugin\Tests\Routes\Endpoints;
use WP_REST_Request;
@dingo-d
dingo-d / acf-repeater-query.php
Created Nov 29, 2017
A fix for cutting down the number of queries done by the ACF
View acf-repeater-query.php
<?php
// Assuming we have ACF.
$rows = get_field('images');
// Regular ACF query with 10 images in repeater yeilds 34 queries
foreach ($rows as $row) :
$image_id = $row['image'];
$image = wp_get_attachment_image_src($image_id, 'your-custom-image-size');
echo '<img src="'. $image[0] . '" width="'. $image[1] . '" height="'. $image[2] . '" />';
endforeach;
@dingo-d
dingo-d / gitconfig
Last active Sep 30, 2019
An example of gitconfig
View gitconfig
[user]
email = // email
name = // name
username = // username
signingkey = // your sign in key
[help]
autocorrect = 0
[diff]
tool = default-difftool
[difftool "default-difftool"]
View wpgraphql-after-phpcbf.txt
FILE: ...wp-graphql/src/Connection/Themes.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
1 | ERROR | Missing file doc comment
| | (Squiz.Commenting.FileComment.Missing)
----------------------------------------------------------------------
FILE: ...wp-graphql/src/Connection/Comments.php
----------------------------------------------------------------------