Skip to content

Instantly share code, notes, and snippets.

View coulterpeterson's full-sized avatar
🤓
Always learning

Coulter Peterson coulterpeterson

🤓
Always learning
View GitHub Profile
@coulterpeterson
coulterpeterson / snippet.sh
Last active October 11, 2023 19:56
List and Export MySQL/mariaDB Databases
# Login to find your db name (optional)
mysql -u username -p
SHOW DATABASES;
EXIT;
# Export
mysqldump -u username -p dbname | gzip > dump.sql.gz
# Copy it from server to local (optional)
@coulterpeterson
coulterpeterson / snippet.html
Created October 4, 2023 18:23
Automatically Updating Copyright Year via JS
<!-- Slick JS 1-liner credit to https://stackoverflow.com/a/4562604 -->
<span>© <script>document.write(new Date().getFullYear())</script> Your Company</span>
@coulterpeterson
coulterpeterson / snippet.php
Created September 19, 2023 20:57
GP Populate Anything Register Custom Data Object
<?php
add_action( 'plugins_loaded', 'register_object' );
function register_object() {
if ( class_exists( 'GP_Populate_Anything' ) && class_exists( 'GPPA_Object_Type' ) ) {
// For a starter class file, you can copy one from source like
// wp-content\plugins\gp-populate-anything\includes\class-object-type-post.php
require_once plugin_dir_path( __FILE__ ) . 'includes/class-object-type-YOURTYPE.php';
gp_populate_anything()->register_object_type( 'yourtype', 'GPPA_Object_Type_YOURTYPE' );
@coulterpeterson
coulterpeterson / snippet.sh
Created September 18, 2023 20:39
Git ignore chmod file permission changes
# Credit https://stackoverflow.com/a/1580644
git config core.fileMode false
@coulterpeterson
coulterpeterson / wordpress-multi-file-upload-snippet.php
Last active September 18, 2023 19:45
WordPress Multi File Upload Helper Function
/**
* Takes in a PHP multi file form field (that uses the name="identifer[]" bracket notation), uploads each attachment,
* provides them with attachment ids, then cleans up after itself.
* Returns: array of attachment ids.
* Example usage: $attachment_ids = multi_file_media_upload($_FILES['multi-upload-field']);
* Example form input field: <input name="myfiles[]" type="file" multiple="true" />
*/
function multi_file_media_upload($multiFile) {
// TODO: Test which of these can be removed for file upload functions used
require_once(ABSPATH . 'wp-admin/includes/media.php');
@coulterpeterson
coulterpeterson / snippet.php
Created August 24, 2023 14:45
WooCommerce General Helper Functions
/**
* Determine if product ID is in cart. Returns true if so, false otherwise.
*/
function is_product_in_cart($product_id) {
$in_cart = false;
foreach( WC()->cart->get_cart() as $cart_item ) {
$product_in_cart = $cart_item['product_id'];
$variation_in_cart = 0;
if( isset( $cart_item['variation_id'] ) ) {
@coulterpeterson
coulterpeterson / snippet.php
Created August 24, 2023 14:30
WooCommerce Limit Cart to 1 Product
/**
* @snippet WooCommerce Max 1 Product @ Cart
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WCooCommerce 7
* @donate $9 https://businessbloomer.com/bloomer-armada/
* Note: technically speaking, the code below will force the product added to cart to replace whatever
* is in the cart, hence will only allow one product in the cart.
* Ref: https://www.businessbloomer.com/woocommerce-allow-1-product-cart/
*/
@coulterpeterson
coulterpeterson / snippet.css
Created June 23, 2023 23:01
Gravity Wiz | File Upload Pro | Hide Error Messages
/* To hide the red error box that's related to the multi-file form field: */
ul[id^='gform_multifile_messages_'] {
display: none;
}
/* Keeping the "Max file size" text while removing the "Max files: 1" part is probably the trickiest CSS rule, however if you're okay with playing with the numbers in this rule, you could try something like this: */
span.gfield_description.gform_fileupload_rules {
max-width: 9.7em;
overflow: hidden;
max-height: 2.3em;
@coulterpeterson
coulterpeterson / snippet.sh
Created June 20, 2023 16:32
WP CLI Add Local Admin Account to Site
wp user create admin [email protected] --user_pass=admin --role=administrator --porcelain
@coulterpeterson
coulterpeterson / how-i-work-template.md
Last active June 19, 2023 23:56 — forked from spivurno/how-i-work-template.md
Template for How I Like to Work posts

How I work

This is my own interpretation of how I like to work, feedback welcome! Especially if my own view of how I think I like to work doesn't match your experience of how it seems I like to work!

When I work

  • Timezone: EST
  • Times/hours you work: ~8am-4pm EST on a regular day
  • How many hours you work in a typical day: 8
  • Weekends y/n? N
  • After hours availability? N