Skip to content

Instantly share code, notes, and snippets.

@afuggetta
afuggetta / helper.sol
Created July 21, 2017 12:23
Helper functions contract solidity
pragma solidity ^0.4.6;
contract Helper {
function lowercaseString(string self) internal constant returns (string) {
bytes memory a = bytes(self);
for (uint i = 0; i < a.length; i++) {
if (uint8(a[i]) >= 0x41 && uint8(a[i]) <= 0x5A) {
a[i] = byte(uint8(a[i]) + 0x20);
}
}
@afuggetta
afuggetta / custom-myaccount-section.php
Created August 26, 2016 14:00
Wocoomerce add to my account
<?php
/**
* Register new endpoint to use inside My Account page.
*
* @see https://developer.wordpress.org/reference/functions/add_rewrite_endpoint/
*/
function my_custom_endpoints() {
add_rewrite_endpoint( 'webinars', EP_ROOT | EP_PAGES );
}
@afuggetta
afuggetta / wp-list-actions.php
Created August 17, 2016 17:49
WordPress list all actions
<?php
add_action( 'shutdown', function() {
foreach( $GLOBALS['wp_actions'] as $action => $count ) {
printf( '%s (%d) <br/>' . PHP_EOL, $action, $count );
}
});
@afuggetta
afuggetta / pull-images.sh
Last active July 5, 2016 16:06
Pull images from server WP
for upload in `mysql -u root database_name -e "select meta_value from wp_postmeta where meta_key='_wp_attached_file';" | grep 2016`; \
do echo $upload; \
wget "https://url.net/wp-content/uploads/$upload" -P `dirname $upload`; \
done
@afuggetta
afuggetta / cookie.js
Created October 19, 2015 21:10
Cookie object javascript
@afuggetta
afuggetta / center-element.scss
Created September 3, 2015 19:08
Centering elements in css
@mixin vertical-align($position: relative) {
position: $position;
top: 50%;
-webkit-transform: translateY(-50%);
-ms-transform: translateY(-50%);
transform: translateY(-50%);
}
@afuggetta
afuggetta / twitterembed.js
Created August 13, 2015 21:39
Check twitter embed iframe is loaded
//Load/Enqueue the twitter widgets.js
window.twttr.ready(function (twttr) {
// At this point the widget.js file had been loaded.
// We can now make use of the twttr events
twttr.events.bind('rendered', function (event) {
// At this point the tweet as been fully loaded
// and rendered and you we can proceed with our Javascript
window.console.log("Created widget", event.target.id);
});
});
@afuggetta
afuggetta / taxonomies.php
Last active August 29, 2015 14:25
Hook into taxonomies
<?php
//Categories hooks
add_action( 'edit_category_form_fields', [ $this, 'coresales_category_custom_fields' ] );
add_action( 'category_add_form_fields', [
$this,
'coresales_category_custom_fields'
] ); //@see https://developer.wordpress.org/reference/hooks/taxonomy_add_form_fields/
add_action( 'create_category', [ $this, 'coresales_category_save' ] );
add_action( 'edit_category', [ $this, 'coresales_category_save' ] );
@afuggetta
afuggetta / media.js
Created June 25, 2015 19:44
Javascript to handle a media upload
/* global jQuery, wp */
/**
* To enqueue in admin:
* $template_dir = get_template_directory_uri();
* //Enqueue necessary scripts for using WP JS media library
* wp_enqueue_media();
* //Custom JS for admin
* wp_enqueue_script( 'coresales-admin-scripts', $template_dir . '/javascripts/coresales_media_admin.min.js', array( 'jquery' ), 1.0, true );
*/
//Setting Ajax handlers
add_action( 'wp_ajax_nopriv_get_author_info', array( $this, 'bps_get_author_info_cb' ) );
add_action( 'wp_ajax_get_author_info', array( $this, 'bps_get_author_info_cb' ) );
/**
* Function used to get author info for popup on article
*/
public function bps_get_author_info_cb() {
global $coauthors_plus;
//Checking nonce