Skip to content

Instantly share code, notes, and snippets.

View jrfnl's full-sized avatar
🐘
Herding 🐘

Juliette jrfnl

🐘
Herding 🐘
View GitHub Profile
@jrfnl
jrfnl / wp-config-debug.php
Last active April 5, 2024 18:16
Code to add to wp-config.php to enhance information available for debugging.
<?php
/**
* == About this Gist ==
*
* Code to add to wp-config.php to enhance information available for debugging.
*
* You would typically add this code below the database, language and salt settings
*
* Oh.. and *do* make sure you change the path to the log file to a proper file path on your server (make sure it exists).
*
@jrfnl
jrfnl / _readme.md
Last active June 4, 2023 17:12
PHPUnit xslt

###PHPUnit logfile XLST template

This fileset provides an easy way to view the PHPUnit XML (JUnit) logfiles in a human readable manner using a web browser.

Use this either in combination with the accompanying html file or add the following tag straight after the xml opening tag of the logfile: <?xml-stylesheet type="text/xsl" href="phpunit.xslt"?>

The thresholds used for the colour-coding and whether or not to show detail for successfull tests can be changed by adjusting the variables at the top of the xslt file.

@jrfnl
jrfnl / reservednames.txt
Last active May 5, 2022 10:19
Reserved names used as parameter names in WordPress - Trac ticket: #55650 https://core.trac.wordpress.org/ticket/55650 - Last updated: 2022-05-05
Command used: `phpcs -ps . --sniffs=Universal.NamingConventions.NoReservedKeywordParameterNames --report=full,summary,source --extensions=php` (will not work by default)
FILE: src\wp-admin\includes\template.php
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
907 | WARNING | It is recommended not to use reserved keywords as function parameter names. Found:
| | $parent
| | (Universal.NamingConventions.NoReservedKeywordParameterNames.parentFound)
----------------------------------------------------------------------------------------------------
@jrfnl
jrfnl / 20210917-notes-on-input-validation.md
Created September 17, 2021 18:11
Notes on input validation for WP Core

What is input validation ?

Checking for a variable/ array index:

  • Does it exist ?
  • Is it of the right type ?
  • Is the value usable for our purposes ?

Problem definition:

  • Lack of input validation throughout most of Core.
  • ... which is especially problematic in the context of filter hooks / callbacks.
@jrfnl
jrfnl / phpunit.bat
Created August 13, 2021 14:23
PHPUnit PHP/PHPUnit switching script example
@echo off
::
:: PHP ??? have Xdebug + Blackfire.
:: PHP 7.4.14 has Xdebug with coverage
:: PHP 7.4.15 has Xdebug with develop + trace
::
:set PHPBIN=C:\wamp\bin\phpcli_x86\php5.2.17\php.exe
:set PHPBIN=C:\wamp\bin\phpcli_x86\php5.3.29\php.exe
:set PHPBIN=C:\wamp\bin\phpcli_x86\php5.4.45\php.exe
:set PHPBIN=C:\wamp\bin\php\php5.5.38\php.exe
@jrfnl
jrfnl / functions-add-icons.php
Created May 26, 2014 19:30
Easily add favicon and apple touch and Windows8 icons to the html page header of a WordPress website
<?php
/**
* Add favicon and apple touch and Windows8 icons to the html page header of a WordPress website
*
* Add the favicon link properly to the page header so it will work in all browsers
* Add apple touch icons
* Add the Windows8 icons
* Presumes you will add the icons in the theme directory in a subfolder '/images/icons/'
* - adjust if you use another folder.
@jrfnl
jrfnl / bccalc.php
Last active October 17, 2019 01:13
Do simple reliable math calculations without the risk of wrong results using bcmath
<?php
/**
* Do simple reliable floating point calculations without the risk of wrong results.
*
* @see http://floating-point-gui.de/
* @see the big red warning on http://php.net/language.types.float.php
*
* In the rare case that the bcmath extension would not be loaded, it will return the
* normal calculation results.
*
@jrfnl
jrfnl / phpcs3.5-dev-upgrade-guide.md
Last active May 24, 2019 00:59
Draft: Upgrade guide to PHP_CodeSniffer 3.5.0 for sniff developers

Upgrade guide to PHP_CodeSniffer 3.5.0 for sniff developers

PHP_CodeSniffer 3.5.0 contains a lot of changes under the hood. For the most part these are non-breaking.

If you maintain an external standard, you have three options:

  • Maintain compatibility with older PHP_CodeSniffer versions [1]. In that case, there is probably nothing you need to do. Just make sure you check the BC-breaks section below just in case. All the "old" utility methods and properties will still work. They will however be removed in PHPCS 4.0.
  • Maintain compatibility with older PHP_CodeSniffer versions [2].
@jrfnl
jrfnl / phpcs3.5-changelog.txt
Last active March 23, 2019 22:48
Draft: PHP_CodeSniffer 3.5.0 changelog
- Squiz.Formatting.OperatorBracket.SpacingAfterMinus has been renamed to Squiz.Formatting.OperatorBracket.SpacingAfterSign
-- If you are referencing the old error code in a ruleset XML file, please use the new code instead
-- If you wish to maintain backwards compatibility, you can provide rules for both the old and new codes
- `Conditions::getCondition()` accepts both a single token type or an array of token types for the `$type` parameter, which has been renamed to `$types` to convey this. The parameter is also now optional.
Additionally, the new version of the method has an optional boolean `$reverse` parameter which allows to indicate whether to get the _first_ condition of a certain type or the _last_.
- `ObjectDeclarations::getClassProperties()` now has improved handling of class declaration code interlaced with comments and/or annotations
- `ObjectDeclarations::findExtendedClassName() and `ObjectDeclarations::findExtendedInterfaceNames()` will now return the class/interface names witho
@jrfnl
jrfnl / phpcs4-removals.md
Last active March 23, 2019 15:19
Draft: PHPCS 4.0 remove deprecated methods and properties

The following methods and properties have been deprecated in PHPCS 3.5.0 and should be removed in PHPCS 4.0.0:

Methods:

  • PHP_CodeSniffer\Files\File::hasCondition()
  • PHP_CodeSniffer\Files\File::getCondition()
  • PHP_CodeSniffer\Files\File::getClassProperties()
  • PHP_CodeSniffer\Files\File::findExtendedClassName()
  • PHP_CodeSniffer\Files\File::findImplementedInterfaceNames()
  • PHP_CodeSniffer\Files\File::getMethodParameters()