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 / readme.md
Last active June 4, 2025 13:39
How To Import a Bedrock WordPress Project Into LocalWP

How To Import a Bedrock WordPress Project Into LocalWP

  1. Per the official doc from Bedrock, start by creating a new site in Local.
  2. Use the "open site folder" or "open site shell" option, delete the public folder in \Local Sites\YOURSITE\app\
  3. While in \Local Sites\YOURSITE\app, clone your project down into this folder.
  4. Open the .env file in app\YOURREPO\src and ensure:
    • DB_NAME=local
    • DB_USER=root
    • DB_PASSWORD=root
  • WP_HOME='https://YOURSITE.local'
@coulterpeterson
coulterpeterson / snippet.bat
Last active October 17, 2023 15:53
Revive SMB When It Conks Out
# Enable SMB1: Thanks Vasily Sosnovsky at https://learn.microsoft.com/en-us/answers/questions/815154/cant-connect-to-smb-share-windows-cannot-access
DISM /Online /Enable-Feature /All /FeatureName:SMB1Protocol
@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;