Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dhaupin
dhaupin / dev_wp_shortcode_woo_login_register.php
Last active November 15, 2020 06:16
Wordpress shortcode to display WP or Woocommerce login forms
<?php
/**
* Shortcode - Render Wordpress login form
**/
add_shortcode('wp_login_form', function() {
if (is_user_logged_in()) {
} else {
ob_start();
@dhaupin
dhaupin / dev_script_ckeditor_plugin_wrapper.js
Last active June 28, 2017 18:51
CKEditor - Example Plugin Wrapper/Init for Config.js - Extending Autosave
// Make sure you include the plugin_wrapper as last item in config.extraPluins
CKEDITOR.editorConfig = function(config) {
config.extraPlugins = 'autosave,plugin_wrapper';
// Define empty autosave object
config.autosave = {};
}
// Extend instance plugins
CKEDITOR.plugins.add('plugin_wrapper', {
@dhaupin
dhaupin / dev_script_get_date_offset.php
Last active June 7, 2017 17:44
Function: Get date offset accounting for weekends and holidays
<?php
// Requires PHP 5.4+
function getWorkingDaysFrom($start, $amtOfDays) {
$globalDays = 0; // a global addition to $amtOfDays (such as a minimum shipping time of 3 days across all objects)
$amtOfDays = $amtOfDays + $globalDays; // set base amount of days for initial range before calculations applied
$ignore = array('6', '7'); // days of the week to ignore (weekends are 6 & 7) in ISO-8061
$holidays = array(
(new DateTime('first monday of january +1 year'))->format('*-m-d'), // new years day (celebrated)
@dhaupin
dhaupin / dev_opencart_img_check.php
Last active October 3, 2018 04:47
Opencart - Crawls over database looking for images/pdfs used and outputs them as a simple text list. CP/Rclone/PHP can use this list to truncate out unused files.
<?php
# Idea from: https://github.com/zenseo/opencart-needless-image
# PHP is not good enough to run this through a large store with many images
# Bash cp cant hold enough arguments from file output unless its batched
# Rclone is the best bet:
# rsync -asv --dry-run --recursive --remove-source-files --checksum --files-from=some-file.txt . destination/
function findImages() {
$tables_to_check = array(
@dhaupin
dhaupin / dev_script_colorbox_init.js
Created May 18, 2017 15:04
Script - Colorbox initialization with back button support
<script type="text/javascript">
$(document).ready(function() {
$('.colorbox').colorbox({
onLoad: function() {
history.pushState(null, document.title + ' [colorbox-active]', window.location.pathname + window.location.search + '#colorbox-active');
window.onpopstate = function(event) {
$.colorbox.close();
};
},
onClosed: function() {
@dhaupin
dhaupin / etc_bash.bashrc.sh-whm
Last active May 24, 2017 15:51
Bash functions to Increase/decrease WHM backend PHP limits
cyan=$(tput setaf 6)
bold=$(tput bold)
reset=$(tput sgr0)
whm-max() {
# Boosts WHM power for exports/imports
if [ -z "$1" ]; then
vars="3000"
else
vars=$1
@dhaupin
dhaupin / dev_smarty_cheatsheat.txt
Last active May 10, 2017 18:39
Smarty - Handy Snippets
## Grabbing a dispatch from CS-Cart
{if $smarty.request.dispatch == 'index.index'}
## Grabbing user group from CS-Cart
{$auth.usergroup_ids[2]}
## Admin user condition from CS-Cart
## $_SESSION prob isnt available, so $auth works instead
{if $auth.user_id && $auth.user_type == 'A'}
@dhaupin
dhaupin / dev_cli_cpanel_update_hooks.txt
Created April 28, 2017 15:03
Example - WHM/cPanel Update Hooks
# https://documentation.cpanel.net/display/SDK/Guide+to+Standardized+Hooks+-+The+manage_hooks+Utility
# To add a script to upcp schema (as a hook)
/usr/local/cpanel/bin/manage_hooks add script /root/src/cpanel-hooks/postupcp.sh --manual --category System --event upcp --stage post
# To remove a script as hook from upcp schema
/usr/local/cpanel/bin/manage_hooks delete script /root/src/cpanel-hooks/postupcp.sh --manual --category System --event upcp --stage post
# To list current hooks (
/usr/local/cpanel/bin/manage_hooks list
@dhaupin
dhaupin / userDefineLang.xml
Created April 20, 2017 18:25
Config - Notepad++ Smarty TPL Highlighting
<NotepadPlus>
<UserLang name="Smarty-DH" ext="tpl" udlVersion="2.1">
<Settings>
<Global caseIgnored="no" allowFoldOfComments="no" foldCompact="no" forcePureLC="0" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="yes" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="no" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00{* 01 02*} 03 04*</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@dhaupin
dhaupin / dev_script_install_uninstall_functions.php
Created April 13, 2017 18:00
Snippet - Table field install/uninstall functions
<?php
// These 3 functions are part of a more extensive module class
private function chkField($table, $field) {
$field = $this->db->query("DESC " . DB_PREFIX . $table . " '%" . $field . "%'");
if ($field->row) {
return true;
}