Skip to content

Instantly share code, notes, and snippets.

@hereswhatidid
hereswhatidid / pager-view.html
Created November 13, 2013 14:45
Generate a pager.js navigation list based on child page elements.
<div data-bind="page: { id: '?', nameParam: postTypeName }">
<h3><?php _e( 'Editing:', $this->plugin_slug ); ?> <span class="text-success" data-bind="text: label"></span></h3>
<ul class="nav nav-tabs" data-bind="foreach: $page.children">
<li data-bind="css: {active: isVisible}"><a data-bind="text: $data.val('title'), page-href: $data"></a></li>
</ul>
<div class="tab-pane" data-bind="page: { id: 'general', title: '<?php _e( 'General', $this->plugin_slug ); ?>' }">
<?php include_once( 'posttypes/edit-tab-general.php' ); ?>
</div>
<div class="tab-pane" data-bind="page: { id: 'features', title: '<?php _e( 'Features', $this->plugin_slug ); ?>' }">
<?php include_once( 'posttypes/edit-tab-features.php' ); ?>
@hereswhatidid
hereswhatidid / gallery-override.php
Created November 20, 2013 22:56
Override the [gallery] shortcode in WordPress
@hereswhatidid
hereswhatidid / shortcodes-exist.php
Last active December 29, 2015 13:29
Detect the existence of multiple shortcodes at one time via an array of strings within WordPress.
<?php
/**
* Loop through an array of shortcodes and check for their existence
* @author Gabe Shackle <gabe@hereswhatidid.com>
* @param array $shortcodes An array of shortcode strings
* @param boolean $match_all Whether to check for the existence of ALL the shortcodes, or just ANY of them
* @return mixed The results will either be an array of the found shortcodes or boolean false
*/
function shortcodes_exist( $shortcodes = array(), $match_all = false ) {
$found_shortcodes = array();
@hereswhatidid
hereswhatidid / clear-submenu.php
Created January 6, 2014 05:17
Hide secondary duplicate menu when creating a menu page within WordPress
<?php
$this->plugin_screen_hook_suffix = add_menu_page(
__( 'Content Toolkit', $this->plugin_slug ),
__( 'Content Toolkit', $this->plugin_slug ),
'manage_options',
$this->plugin_slug,
array( $this, 'display_plugin_admin_page' )
);
add_submenu_page(
$this->plugin_slug,
@hereswhatidid
hereswhatidid / sample-usage.html
Last active January 3, 2016 02:19
Knockout binding handler for select with other field inputs
<div class="col-lg-4" data-bind="selectWithOther: query_var, selectWithOtherOptions: { selectField: '#post-type-query_var', textField: '#post-type-query_var_text' }">
<label for="post-type-query_var"><?php _e( 'Query Variable', $this->plugin_slug ); ?></label>
<select id="post-type-query_var" class="form-control">
<option value="true"><?php _e( 'Default', $this->plugin_slug ); ?></option>
<option value="false"><?php _e( 'None', $this->plugin_slug ); ?></option>
<option value="other"><?php _e( 'Custom', $this->plugin_slug ); ?></option>
</select>
<span class="help-block"><?php _e( 'Sets the query_var key for this post type.', $this->plugin_slug ); ?></span>
</div>
<div class="col-lg-4">
@hereswhatidid
hereswhatidid / lastfour-and-type.php
Last active January 4, 2016 03:28
Get the last four digits and card type from an Offline Credit Card order in PrestaShop.
<?php
protected function getCardType( $ccNum ) {
if (preg_match("/^5[1-5][0-9]{14}$/", $ccNum))
return "Mastercard";
if (preg_match("/^4[0-9]{12}([0-9]{3})?$/", $ccNum))
return "Visa";
if (preg_match("/^3[47][0-9]{13}$/", $ccNum))
return "American Express";
@hereswhatidid
hereswhatidid / email.php
Last active February 12, 2016 14:23
ACF field generation code.
<?php
array (
'key' => 'field_56bde9a0ea676',
'label' => 'Email',
'name' => 'email',
'type' => 'email',
'instructions' => '',
'required' => 0,
'conditional_logic' => 0,
'wrapper' => array (
@hereswhatidid
hereswhatidid / retina-media-query.css
Created May 9, 2016 19:48
Retina-specific media query
@media(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
/* Retina-specific stuff here */
}
@hereswhatidid
hereswhatidid / show_errors.php
Created October 7, 2013 18:54
PHP force show all errors
<?php
// ----------------------------------------------------------------------------------------------------
// - Display Errors
// ----------------------------------------------------------------------------------------------------
ini_set('display_errors', 'On');
ini_set('html_errors', 0);
// ----------------------------------------------------------------------------------------------------
// - Error Reporting
@hereswhatidid
hereswhatidid / example-usage.php
Last active September 8, 2017 16:57
Plugin for adding any field as an attribute to the WooCommerce CSV import
<?php
function hwid333_add_custom_attribute_columns( $fields ) {
$fields[] = array(
'slug' => 'shirt-size',
'name' => 'Shirt Size', // This is the name of the column in the CSV
);
$fields[] = array(