Skip to content

Instantly share code, notes, and snippets.

View luclemo's full-sized avatar

Lucas Lemonnier luclemo

  • Ste-Justine Hospital Research Center
  • Montreal, QC
View GitHub Profile
@luclemo
luclemo / custom-menu-items.php
Last active June 3, 2016 12:39 — forked from frankiejarrett/gist:5224398
Remove menu items from the WP dashboard (ex: remove posts & comments if client doesn't blog) #wordpress
<?php
/**
* Restricts certain menu items from appearing the WP Admin area. Does not
* affect Administrator users.
*
* @action admin_menu
*/
function fjarrett_restrict_admin_menu_items() {
// Don't restrict Administrator users.
@luclemo
luclemo / remove-toolbar.php
Last active June 3, 2016 12:38 — forked from JiveDig/remove_toolbar.php
#wordpress
<?php
//* Remove toolbar from frontend and remove CSS that bumps content down
add_filter( 'show_admin_bar', 'bhl_hide_admin_bar_from_front_end' );
function bhl_hide_admin_bar_from_front_end(){
if ( ! current_user_can('manage_options') ) {
return false;
// Remove CSS
remove_action( 'wp_head', '_admin_bar_bump_cb' );
@luclemo
luclemo / gulpfile-stylus.js
Last active June 3, 2016 12:38
Basic gulpfile configuration for stylus, live reload, and browsersync on a WordPress build. #wordpress
// Load gulp
var gulp = require('gulp'); // npm install gulp --save-dev
// Load necessary packages
var stylus = require('gulp-stylus'); // install --save-dev gulp-stylus
var autoprefixer = require('gulp-autoprefixer'); // npm install gulp-autoprefixer --save-dev
var browserSync = require('browser-sync'); // npm install browser-sync --save-dev
var reload = browserSync.reload; // npm install gulp-livereload --save-dev
// Define the styles task
@luclemo
luclemo / img-functions.php
Last active June 3, 2016 12:37
Image Functions #wordpress
<?php
// function to remove <p> tags on images
add_filter('the_content', 'filter_ptags_on_images');
function filter_ptags_on_images($content){
return preg_replace('/<p>\s*(<a .*>)?\s*(<img .* \/>)\s*(<\/a>)?\s*<\/p>/iU', '\1\2\3', $content);
}
// function to set default image link to none
update_option('image_default_link_type','none');
@luclemo
luclemo / add_svg.php
Last active June 3, 2016 12:36
Add SVG files to the WordPress uploader #wordpress
<?php
function cc_mime_types($mimes) {
$mimes['svg'] = 'image/svg+xml';
return $mimes;
}
add_filter('upload_mimes', 'cc_mime_types');
@luclemo
luclemo / dynamic-image-object.php
Last active December 3, 2015 20:54
Code snippet by Darcy to help me understand dynamic objects in PHP. Props taken from WordPress project (mdupuis)
<?php
// PHP 5.4+
// Dynamically generated images objects
// Properties
$props = array('ID', 'caption', 'title', 'alt', 'sizes');
// Make an images object
$images = new stdClass();
@luclemo
luclemo / repeater_array.php
Last active November 6, 2020 17:42
Creating objects using ACF repeater fields #wordpress #acf
<?php
// check if the repeater field has rows of data
if( have_rows('drop-down_menus') ) :
$array = array(); // empty array, must be declared outside of while loop
$i = 0; // incrementer
// loop through the rows of data and add to our array
while ( have_rows('drop-down_menus') ) : the_row();
@luclemo
luclemo / pricing-models.md
Last active July 31, 2022 16:11
Talk on pricing models for freelancers along with pros and cons #biz

Pricing Models

The following is a rough breakdown of different popular pricing models in freelancing, as well as some pros & cons for each one.

✌️ Note: There is no ONE way to this. Much of your approach to pricing will be influenced by the type of clients & projects you work with, as well your own personality. Also, to this day I have not worked for/with agencies so I will update this doc based on your feedback.

1. Hourly Pricing

It's the model we, and most of North America, is most familiar with.

@luclemo
luclemo / database-sync.md
Last active February 25, 2017 19:25
Manually sync MySQL database between local and staging or live site #wordpress

Export the mysql database for your WordPress to an .sql file. Unzip it (if applicable) to a convenient place on your computer.

NOTE: If you're using phpMyAdmin to do this export (recommended), make sure that you do a "custom" export, scroll down to "Object creation options," and check these two boxes:

[x] Add CREATE DATABASE / USE statement
[x] Add DROP TABLE / VIEW / PROCEDURE / FUNCTION / EVENT statement

Open your .sql file in your preferred text editor. Make the following four changes.

@luclemo
luclemo / google-analytics-plugin-wp.php
Last active March 9, 2019 00:42
Adds a Google analytics tracking code to the <head> of your theme. #wordpress
<?php
/*
Plugin Name: THEME NAME Google Analytics Plugin
Description: Adds a Google analytics tracking code to the <head> of your theme, by hooking to wp_head.
Author: Lucas Lemonnier
*/
/*
* Replace all instances of XXXXXXXXX-X with your GA code
*/