Skip to content

Instantly share code, notes, and snippets.

View nandomoreirame's full-sized avatar
🎧
Working

Fernando Moreira nandomoreirame

🎧
Working
View GitHub Profile
@nandomoreirame
nandomoreirame / setup-server.sh
Created May 5, 2018 01:31
Setup nginx server sell script
#!/usr/bin/env bash
#
# Nginx - new server block
# Functions
ok() { echo -e "\033[1;32m$1 ✔ \033[0m"; }
die() { echo -e "\033[1;31m$1 ✖ \033[0m"; exit 1; }
# Variables
USER=$1
@nandomoreirame
nandomoreirame / .htaccess
Last active April 21, 2018 11:45
WordPress .htaccess with http basic auth
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
@nandomoreirame
nandomoreirame / function.php
Last active January 1, 2023 04:47
WordPress REST API send email SMTP in with PHPMailer
<?php
function sendWithPhpMailer($subject, $body, $reply) {
require(ABSPATH . WPINC . '/class-phpmailer.php');
require(ABSPATH . WPINC . '/class-smtp.php');
// date_default_timezone_set( 'America/Sao_Paulo' );
$blogname = wp_strip_all_tags( trim( get_option( 'blogname' ) ) );
$smtpHost = wp_strip_all_tags( trim( get_option( 'smtp_host' ) ) );
@nandomoreirame
nandomoreirame / php.ini-development
Created March 23, 2018 18:19
php.ini development
[PHP]
;;;;;;;;;;;;;;;;;;;
; About php.ini ;
;;;;;;;;;;;;;;;;;;;
; PHP's initialization file, generally called php.ini, is responsible for
; configuring many of the aspects of PHP's behavior.
; PHP attempts to find and load this configuration from a number of locations.
@nandomoreirame
nandomoreirame / wp-api-post-comments.php
Created March 21, 2018 17:51
WordPress API get Post Comment
<?php
add_action( 'rest_api_init', 'theme_register_rest_fields' );
function theme_register_rest_fields() {
register_rest_field( 'post', 'comments', array(
'get_callback' => 'theme_get_post_comments',
'update_callback' => null,
'schema' => null
));
}
@nandomoreirame
nandomoreirame / post-views.php
Created March 21, 2018 02:21
WordPress Post Views with post_meta
<?php
define('POST_VIEWS_KEY', 'post_views_count');
function addMetaPostViews( $_postID, $_count = 0 ) {
delete_post_meta( $_postID, POST_VIEWS_KEY );
add_post_meta( $_postID, POST_VIEWS_KEY, $_count );
}
function hasViews( $_postID ) {
@nandomoreirame
nandomoreirame / functions.php
Last active March 14, 2018 20:28
show wp_mail() errors
<?php
/*
* show wp_mail() errors
*/
add_action( 'wp_mail_failed', 'onMailError', 10, 1 );
function onMailError( $wp_error ) {
echo '<pre>' . print_r($wp_error , true ) . '</pre>';
}
@nandomoreirame
nandomoreirame / micromodal.sass
Last active November 21, 2017 19:12
Micromodal.js sass file
.modal
font-family: inherit
position: fixed
z-index: 10000
&__overlay
position: fixed
top: 0
left: 0
right: 0
bottom: 0
@nandomoreirame
nandomoreirame / about-meta-box.php
Created November 13, 2017 19:05
Odin_Metabox on about page
<?php
function about_metabox_page () {
$hasGetMethod = (isset($_GET['post']) && !empty($_GET['post']));
$hasPostMethod = (isset($_POST['post_ID']) && !empty($_POST['post_ID']));
$about_pages_arr = array(
'sobre',
'sobre-nos',
'sobre-a-grgit',
'quem-somos',
@nandomoreirame
nandomoreirame / custom_post_type.php
Created November 6, 2017 13:05
Odin custom post type
<?php
$services_post_type = new Odin_Post_Type(
'Service',
'services'
);
$services_post_type->set_labels(
array(
'name' => __( 'Services', 'odin' ),