Skip to content

Instantly share code, notes, and snippets.

View dariodev's full-sized avatar

Dario Devcic dariodev

  • Zagreb
View GitHub Profile
@dariodev
dariodev / calc-read-time.php
Created January 18, 2017 11:05 — forked from norcross/calc-read-time.php
calculate and display an estimated reading time
<?php
/**
* handle the calculation
* @param integer $seconds [description]
* @return [type] [description]
*/
function rkv_calc_read_time( $seconds = 0 ) {
// calc the minutes
@dariodev
dariodev / gist:a9b969605fe8b65aa790b2a0759d8b26
Created January 4, 2017 20:18
WooCommerce - Show number of items in cart and total
<a class="cart-contents" href="<?php echo wc_get_cart_url(); ?>" title="<?php _e( 'View your shopping cart' ); ?>"><?php echo sprintf ( _n( '%d item', '%d items', WC()->cart->get_cart_contents_count() ), WC()->cart->get_cart_contents_count() ); ?> - <?php echo WC()->cart->get_cart_total(); ?></a>
@dariodev
dariodev / functions.php
Created November 15, 2016 13:30
Adding author role in body class
<?php
// Add role class to body
function add_role_to_body($classes) {
global $current_user;
$user_role = array_shift($current_user->roles);
// add class 'role-user_role' to the $classes array
$classes[] = 'role-'. $user_role;
@dariodev
dariodev / just_another_input_inset.css
Last active September 22, 2016 14:18
The perfect inset box shadow input field for my project.
input {
background: #fff;
color: #525865;
border-radius: 4px;
border: 1px solid #d1d1d1;
box-shadow: inset 1px 2px 8px rgba( 0, 0, 0, 0.07);
font-family: inherit;
font-size: 1em;
line-height: 1.45;
outline: none;
@dariodev
dariodev / functions.php
Last active June 17, 2021 06:17
Programmatically Create a User in WordPress
<?php
// Programmatically Create a User in WordPress
add_action('init', 'prefix_add_user');
function prefix_add_user() {
$username = 'username123';
$password = 'pasword123';
$email = '[email protected]';
$user = get_user_by( 'email', $email );
if( ! $user ) {
@dariodev
dariodev / functions.php
Last active April 25, 2016 15:06
WooCommerce - Removing a product from the cart programatically
<?php
add_action( 'template_redirect', 'remove_product_from_cart' );
function remove_product_from_cart() {
// Run only in the Cart or Checkout Page
if( is_cart() || is_checkout() ) {
// Set the product ID to remove
$prod_to_remove = 58;
// Cycle through each product in the cart
@dariodev
dariodev / high-dpi-media.css
Created January 15, 2016 16:53 — forked from marcedwards/high-dpi-media.css
A CSS media query that captures almost all high DPI aware devices.
/* ---------------------------------------------------------- */
/* */
/* A media query that captures: */
/* */
/* - Retina iOS devices */
/* - Retina Macs running Safari */
/* - High DPI Windows PCs running IE 8 and above */
/* - Low DPI Windows PCs running IE, zoomed in */
/* - Low DPI Windows PCs and Macs running Firefox, zoomed in */
/* - Android hdpi devices and above */
@dariodev
dariodev / register-post-type.php
Created October 6, 2015 00:56 — forked from justintadlock/register-post-type.php
Help file when registering post types.
<?php
/* Register custom post types on the 'init' hook. */
add_action( 'init', 'my_register_post_types' );
/**
* Registers post types needed by the plugin.
*
* @since 0.1.0
* @access public
@dariodev
dariodev / wp-via-ssh.el
Last active March 14, 2016 14:22
Install WordPress via SSH
1. SSH, then navigate to your domain’s web root (example path for serverpilot managed server)
/srv/users/serverpilot/apps/myapp/public
2. Get the latest WP install
wget http://wordpress.org/latest.tar.gz
3. Unpack the archive
tar zxf latest.tar.gz
4. Navigate to the wordpress directory
@dariodev
dariodev / wc-quantity-increment.js
Last active September 21, 2015 12:45 — forked from webaware/gist:ebdb30dc33714f04e32b
Adds Quantity Increment buttons that were depreciated as of WooCommerce 2.3
jQuery(function($) {
// Quantity buttons
$( 'div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)' ).addClass( 'buttons_added' ).append( '<input type="button" value="+" class="plus" />' ).prepend( '<input type="button" value="-" class="minus" />' );
$( document ).on( 'click', '.plus, .minus', function() {
// Get values
var $qty = $( this ).closest( '.quantity' ).find( '.qty' ),