Skip to content

Instantly share code, notes, and snippets.

@everaldomatias
everaldomatias / snippets.json
Last active September 25, 2024 17:36
VS Code PHP/WP snippets
{
"If Simples": {
"prefix": "ifs",
"body": [
"if ( $1 ) {",
"$2",
"}"
],
"description": "Imprime uma condição if simples"
},
@everaldomatias
everaldomatias / plugin.php
Created September 12, 2024 18:31
Basic WordPress plugin structure
<?php
/**
* Plugin Name: Plugin Template
* Plugin URI: https://site.com.br
* Description: Plugin description.
* Version: 0.0.1
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: The dev/
* Author URI: https://site.com.br
/*!
* Understrap v1.1.0 (https://understrap.com)
* Copyright 2013-2022 The UnderStrap Authors (https://github.com/understrap/understrap/graphs/contributors)
* Licensed under GPL (http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html)
*/
(function (factory) {
typeof define === 'function' && define.amd ? define(factory) :
factory();
})((function () { 'use strict';
@everaldomatias
everaldomatias / wp-log-hook.php
Created June 10, 2024 18:06
WordPress log functions hooked
<?php
add_action( 'wp_loaded', function() {
function list_hook_callbacks( $hook_name ) {
global $wp_filter;
if ( ! isset( $wp_filter[$hook_name] ) ) {
return [];
}
@everaldomatias
everaldomatias / cody.json
Created April 17, 2024 22:39
Cody custom commands.
{
"format": {
"description": "Format the code using WP coding standards",
"prompt": "Formate o código selecionado seguindo as melhores práticas (coding standards) propostas pelo WordPress, independente da linguagem usada.",
"context": {
"selection": true
}
}
}
@everaldomatias
everaldomatias / is_rest.php
Created February 22, 2024 20:20 — forked from matzeeable/is_rest.php
Checks if the current request is a WP REST API request.
<?php
if ( !function_exists( 'is_rest' ) ) {
/**
* Checks if the current request is a WP REST API request.
*
* Case #1: After WP_REST_Request initialisation
* Case #2: Support "plain" permalink settings and check if `rest_route` starts with `/`
* Case #3: It can happen that WP_Rewrite is not yet initialized,
* so do this (wp-settings.php)
@everaldomatias
everaldomatias / get-post-by-name.php
Last active February 20, 2024 17:51
Get WordPress post by name
<?php
if ( ! function_exists( 'get_post_by_name' ) ) {
function get_post_by_name($name, $post_type = 'post') {
$get_posts = get_posts(
[
'post_status' => 'publish',
'post_type' => $post_type,
'posts_per_page' => 1,
'name' => $name
]
@everaldomatias
everaldomatias / meta-to-featured-image.php
Created December 5, 2023 14:10
Migrate image of the post meta to featured image
@everaldomatias
everaldomatias / exclude_posts_by_filter_field.php
Created November 16, 2023 13:41
Remove posts using term name on field filter of the block Query Loop
<?php
function exclude_posts_by_filter_field( $query ) {
// Add other checks to determine exactly where you want to remove posts
if ( isset( $query->query['s'] ) && ! empty( $query->query['s'] ) ) {
// Continue if post_type equal `post`
if ( isset( $query->query['post_type'] ) && 'post' === $query->query['post_type'] ) {
$parts = explode( ' ', $query->query['s'] );
const handleSubmitBackup = () => {
// Definindo os detalhes do usuário que você quer criar
let rand = Math.floor(Math.random() * 999)
let userData = {
username: 'jane-'+rand,
password: 'secret',
email: 'jane-'+rand+'@example.com',
roles: ['']
};