Skip to content

Instantly share code, notes, and snippets.

View marcosnakamine's full-sized avatar

Marcos Nakamine marcosnakamine

View GitHub Profile
@marcosnakamine
marcosnakamine / funcstions.php
Created April 10, 2017 20:40
WordPress - Deny access for admin pages
<?php
add_filter( 'init', 'exclude_pages_from_normal_admin' );
function exclude_pages_from_normal_admin() {
global $pagenow;
$deny_pages = array(
'edit.php',
'update-core.php',
'upload.php',
'edit-comments.php',
@marcosnakamine
marcosnakamine / index.php
Created April 10, 2017 18:21
PHP - Google Invisible reCAPTCHA example
<html>
<head>
<title>reCAPTCHA demo: Simple page</title>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("demo-form").submit();
}
</script>
</head>
@marcosnakamine
marcosnakamine / index.php
Created April 4, 2017 17:42
WordPress - Get current categories
<?php
var_dump( get_the_category() ); // use in wp loop
/*
object(WP_Term)#306 (16) {
["term_id"]=>
int(49)
["name"]=>
string(6) "Markup"
["slug"]=>
string(6) "markup"
@marcosnakamine
marcosnakamine / script.sh
Created April 4, 2017 14:46
Git - Change last commited message
git commit --amend -m "New commit message"
@marcosnakamine
marcosnakamine / script.js
Created April 3, 2017 16:50
jQuery Fancybox - Close parent window from iframe
parent.$.fancybox.getInstance().close();
@marcosnakamine
marcosnakamine / script.js
Created April 3, 2017 16:47
jQuery Fancybox - Open iframe with fixed width and height
$.fancybox.open({
src:'url',
type:'iframe',
opts:{
iframe:{
css:{
width:1000,
height:1000
}
},
@marcosnakamine
marcosnakamine / index.php
Last active April 3, 2017 16:51
Sendy - Add contact in newsletter list via ajax
<?php
//------------------- Edit here --------------------//
$sendy_url = 'http://url';
$list = 't'; // LIST ID
//------------------ /Edit here --------------------//
//--------------------------------------------------//
//POST variables
$name = $_POST['name'];
$email = $_POST['email'];
@marcosnakamine
marcosnakamine / script.sh
Last active March 30, 2017 21:14
Shell - Change the quality of all images in the folder
#!/bin/bash
IFS=$'\n'
for i in `find -name '*.jpg'`
do mogrify -quality 80% "$i"
done
@marcosnakamine
marcosnakamine / index.php
Created March 30, 2017 14:01
PHP - MySQLi mysqli_connect, query, fetch_array, mysqli_escape_string
<?php
$db = mysqli_connect( 'host','user_name','password', 'data_base_name' );
$query = $db->query('
SELECT * FROM table_name
WHERE id = mysqli_escape_string( $db, '1' )
');
if( $query->num_rows > 0 ){
while ( $row = $query->fetch_array() ) {
@marcosnakamine
marcosnakamine / index.php
Created March 28, 2017 19:55
WordPress - Open fancybox on page with gallery and iframe in others
<ul>
<?php wp_nav_menu(); ?>
</ul>
<div class="hidden-gallery">
<?php
function get_image_gallery_src( $post_id ) {
$gallery = get_post_gallery( $post_id, false );
$gallery_id = explode( ',', $gallery['ids'] );