Skip to content

Instantly share code, notes, and snippets.

@8ctopotamus
8ctopotamus / wp-generate-i18n.md
Last active August 11, 2019 20:45
Genrate a .pot file for i18n from your source code.
  1. Download https://github.com/wp-mirrors/wp-i18n-tools
  2. Extract contents to /wp-includes
  3. Run following in command line to generate .pot file (Fix paths as needed)

Plugin

php wp-includes/makepot.php wp-plugin wp-content/plugins/YOURPLUGIN/ wp-content/plugins/YOURPLUGIN/YOURPLUGINSLANGFOLDER/YOURPLUGIN.pot

Theme

php wp-includes/makepot.php wp-theme wp-content/themes/YOURTHEME/ wp-content/themes/YOURTHEME/YOURTHEMESLANGFOLDER/YOURTHEME.pot

@8ctopotamus
8ctopotamus / detect-ie.js
Last active April 15, 2019 21:42
Detect IE 11 and tell user to use a real browser ;P
// detect IE
if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/))) {
document.write('<p style="text-align: center;">You are using a browser no longer supported by Microsoft. To use What Plow Fits, please use a <a href="http://outdatedbrowser.com/en" target="_blank">modern browser</a>.</p>')
}
@8ctopotamus
8ctopotamus / .htaccess
Last active September 11, 2020 21:40
Leverage Browser Caching Gzip all the things
# Headers for Mozilla Observatory test #
Header always set Strict-Transport-Security "max-age=31536000" env=HTTPS
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy: no-referrer-when-downgrade
Header set Feature-Policy "vibrate none;
# START EXPIRES CACHING #
@8ctopotamus
8ctopotamus / woocommerce.php
Created November 9, 2018 07:26 — forked from marcosnakamine/woocommerce.php
WooCommerce - Get variable product attributes
<?php $attributes = $product->get_attributes() // GET ALL ATRIBUTES ?>
<?php foreach( $attributes as $key => $value ): ?>
<?php $attribute_name = preg_replace( '/pa_/', '', $key ) // GET ATTRIBUTE NAME ?>
<label>
<select name="attribute_pa_<?php echo $attribute_name ?>" id="attribute_pa_<?php echo $attribute_name ?>">
<option value=""><?php echo $attribute_name ?></option>
<?php $attribute_name = wc_get_product_terms( get_the_ID(), $key ) // GET ATTRIBUTE NAME ?>
<?php $attribute_slug = wc_get_product_terms( get_the_ID(), $key, array( 'fields' => 'slugs' ) ) // GET ATTRIBUTE SLUG ?>
<?php for ( $i=0; $i<count( $attribute_name ); $i++ ): // array_slice BECAUSE ARRAY INDEX IS NOT SEQUENCIAL ?>
<option value="<?php $slug = array_slice( $attribute_slug, $i, 1 ); echo $slug[0]; ?>"><?php $name = array_slice( $attribute_name, $i, 1 ); echo $name[0]; ?></option>
@8ctopotamus
8ctopotamus / var_awesome.php
Last active September 30, 2018 18:38
var_dump() looks like s***. Make it readable for humans.
function var_awesome($value) {
echo '<pre>';
var_export($value);
echo '</pre>';
}
// useage
$example_arr = array('testing', 1, 2, 3);
var_awesome($example_arr);
@8ctopotamus
8ctopotamus / lobff-book-slider.html
Created August 27, 2018 15:31
LOBFF Book slider
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css"/>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.9.0/slick-theme.min.css">
<style>
#nowhere-to-go-book {
display: flex;
flex-direction: column;
align-items: center;
padding: 40px 0;
width: 100%;
@8ctopotamus
8ctopotamus / Dynamically force HTTPS in .htaccess
Created August 23, 2018 19:53
Dynamically force HTTPS in .htaccess
# force HTTPS dynamically
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@8ctopotamus
8ctopotamus / count-repeater-fields-in-acf-flexible-content-example.php
Last active June 27, 2024 13:19
Count number of repeater fields in ACF flexible content.
// Source: https://katienelson.co.uk/developer-acf-counting-repeater-rows-inside-flexible-content/
// The following code doesn’t work with a repeater field if it is part of a flexible content block.
<?php
if(have_rows('card')):
$cards = get_sub_field('card');
$number_of_cards = count($cards);
endif;
?>
@8ctopotamus
8ctopotamus / Expose Custom Post Type (And Taxonomy) as Endpoint to WP JSON API
Last active May 16, 2018 20:59
After adding the properties (indicated by comment: /* Required to expose to WP-JSON API */ ) to your register_post_type() function, you should be able to get your CPT data as JSON by visiting example.com/wp-json/wp/v2/cpt-endpoint.
//Register the post type
register_post_type('podcasts', array(
'label' => 'Podcasts',
'description' => 'A library of podcasts.',
'public' => true,
'show_in_rest' => true, /* Required to expose to WP-JSON API */
'rest_base' => 'podcasts', /* Required to expose to WP-JSON API */
'rest_controller_class' => 'WP_REST_Posts_Controller', /* Required to expose to WP-JSON API */
'show_ui' => true,
'show_in_menu' => true,
@8ctopotamus
8ctopotamus / github-generate-ssh-key.md
Created March 15, 2018 21:21
Generate an SSH key to fix 'could not read Username for 'https://github.com': Invalid argument'

Source: hexojs/hexo-deployer-git#71

error: failed to execute prompt script (exit code 1) fatal: could not read Username for 'https://github.com': Invalid argument

1- Create a ssh key using Git Bash using following command

ssh-keygen -t rsa -b 4096 -C "your-github@email.com"

After running this command just install the by default options and enter the password balnk when it prompts.