Skip to content

Instantly share code, notes, and snippets.

@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: ['']
};
@everaldomatias
everaldomatias / taincan.php
Created September 28, 2023 19:09
Tentativas tainacan
<?php
$repo_collection = \Tainacan\Repositories\Collections::get_instance();
$repo_items = \Tainacan\Repositories\Items::get_instance();
$repo_metadata = \Tainacan\Repositories\Metadata::get_instance();
$acervo = $repo_collection->fetch_one( ['pagename' => 'acervo'] );
$unidade = $repo_metadata->fetch_one( ['name' => 'Unidade'] );
$item = new \Tainacan\Entities\Item( 7200 );
<?php
function migrate_user_role_custom_network() {
$users = get_users( ['role' => 'custom_network'] );
foreach ( $users as $user ) {
$user->set_role( 'editor' );
$user->set_role( 'custom_network' );
}
}
@everaldomatias
everaldomatias / set-wp--post-author.php
Created September 22, 2023 18:51
Create relationship of the user and cpt
<?php
$args = array(
'post_type' => 'organizacao',
'posts_per_page' => -1,
'author__in' => [],
);
$query = new WP_Query( $args );
@everaldomatias
everaldomatias / helper.php
Created August 14, 2023 21:37
Get vote count
<?php
function get_vote_count ( $post_id ) {
$args = [
'post_type' => 'vote',
'fields' => 'ids',
'meta_query' => [
[
'key' => 'voting_id',