Skip to content

Instantly share code, notes, and snippets.

View mariovalney's full-sized avatar
🏠
Working from home

Mário Valney mariovalney

🏠
Working from home
View GitHub Profile
@mariovalney
mariovalney / event-scroll.js
Last active August 29, 2015 14:14
Evento Scroll de Acordo com a Altura
$(document).on('scroll', function () {
var altura = pageYOffset;
if (altura > 200) {
// Macumba pra quando rolar e passar dos 200px do topo
} else {
// Macumba pra quando rolar e ainda não passar dos 200px do topo
}
});
@mariovalney
mariovalney / functions.php
Created May 6, 2015 13:34
Menu Manage Functions - WordPress
// Modifica as Páginas do Menu
function meu_plugin_menu_pages() {
if (!is_super_admin()) {
remove_menu_page('index.php');
remove_menu_page('edit.php');
remove_menu_page('upload.php');
remove_menu_page('edit.php?post_type=page');
remove_menu_page('edit-comments.php');
remove_menu_page('themes.php');
@mariovalney
mariovalney / ActivityToShare.java
Created June 7, 2015 23:07
Piece of code ("onOptionsItemSelected" method) to share anything in a Android Activity
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_share) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "TEXTO A SER COMPARTILHADO");
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, "Compartilhe com..."));
@mariovalney
mariovalney / scroller.js
Last active January 7, 2016 12:30
Scroller
$.fn.scroller = function(offsetTop) {
if (offsetTop == null) {
offsetTop = 0;
}
this.each( function() {
var id = this.id;
$("a[href=#" + id + "]").on('click', function(event) {
event.preventDefault();
@mariovalney
mariovalney / functions.php
Created February 24, 2016 19:07
Alterar slug de um custom post type já registrado
function change_post_type_slug() {
$post_type_portfolio_object = get_post_type_object( 'portfolio' );
$post_type_portfolio_object->rewrite['slug'] = 'produto';
register_post_type( $post_type_object->name, $post_type_object );
}
add_action( 'init', 'change_post_type_slug', 20 );
@mariovalney
mariovalney / validate-documents.js
Last active May 17, 2016 17:13
CPF and CNPJ validation (front-end)
function validateCPF(number) {
var cpf = number.toString().replace(/[^0-9]/g, '');
if (cpf.length != 11) {
return false;
}
var digitoTestado = cpf.slice(9, 11);
var digitoValidado = '';
var sum1 = sum2 = dig1 = dig2 = 0;
@mariovalney
mariovalney / validate-documents.php
Last active May 17, 2016 17:19
CPF and CNPJ validation (back-end)
<?php
/**
* Função que checa se um CPF é válido
* Criado em fevereiro/2016
*/
function check_cpf_is_valid( $string ) {
$cpf = pm_sanitize_number($string);
@mariovalney
mariovalney / content-factory.php
Last active July 21, 2016 13:38
Content Factory - WordPress
<?php
/**
* ContentFactory
* Classe responsável pela criação de conteúdo personalizado
*
* @author Mário Valney <mariovalney@gmail.com>.
*/
if (!defined( 'ABSPATH' )) {
@mariovalney
mariovalney / main-js
Created September 16, 2016 20:22
Validate Documents
function putDots(num) {
if (num == 0) {
return "0"
} else {
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ".");
}
}
function putDotsToMoney(num) {
num = parseFloat(num);
@mariovalney
mariovalney / functions.php
Created August 2, 2017 19:31
Descrição das taxas no carrinho do WooCommerce
<?php
/**
* Adiciona as taxas ao subtotal no carrinho
*/
function vta_cart_item_subtotal( $wc, $cart_item, $cart_item_key ) {
$_product = apply_filters( 'woocommerce_cart_item_product', $cart_item['data'], $cart_item, $cart_item_key );
$subtotal = wc_get_price_including_tax( $_product, array( 'qty' => $cart_item['quantity'] ) );