Skip to content

Instantly share code, notes, and snippets.

@daveromsey
Created March 29, 2024 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daveromsey/4159f64b461912aa59699cf11815d686 to your computer and use it in GitHub Desktop.
Save daveromsey/4159f64b461912aa59699cf11815d686 to your computer and use it in GitHub Desktop.
{
// Place your snippets for php here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",
// "$2"
// ],
// "description": "Log output to console"
// }
"Log var_export()": {
"prefix": "logv",
"body": ["error_log( '$1 ' . var_export( $2, true ) );"],
"description": "Do a var_export( $variable ) to PHP error log."
},
"Exit with var_dump()": {
"prefix": "xvd",
"body": ["exit( var_dump( $0 ) );"],
"description": "Exit with var_dump()"
},
"Exit with print_r()": {
"prefix": "xpr",
"body": ["exit( print_r( $0 ) );"],
"description": "Exit with print_r()"
},
"Log print_r()": {
"prefix": "logp",
"body": ["error_log( print_r( $0, true ) );"],
"description": "Do a print_r( $variable ) to PHP error log."
},
"Detailed Error Log": {
"prefix": "logd",
"body": [
"error_log( print_r( (object)",
"\t[",
"\t\t'line' => __LINE__,",
"\t\t'file' => __FILE__,",
"\t\t'dump' => [",
"\t\t\t$0,",
"\t\t],",
"\t], true ) );"
],
"description": "Detailed error logging"
},
"Log gettype()": {
"prefix": "logt",
"body": ["error_log( gettype( $0 ) );"],
"description": "Do a gettype( $variable ) to PHP error log."
},
"PHPCS Fix Escape Output": {
"prefix": "phpcseo",
"body": ["// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped"],
"description": "Ignore PHPCS Escape output error"
},
"__()": {
"prefix": "__(",
"body": ["__( '$0', '' )"],
"description": "Basic translatable string."
},
"Debug Filters": {
"prefix": "logf",
"body": ["add_action( 'all', function() { error_log( var_export( current_filter(), true ) ); } );"],
"description": "Logs current filter."
},
"if …": {
"prefix": "if",
"body": [
"if ( ${1:condition} ) {",
"\t${0:# code...}",
"}"
],
"description": "If block"
},
"foreach …": {
"prefix": "foreach",
"body": [
"foreach ( $${1:variable} as $${2:key} ${3:=> $${4:value}} ) {",
"\t${0:# code...}",
"}"
],
"description": "Foreach loop"
}
}
@ramiwds
Copy link

ramiwds commented Apr 4, 2024

Solid!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment