Skip to content

Instantly share code, notes, and snippets.

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',
@everaldomatias
everaldomatias / virtual-page.php
Created July 15, 2023 01:20
Create virtual page on WP
<?php
namespace MeuPlugin;
$voting_page = apply_filters( 'voting_page', 'create-voting' );
define( 'MEUPLUGIN_VOTING_PAGE', $voting_page );
function add_rewrite()
{
add_rewrite_rule('^concordamos/' . CONCORDAMOS_VOTING_PAGE . '/?', 'index.php?voting_page=1', 'top');
p1_eixo
p12_uf
p16_bairro
p16_cidade
p16_estado
p16_internacional
p16_nacional
p17_ano
p18_agrario
p18_comunicacao
@everaldomatias
everaldomatias / excerpt.php
Created June 22, 2023 22:41
Altera o `excerpt_more` na Home e para o CPT `deputado`
<?php
function filter_excerpt_more( $more ) {
global $post;
if ( is_front_page() ) {
if ( ! ( 'deputado' == $post->post_type ) ) {
return $more;
@everaldomatias
everaldomatias / endpoint.php
Created June 21, 2023 01:27
Implementa chart.js no WP
<?php
function custom_endpoint_init() {
register_rest_route( 'meusite/v1', '/graficos/', array(
'methods' => 'GET',
'callback' => 'minha_funcao_de_resposta',
'args' => array(
'meta' => array(
'validate_callback' => function($param, $request, $key) {
return is_string( $param );
@everaldomatias
everaldomatias / woocommerce-functions.php
Last active June 3, 2023 01:01
Enqueue WooCommerce template from plugin
<?php
add_filter( 'woocommerce_locate_template', 'custom_woocommerce_locate_template', 10, 3 );
function custom_woocommerce_locate_template( $template, $template_name, $template_path ) {
global $woocommerce;
$_template = $template;
if ( ! $template_path ) $template_path = $woocommerce->template_url;