Skip to content

Instantly share code, notes, and snippets.

View QROkes's full-sized avatar

Cristhian Martínez Ochoa QROkes

View GitHub Profile
@QROkes
QROkes / traccar.xml
Last active September 29, 2018 09:38
Traccar GPS Configuration file
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE properties SYSTEM 'http://java.sun.com/dtd/properties.dtd'>
<properties>
<entry key="config.default">./conf/default.xml</entry>
<!-- DataBase MariaDB -->
<entry key='database.driver'>com.mysql.jdbc.Driver</entry>
<entry key='database.url'>jdbc:mysql://[HOST]:3306/[DATABASE]?useSSL=false&amp;allowMultiQueries=true&amp;autoReconnect=true&amp;useUnicode=yes&amp;characterEncoding=UTF-8&amp;sessionVariables=sql_mode=''</entry>
<entry key='database.user'>[USER]</entry>
@QROkes
QROkes / qa-plugin.php
Created July 25, 2018 18:16
Add the META robots noindex for better SEO and avoid duplicate content in Question2Answer forum.
<?php
/*
Plugin Name: SEO Custom Meta-Robots
Plugin URI: https://qrokes.com/
Plugin Description: SEO Custom Meta Robots
Plugin Version: 1.0
Plugin Date:
Plugin Author: QROkes
Plugin Author URI: https://qrokes.com/
Plugin License: GPLv3
@QROkes
QROkes / rc.local
Last active December 24, 2017 22:21
Automatically associate an elastic IP to an EC2 instance.
# Please, enable "Multiverse" in /etc/apt/sources.list
# Add the AWS PPA - sudo apt-add-repository ppa:awstools-dev/awstools
# Update and then install - sudo apt-get update && sudo apt-get install ec2-api-tools
# Upload your AWS Credential (PEM files)
# Save this script in /etc/rc.local
export EC2_KEYPAIR=<name only-not the file name>
export EC2_URL=https://ec2.us-east-1.amazonaws.com
export EC2_PRIVATE_KEY=/var/opt/ec2/<pk-filename.pem>
export EC2_CERT=/var/opt/ec2/<cert-filename.pem>
@QROkes
QROkes / functions.php
Last active November 29, 2017 15:13
Opensearch XML Code (Wordpress)
/* Insert OpenSearch Code (Wordpress) */
add_action( 'wp_head', 'qr_opensearch' );
function qr_opensearch () {
echo '<link rel="search" type="application/opensearchdescription+xml" href="/wp-content/themes/qrokes/opensearch.xml" title="QROkes.com" />' . "";
}
@QROkes
QROkes / functions.php
Created May 10, 2017 01:37
How to use Amazon SES in WordPress.
// Amazon SES (AWS) instead php mail.
add_action( 'phpmailer_init', 'qr_aws_ses_smtp' );
function qr_aws_ses_smtp( $phpmailer ) {
$phpmailer->isSMTP();
$phpmailer->Host = 'email-smtp.us-east-1.amazonaws.com';
$phpmailer->SMTPAuth = true;
$phpmailer->Port = 25;
$phpmailer->Username = 'AWS SES Credentials - username';
$phpmailer->Password = 'AWS SES Credentials - password';
$phpmailer->SMTPSecure = 'tls';
@QROkes
QROkes / functions.php
Created March 25, 2016 03:28
Sends an email notification when a comment receives a reply - WordPress
<?php
/* Based on: https://wordpress.org/plugins/comment-reply-email-notification/ */
add_action('wp_insert_comment', 'qr_comment_notification', 99, 2);
add_action('wp_set_comment_status','qr_comment_status_update', 99, 2);
add_filter('wp_mail_content_type', function($contentType) { return 'text/html'; });
/**
* Sends an email notification when a comment receives a reply
* @param int $commentId The comment ID
@QROkes
QROkes / file.php
Created March 25, 2016 02:23
Download the url to a local temp file and then process it with getimagesize so we can optimize browser layout
<?php
$img_url = 'http://someurl.com/image.jpg';
if ( !empty( $img_url ) ) {
$tmp_file = download_url( $img_url, 10 );
if ( !is_wp_error( $tmp_file ) ) {
$size = getimagesize( $tmp_file );
$img_width = $size[0];
$img_height = $size[1];
@QROkes
QROkes / functions.php
Created March 18, 2016 22:05
Genesis Simple Sidebars for Custom Post Types (WordPress + Genesis Framework)
<?php
add_action( 'genesis_before_sidebar_widget_area', 'qr_remove_default_sidebar' );
function qr_remove_default_sidebar() {
if ( get_post_type() == 'my-cpt' ) { // set CPT here
remove_action( 'genesis_sidebar', 'ss_do_sidebar' );
remove_action( 'genesis_sidebar', 'genesis_do_sidebar' );
add_action( 'genesis_sidebar', 'qr_add_cpt_sidebar' );
}
}
function qr_add_cpt_sidebar() {
@QROkes
QROkes / page.php
Created March 18, 2016 20:55
List custom taxonomy terms (WordPress)
<?php
$args = array( 'hide_empty=0' );
$terms = get_terms( 'my-taxonomy', $args );
if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) {
$count = count( $terms );
$i = 0;
$term_list = '<p class="term-list">Tags: ';
foreach ( $terms as $term ) {
$i++;
$term_list .= '<a href="' . esc_url( get_term_link( $term ) ) . '" alt="' . esc_attr( sprintf( __( 'View all post filed under - %s -', 'my_localization_domain' ), $term->name ) ) . '">' . $term->name . '</a>';
@QROkes
QROkes / functions.php
Created March 18, 2016 19:15
WordPress exclude posts from Loop.
add_action( 'pre_get_posts', 'qr_exclude_tagged_posts' );
function qr_exclude_tagged_posts( $query ) {
if ( $query->is_main_query() && $query->is_home() ) {
$query->set( 'tag__not_in', array( 63 ) );
}
}