Skip to content

Instantly share code, notes, and snippets.

View dingo-d's full-sized avatar
🏠
Working from home

Denis Žoljom dingo-d

🏠
Working from home
View GitHub Profile
@dingo-d
dingo-d / phpcs-results.txt
Created February 16, 2020 17:07
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
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'·),
@dingo-d
dingo-d / test-api-doc-response.php
Created January 3, 2020 09:54
A test for API response
<?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 November 29, 2017 10:21
A fix for cutting down the number of queries done by the ACF
<?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 September 30, 2019 11:58
An example of gitconfig
[user]
email = // email
name = // name
username = // username
signingkey = // your sign in key
[help]
autocorrect = 0
[diff]
tool = default-difftool
[difftool "default-difftool"]
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
----------------------------------------------------------------------
version: '3.3'
services:
app:
image: wordpress:5.2.0-php7.2-fpm
container_name: wptest-app
depends_on:
- db
- redis
@dingo-d
dingo-d / composer.json
Created July 8, 2019 08:26
PHPCS Security scan (for WordPress). This setup can check your project for some possible security issues. It will also check it against the PHPCompatibility standard, WPCS-Extra standard (includes Core), and uses a security audit standard from Pheromone.
{
"require-dev": {
"pheromone/phpcs-security-audit": "^2.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
"roave/security-advisories": "dev-master",
"phpcompatibility/php-compatibility": "^9.2",
"wp-coding-standards/wpcs": "^2.1"
},
"scripts": {
"phpcs-i": "@php vendor/bin/phpcs -i",
@dingo-d
dingo-d / random.php
Last active April 12, 2019 11:31
Random string generator
<?php
/**
* The random string generator helper
*
* Solution implemented from http://stackoverflow.com/a/13733588/1056679
*
* Usage: CLI: php random.php {length}
* length - length of the random string to generage
*
* @since 1.0.0
<?php
/**
* !!WARNING!!
* This script will delete everything you have in wordpress.
* I use it only when developing something that requires me to delete everything, e.g. importer.
* You can comment some parts out if you need to quickly delete just posts, or pages or so, but still be very careful!!!
*
* @author Denis Žoljom (https://github.com/dingo-d)
* @license Free to use at your own risk
@dingo-d
dingo-d / keybindings.json
Last active February 2, 2019 19:42
Some keybindings that help me develop in visual studio code editor
[
{
"key": "cmd+shift+[Period]",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "error_log( print_r( , true ) );"
}
},
{
"key": "cmd+shift+m",