Skip to content

Instantly share code, notes, and snippets.

@WPAcademic
WPAcademic / relatedRecordOnAccount.cls
Last active January 20, 2023 20:41
Trigger Apex Bulk DML on Trigger
/**
* The trigger fires after accounts are inserted or updated. The trigger adds a default opportunity for every account that doesn’t already have an opportunity. 
*/
trigger AddRelatedRecord on Account (after insert, after update) {
List<Opportunity> oppList = new List<Opportunity>();
// this will be determined by the operation type
List<Account> toProcess = null;
<?php
/**
* Plugin Name: Get ACF Field Label from Name
* Plugin URI: https://wpacademic.com
* Version: 1.0.0
* Author: Louis Fico
* Author URI: https://profiles.wordpress.org/louis
* Description: Adds function to get ACF field name from its label
* License: GPL2
*/
@WPAcademic
WPAcademic / functions.php
Created July 17, 2020 15:23
WordPress Create a New User Account
add_action('init', function() {
$user = 'Username';
$pass = 'P@ssword';
$email = 'email@domain.com';
if ( !username_exists( $user ) && !email_exists( $email ) ) {
$user_id = wp_create_user( $user, $pass, $email );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
@WPAcademic
WPAcademic / functions.php
Created July 17, 2020 14:52
Reset WordPress Password From Username
add_action('init', function() {
$userName = 'admin';
$passwordToSet = 'testing';
$userObj = get_user_by('login', $userName);
// $userEmail = 'user@example.com';
// $userObj = get_user_by( 'email', $userEmail );