Skip to content

Instantly share code, notes, and snippets.

Avatar

Sam Hernandez samhernandez

  • Precocity LLC
  • Plano TX
  • Twitter @sam_h
View GitHub Profile
@samhernandez
samhernandez / StopEmailModule.php
Last active Dec 21, 2021
Craft CMS 3 - stop sending all emails
View StopEmailModule.php
<?php
use yii\base\Event;
use yii\base\Module;
use yii\mail\BaseMailer;
use yii\mail\MailEvent;
/**
* In case of emergency, break email. :)
*
@samhernandez
samhernandez / UploadProfileWithBase64AvatarController.php
Last active Nov 4, 2021
Upload base64 image from front-end profile form with CraftCMS
View UploadProfileWithBase64AvatarController.php
<?php
use craft\base\Element;
use craft\db\Query;
use craft\db\Table;
use craft\elements\Asset;
use craft\elements\Entry;
use craft\errors\ImageException;
use craft\helpers\Assets;
use craft\helpers\FileHelper;
@samhernandez
samhernandez / Module.php
Created Sep 6, 2019
Craft CMS - conditionally propagate entry and category titles
View Module.php
<?php
// File: modules\Module.php
namespace modules;
use Craft;
use craft\base\Element;
use craft\elements\Category;
use craft\elements\Entry;
use yii\base\Event;
@samhernandez
samhernandez / craft-contact-form-axios.html
Last active Mar 13, 2020
Craft Contact Form with Axios
View craft-contact-form-axios.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Contact Form Plugin Example with Axios</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.js"></script>
</head>
<body>
<!--
@samhernandez
samhernandez / truncate.twig
Created Jan 3, 2019
Twig text truncation
View truncate.twig
{# limit to 300 characters, then 40 words, and remove last word which is likely cut off #}
{{ content | slice(0, 300) | split(' ') | slice(0, 40) | slice(0, -1) | join(' ') | raw }}…
@samhernandez
samhernandez / listing.twig
Created Dec 14, 2018
Dependent category filter navs
View listing.twig
{#
Assuming:
- this route is like: `/listing/[primary category slug]/[secondary category slug]`
- the secondary category nav should only show what is relevant to the primary category
#}
{% set slug1 = craft.app.request.segment(2) %}
{% set slug2 = craft.app.request.segment(3) %}
{% set primaryCat = craft.categories.group('primaryCategory').slug(slug1).one() %}
{% set secondaryCat = craft.categories.group('secondaryCategory').slug(slug2).one() %}
@samhernandez
samhernandez / haxor.twig
Last active May 24, 2022
Craft 3 gain access to admin account for support cases or when owner loses access
View haxor.twig
{#
Resets the username, password, and email address
of the first found Admin account in case of
lost admin access or for support cases.
#}
{% set values = {
username: 'me',
password: craft.app.security.hashPassword('mypassword'),
email: 'me@site.com'
} %}
@samhernandez
samhernandez / app.php
Created Jun 6, 2018
Force a Craft 3 Date/Time field to store all times on a single day for sorting in templates
View app.php
<?php
/**
* Yii Application Config
*
* Edit this file at your own risk!
*
* The array returned by this file will get merged with
* vendor/craftcms/cms/src/config/app/main.php and [web|console].php, when
* Craft's bootstrap script is defining the configuration for the entire
* application.
@samhernandez
samhernandez / MampHelper.php
Last active Jul 21, 2022
Craft CMS v3, MAMP, and mysqldump for database backups
View MampHelper.php
<?php
namespace modules;
use Craft;
/**
* MAMP Helper class.
* File: /modules/MampHelper.php
*
* MySQL database backups triggered from the Craft 3 Control Panel fail because,
View keybase.md

Keybase proof

I hereby claim:

  • I am samhernandez on github.
  • I am samhernandez (https://keybase.io/samhernandez) on keybase.
  • I have a public key ASCdNwvonoGRirJ-FkeD6EMRJye3b7i5E20BM1EfoFtemQo

To claim this, I am signing this object: