Skip to content

Instantly share code, notes, and snippets.

View DanBeckett's full-sized avatar

Dan Beckett DanBeckett

  • Lancashire
View GitHub Profile
@DanBeckett
DanBeckett / .htaccess
Created October 30, 2018 01:52
magento 2 pub/static .htaccess
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
<IfModule mod_php7.c>
php_flag engine 0
</IfModule>
# To avoid situation when web server automatically adds extension to path
Options -MultiViews
@DanBeckett
DanBeckett / .htaccess
Created September 8, 2015 10:18
Blocking Referral Spam within your .htaccess
# Make sure our server has the rewrite module active.
# (This is very standard - it almost certainly will)
<IfModule mod_rewrite.c>
# Let the system know we’re configuring redirections here
RewriteEngine on
# Now let’s list our redirections (technically these are known as “Rewrite Conditions”.)
RewriteCond %{HTTP_REFERER} ^http://.*referrerurlone\.com/ [NC,OR]
@DanBeckett
DanBeckett / stackex_168749.php
Created November 18, 2014 14:19
List WordPress category terms, apply parent class to any terms with children
<?php
$terms = get_terms('category');
if ( !empty( $terms ) && !is_wp_error( $terms ) ){
foreach( get_terms( 'category', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
$term_children = get_term_children($parent_term->term_id, 'category'); ?>
<li class="term_item<?php echo ($term_children ? ' parent' : ''); ?>" data-hook="<?php echo $parent_term->slug; ?>">
<a href="<?php echo home_url(); ?>/products/<?php echo $parent_term->slug; ?>"><?php echo $parent_term->name; ?></a>
</li>
<?php }
} ?>
@DanBeckett
DanBeckett / stackex_165855.php
Created October 28, 2014 13:30
List WordPress pages in and not in a specific category
<!-- Quick solution for a question on StackExchange,
running through site pages, and compiling a ul of
pages in a category and a ul of pages that aren't. -->
<?php $args = array(
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => -1
);
@DanBeckett
DanBeckett / gforms_address_uk_postcode_validation
Last active March 29, 2018 13:15
Validate Gravity Forms standard multi-part Address field to check for a UK Valid Postcode
add_filter("gform_field_validation_[FORM_ID]_[FIELD_ID]", "uk_postcode_validation", 10, 4);
function uk_postcode_validation($result, $value, $form, $field){
//address field will pass $value as an array with each of the elements as an item within the array, the key is the field id
$postcode = $value["[FIELD_ID].5"];
//the default regex is valid both with and without the space in the middle.
//to force the space, replace with the following:
//'#^(GIR ?0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]([0-9ABEHMNPRV-Y])?)|[0-9][A-HJKPS-UW]) [0-9][ABD-HJLNP-UW-Z]{2})$#'
@DanBeckett
DanBeckett / print_with_pre_function
Last active August 29, 2015 14:04
Simple function to display an array or object with the pre tags already added.
function print_with_pre($variable, $show=false) {
if($show===true) {
$style = '';
} else {
$style = ' style="display: none;"';
};
$variable_to_show = print_r($variable, true);
$html = '<pre'.$style.'>'.$variable_to_show.'</pre>';
echo $html;
@DanBeckett
DanBeckett / CodaSSHConfigFileCommented
Last active August 29, 2015 14:03
Config File Solution for Coda SSH Errors
//This file is just a guide, don't include the comments in Coda.
//To directly add, copy the stripped down "config" file instead.
Host sitedev // the nickname you give the project. set Coda’s “nickname” and “server” the same
HostName access.b1.server.com // the SSH address provided
User user123 // the SSH username
IdentityFile ~/.ssh/id_rsa // path to your SSH key
Port 22 // port. usually 22 unless specified differently
//Coda Project settings
@DanBeckett
DanBeckett / get_term_object_from_uri
Created June 17, 2014 15:04
Quick function to convert a permalink into a term object when inside a custom taxonomy
function get_term_object_from_uri($taxonomy) {
global $wp;
//get requested uri
$wp_request = $wp->request;
//split into array
$uri_params = explode('/', $wp_request);
//drop the product id as unnecessary
$param_total = (count($uri_params)-1);
unset($uri_params[$param_total]);