Skip to content

Instantly share code, notes, and snippets.

View patrickgilmour's full-sized avatar

Pat Gilmour patrickgilmour

  • Self-employed
  • Brookyln, New York, USA
View GitHub Profile
@patrickgilmour
patrickgilmour / dayone-import-from-ulysses-text-file.scpt
Last active November 6, 2021 20:08
AppleScript to import Ulysses text files to DayOne
--Script to import text files (Markdown)
--exported from External folder in Ulysses (Mac)
--to a Finder folder THE_FOLDER
--Imports entries from that folder with tags (Keywords) and removes tags
--from body of the entry
--Entry date is same as Creation Date of text file
--Required DayOne CLI tool installed on Mac
tell application "Finder"
@patrickgilmour
patrickgilmour / woocommerce-remove-admin-menu.php
Created June 26, 2014 14:39
Remove WooCommerce Admin Menu for everyone except Administrators
<?php
/**
* Remove the WooCommerce admin menu for everyone except WordPress Administrators
*
*/
add_action( 'admin_menu', 'remove_menus' );
function remove_menus(){
// If the current user is not an admin
@patrickgilmour
patrickgilmour / woocommerce-simple-or-variable.php
Created June 27, 2014 17:57
WooCommerce conditional to test if a Product is Simple or Variable.
<?php
/**
* Is a WooCommerce Product Simple or Variable
*
* see http://wordpress.org/support/topic/condition-to-check-if-product-is-simple-or-variable
*/
if( $product->is_type( 'simple' ) ){
// a simple product
@patrickgilmour
patrickgilmour / woocommerce-filter-single-product-page-title.php
Created June 27, 2014 19:18
Filter the Title of a WooCommerce Product on the Single Product Page
<?php
/**
* Rename/Filter the Title of a WooCommerce Product on the Single Product Page
*
*/
add_filter('the_title', 'xcsn_single_product_page_title', 10, 2);
function xcsn_single_product_page_title($title, $id) {
if( ( is_product() && in_the_loop() ) ) {
@patrickgilmour
patrickgilmour / wp-get-image-alt-text.php
Created June 28, 2014 14:20
WordPress Images - echo the Alt text of the Featured image (and other image attributes)
<?php
/**
* Get the Alt text of a Featured Image
*
* And other image attributes
*/
add_action('genesis_before_sidebar_widget_area', 'pgwp_genesis_before_sidebar_widget_area' );
function pgwp_genesis_before_sidebar_widget_area () {
@patrickgilmour
patrickgilmour / truncate-string-to-word.php
Created October 13, 2015 21:38
Truncates a string to the nearest defined word boundary.
<?php
// Truncates a string to 275 characters to the nearest word
// from: preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, 201));
$the_substring = preg_replace('/\s+?(\S+)?$/', '', substr( $the_string , 0, 275));
@patrickgilmour
patrickgilmour / Rewrite-to-HTTPS-for-MAMP
Last active October 12, 2015 20:12
MAMP - Force Host to use https for all pages using rewrites in MAMP
# Paste the following into the Additional Parameters for <Virtual Host> field of the "Hosts" tab in MAMP (Pro)
# Restart MAMP
# Now when you type http://thishost MAMP with forward the request to https://thishost
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
@patrickgilmour
patrickgilmour / gravity-forms-scroll-jump.php
Last active August 30, 2015 20:45
On submitting a Gravity Form (with id of 25), the response page will jump to top of the page minus 1 px
/**
* Gravity Forms - scroll to the top of page on form submit
*
* Returns a value of 1px from the top.
*/
add_filter( 'gform_confirmation_anchor_25', function() {
return 1;
} );
@patrickgilmour
patrickgilmour / option_page_capability.php
Last active August 29, 2015 14:27
option_page_capability
<?php
/**
* Allow users with capability 'my_edit_settings' to edit the `my_plugin_options` settings of your Plugin
*
* This avoids giving them 'manage_options' capabilities
*
* @category WordPress
* @see https://codex.wordpress.org/Function_Reference/add_options_page
*
/**
* WooCommerce enqueues 3 stylesheets by default. You can disable them all using:
*
* see http://docs.woothemes.com/document/disable-the-default-stylesheet/
*/
add_filter( 'woocommerce_enqueue_styles', '__return_false' );