Skip to content

Instantly share code, notes, and snippets.

View nandomoreirame's full-sized avatar
🎧
Working from home

Fernando Moreira nandomoreirame

🎧
Working from home
View GitHub Profile
@nandomoreirame
nandomoreirame / rest-api-theme-options.php
Created August 19, 2019 04:35
WordPress REST API theme options
<?php
add_action('rest_api_init', function () {
register_rest_route( 'wp/v2', 'options', [
'methods' => 'GET',
'callback' => 'api_theme_options'
]);
});
function api_theme_options($request) {
@nandomoreirame
nandomoreirame / rest-api-contact-mail.php
Created August 19, 2019 02:07
WP REST API send contact mail
<?php
add_action('rest_api_init', function () {
register_rest_route( 'contact/v1', 'send', [
'methods' => 'POST',
'callback' => 'api_send_contact_form'
]);
});
function api_send_contact_form( $request ) {
@nandomoreirame
nandomoreirame / metabox-page.php
Last active July 20, 2020 21:56
add custom metabox per page
<?php
function theme_metabox_per_page() {
global $pagenow;
if ( $pagenow == 'post.php' ) {
$page_id = ( $_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['post_ID'] ) ? $_POST['post_ID'] : $_GET['post'];
if ( $page_id ) {
$page_slug = get_post_field( 'post_name', $page_id );
@nandomoreirame
nandomoreirame / custom-fields.php
Created August 19, 2019 02:04
Add custom post meta to WordPress REST API
<?php
function get_custom_post_meta_cb($object, $field_name, $request) {
return get_post_meta( $object['id'], $field_name, true );
}
function get_custom_post_meta_cb_the_content($object, $field_name, $request) {
return apply_filters( 'the_content', get_post_meta( $object['id'], $field_name, true ) );
}
@nandomoreirame
nandomoreirame / http.js
Last active July 27, 2019 17:32
WordPress Rest API http service for Vue.js projects
import axios from 'axios'
const isProduction = process.env.NODE_ENV === 'production'
const http = axios.create({
baseURL: `${isProduction ? 'https://api' : 'http://api-dev'}.dominio.com.br`,
headers: {}
})
export default http
@nandomoreirame
nandomoreirame / replace.sh
Last active May 3, 2019 13:16
Shell script for replace code multiples files in folder
#!/bin/bash
SEARCH="passenger_ruby \/home\/ubuntu\/.rvm\/gems\/ruby-2.4.1\/wrappers\/ruby;"
REPLACE="include snippets\/passenger_ruby.conf;"
# Note the double quotes
for file in ./sites-enabled/*;
do
sed -i -- "s/${SEARCH}/${REPLACE}/g" $file;
echo $file;
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
@nandomoreirame
nandomoreirame / fontawesome-icons.js
Created April 10, 2019 20:37
All font awesome icons, JSON, Javascript Array and Plain Text
const faIcons = [
'fa-500px',
'fa-address-book',
'fa-address-book-o',
'fa-address-card',
'fa-address-card-o',
'fa-adjust',
'fa-adn',
'fa-align-center',
'fa-align-justify',
@nandomoreirame
nandomoreirame / randomNumber.js
Created April 4, 2019 13:15
Returns a random number
/**
* Returns a random number
*
* @param {Number} length
* @return {Number}
*/
const randomNumber = length =>
Math.floor(Math.random() * length)

Keybase proof

I hereby claim:

  • I am nandomoreirame on github.
  • I am oseunando (https://keybase.io/oseunando) on keybase.
  • I have a public key ASC-nysW75DuYqBhwC5M0v6HovGYuZeTjr-yq6BgQJskXgo

To claim this, I am signing this object: