Skip to content

Instantly share code, notes, and snippets.

View danielpataki's full-sized avatar

Daniel Pataki danielpataki

View GitHub Profile
@danielpataki
danielpataki / cd.sh
Last active February 12, 2018 16:48
Terminal Basics
cd vvv/www/wordpress-default
cd /users/danielpataki/vvv/www/wordpress-default
@danielpataki
danielpataki / form.php
Last active October 7, 2018 18:21
Movie list with transients
function form( $instance ) {
$title = ( empty( $instance['title'] ) ) ? '' : $instance['title'];
$director = ( empty( $instance['director'] ) ) ? '' : $instance['director'];
?>
<p>
<label for="<?php echo $this->get_field_name( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
function __construct( $config ) {
$this->providers = $config['providers'];
$this->provider = $config['provider'];
// Actions and filters here
}
@danielpataki
danielpataki / chirp-basic.php
Last active October 7, 2018 17:47
Advanced WP: The Basics Of Object Oriented Programming
// Cut text down to required length
function get_chirp_text( $text ) {
return substr( $text, 0, 200 );
}
// Parse hashtags from text
function get_hashtags( $text ) {
preg_match_all("/S*#((?:\[[^\]]+\]|\S+))/", $text, $matches);
return $matches;
}
@danielpataki
danielpataki / action.js
Last active March 5, 2019 13:48
AJAX and WordPress
(function($) {
$(document).on( 'click', '.love-button img', function(){
alert('Love is being given');
})
})( jQuery );
@danielpataki
danielpataki / admin-conditional.php
Last active September 11, 2016 00:22
Enqueueing Scripts In WordPress
function my_enqueue($hook) {
if ( 'edit.php' != $hook ) {
return;
}
wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . 'myscript.js' );
}
add_action( 'admin_enqueue_scripts', 'my_enqueue' );
@danielpataki
danielpataki / addClass.js
Last active July 10, 2016 17:36
Getting Started With jQuery
jQuery('.post .entry-title').addClass('better-entry-title')
@danielpataki
danielpataki / constructor.js
Last active October 9, 2016 08:28
Thinking In Javascript: Objects
function Tweet( text, username ) {
this.text = text;
this.username = username;
this.display = function() {
return this.text + ' - ' + this.username;
}
}
var tweet_1 = new Tweet( 'I love dogs, they are awesome!', '@danielpataki' ),
var tweet_2 = new Tweet( 'Coconut juice is the best thing to drink.', '@danielpataki' ),
@danielpataki
danielpataki / array.pop.js
Last active October 24, 2018 03:41
Thinking In Javascript: The basics
var animals = [ "dog", "cat", "bird" ];
console.log( animals.pop() ); // bird
console.log( animals ) // dog, cat
@danielpataki
danielpataki / copy.sh
Last active May 6, 2016 06:37
Terminal Basics
cp /etc/hosts ~/hosts.txt