Skip to content

Instantly share code, notes, and snippets.

View marcelo-ribeiro's full-sized avatar

Marcelo Ribeiro marcelo-ribeiro

  • Front-End Developer
  • Salvador, Bahia, Brasil
View GitHub Profile
function remove_http($url) {
$disallowed = array('http://', 'https://');
foreach($disallowed as $d) {
if(strpos($url, $d) === 0) {
return str_replace($d, '', $url);
}
}
return $url;
}
@marcelo-ribeiro
marcelo-ribeiro / back-to-top.js
Last active August 10, 2016 19:55
Smooth Scroll to top and to target
// ---------------------------------------------------------
// Back to Top
// ---------------------------------------------------------
$(window).scroll(function () {
if ($(this).scrollTop() > 100) {
$('#back-top').fadeIn();
} else {
$('#back-top').fadeOut();
}
});
<section class="section">
<header class="section--header">
<div class="container">
<h1 class="section--title">Section Title</h1>
</div>
</header>
<main class="section--content">
<div class="container">
<!-- ... -->
</div>
@marcelo-ribeiro
marcelo-ribeiro / javascript-remove-accents.js
Last active August 13, 2024 19:35 — forked from fabiofdsantos/angularJS_removeAccents.js
An Javascript function to remove accents and others characters from an input string.
// Example: https://codepen.io/marcelo-ribeiro/pen/OJmVOyW
const accentsMap = new Map([
["A", "Á|À|Ã|Â|Ä"],
["a", "á|à|ã|â|ä"],
["E", "É|È|Ê|Ë"],
["e", "é|è|ê|ë"],
["I", "Í|Ì|Î|Ï"],
["i", "í|ì|î|ï"],
["O", "Ó|Ò|Ô|Õ|Ö"],
@marcelo-ribeiro
marcelo-ribeiro / send-mail.php
Last active May 22, 2018 15:39
Sample Function To Send WP Mail
<?php
function send_email() {
$site_name = 'Company Name';
$site_email = '[email protected]';
$to = "$site_name <$site_email>";
$name = $_POST['name'];
$email = $_POST['email'];
$subject = "$site_name - " . $_POST['subject'];
$message = $_POST['message'];
@marcelo-ribeiro
marcelo-ribeiro / ajax-pagination.js
Last active March 20, 2018 17:38
Wordpress - Ajax Pagination
$(function() {
var paged = 1,
isLoading = false,
posts = $('.posts'),
button = $('.read_more'),
foundPosts = button.attr('data-found-posts');
(function() {
hasMoreItens() && button.fadeIn();
@marcelo-ribeiro
marcelo-ribeiro / angular-jsonp.js
Last active August 28, 2017 18:16
Angular JSONP
$http({
method: 'JSONP',
url: $sce.trustAsResourceUrl(url),
jsonpCallbackParam: 'callback'
})
.then(function(response) {
console.log(response);
});
@marcelo-ribeiro
marcelo-ribeiro / edit_image.js
Last active September 12, 2017 04:38
WP REST API Upload Image
var settings = {
"async": true,
"crossDomain": true,
"url": "http://www.marcelo-ribeiro.tk/wp-json/wp/v2/media/48",
"method": "POST",
"headers": {
"authorization": "Basic bWFyY2Vsb3JpYmVpcm86QDg1ODM1OTU0Iw==",
"content-type": "application/json"
},
"processData": false,
@marcelo-ribeiro
marcelo-ribeiro / allow-cors-origin.php
Last active October 10, 2017 22:03
WP REST API - SNIPPETS
// Access-Control-Allow-Origin
add_action( 'rest_api_init', function() {
remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );
add_filter( 'rest_pre_serve_request', function( $value ) {
$origin = get_http_origin();
if ( $origin && in_array( $origin, array(
'http://localhost'
) ) ) {
header( 'Access-Control-Allow-Origin: ' . esc_url_raw( $origin ) );
header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
@marcelo-ribeiro
marcelo-ribeiro / categories-list.php
Created October 20, 2017 21:50
List categories and subcategories in JSON format
$args = [
'taxonomy' => 'category',
'hide_empty' => 0,
'parent' => 0
];
function _get_child_terms( $items ) {
foreach ( $items as $item ) {
$item->children = get_terms( 'category', array( 'child_of' => $item->term_id, 'hide_empty' => 0 ) );
if ( $item->children ) _get_child_terms( $item->children );