Skip to content

Instantly share code, notes, and snippets.

View mikeott's full-sized avatar
😀
Greetings programs. See you on the grid.

Michael Ott mikeott

😀
Greetings programs. See you on the grid.
View GitHub Profile
@mikeott
mikeott / fix-double-lines-issue.txt
Last active July 29, 2022 08:01
Fix double lines issue using a regular expression
Using a regx search, search your file for...
[\r\n]{2,}
...and replace with ...
\n
@mikeott
mikeott / wordpress-plugin-css-cache-buster.php
Last active March 14, 2019 03:43
WordPress plugin CSS cache buster (based on plugin version number)
/*
Add custom stylesheet into plugin admin.
This method appends the plugin version number to the stylesheet for easy CSS cache busting.
If your plugin is at version 1.0 the styesheet URL will look like this:
https://example.com/wp-content/plugins/your-plugin/css/your-plugin-style.css?ver=1.0
Any time you update your plugin version number, the query string value will match it.
*/
function your_plugin_style() {
@mikeott
mikeott / wordpres-custom-css.php
Last active July 29, 2022 07:57
WordPress: include custom CSS file if page slug matches CSS file name.
/* Check if css file of slug name exists and if it does, include stylesheet for that slug */
function check_for_css() {
global $post;
$post_slug = $post->post_name;
$filename = get_template_directory() . '/css/' . $post_slug . '.css';
if (file_exists($filename)) {
echo '<link rel="stylesheet" id="' . $post_slug . '-css" href="' . get_template_directory_uri() . '/css/' . $post_slug . '.css" type="text/css" media="all" />';
}
@mikeott
mikeott / add-custom-radio-buttons-to-woo-checkout.php
Last active April 1, 2024 13:42
Add custom radio buttons to Woo checkout
<?php
/*
Add custom delivery radio buttons to checkout.
Requires WooCommerce v3+
Add your radio buttons.
Remove the 'required' attribute if these are to be optional.
*/
add_action( 'woocommerce_review_order_before_payment', 'display_extra_fields_after_billing_address' , 10, 1 );
function display_extra_fields_after_billing_address () { ?>
@mikeott
mikeott / scroll-down-page-on-page-load.js
Last active July 29, 2022 07:52
Scroll down page on page load
/* jQuery */
$( document ).ready(function() {
window.scroll(0,400);
});
@mikeott
mikeott / insert-gravity-forms-field-entries-into-database-table-after-form-submission.php
Last active July 29, 2022 07:50
Insert Gravity Forms field entries into database table after form submission
/*
Add to functions.php
*/
add_action( 'gform_after_submission_2', 'capture', 10, 2 ); /* gform_after_submission_2 = form ID 2 */
function capture( $entry, $form ) {
global $wpdb;
$table= $wpdb->prefix . 'my_table';
$end_date = $entry['4']; /* Field ID 4 */
@mikeott
mikeott / load-custom-css.php
Last active September 23, 2020 02:06
Load Custom Page CSS (WordPress)
<?php /*
Check if css file of slug name exists and if it does, include stylesheet for that slug.
Place in functions.php or make it a plugin.
What is this for?
If you need to add some custom CSS for a particular page, then this script will make that possible.
Simply create a .css file with the name of the page slug (example: about-our-company.css) and place it in the theme /css/ folder.
This CSS file will be automatically loaded when the page is visited.
@mikeott
mikeott / check-for-template.php
Last active March 14, 2023 23:16
WordPress: Check if a custom template exists in the theme folder, if not, then use the plugin template file
<?php
// The template
$template = 'my-custom-script.php';
// If a template file exists in the theme folder, use it.
if ( $theme_file = locate_template( array( 'my-custom-files/' . $template ) ) ) {
include(get_template_directory() . '/my-custom-files/' . $template);
} else { // Otherwise, use the plugin template file.
include(plugin_dir_path( __FILE__ ) . '/templates/' . $template);
}
@mikeott
mikeott / list-all-google-fonts.php
Last active November 11, 2020 07:30
List all Google fonts (for use in a WordPress plugin)
<?php
/*
You'll need to get an API key.
Go to https://developers.google.com/fonts/docs/developer_api and scroll down to the 'Gey a Key' button.
*/
$api_key = "your-key-here";
$google_font = isset($options['google_font']) ? $options['google_font'] : '';
$url = 'https://www.googleapis.com/webfonts/v1/webfonts?key=' . $api_key;
$args = array(
'timeout' => 15,
@mikeott
mikeott / Compare local and remote plugin versions.php
Last active July 29, 2022 08:03
WordPress: Compare local and remote plugin versions (WordPress)
<?php function my_current_plugin_version() {
$plugin_data = get_plugin_data( __FILE__ );
return $plugin_data['Version'];
}
function my_remote_plugin_version() {
$str = file_get_contents('https://rocketapps.com.au/files/open-graphite-pro/open-graphite-pro/info.json');
$json = json_decode($str, true);
return $json['version'];
}