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 / text-gradient-fill.html
Last active April 21, 2022 08:22
Text gradient fill
<h1>
<span>This is a test</span>
</h1>
<style>
h1 span {
-webkit-text-fill-color: transparent; /* Chrome Only */
@mikeott
mikeott / waypoint.js
Last active March 29, 2022 06:14
Waypoints control
<script>
// Actual waypoint script. Save into waypoint.js
/*!
Waypoints - 4.0.0
Copyright © 2011-2015 Caleb Troughton
Licensed under the MIT license.
https://github.com/imakewebthings/waypoints/blob/master/licenses.txt
*/
! function() {
jQuery('.my-button').click(function() {
if(jQuery(this).prop('checked')) {
jQuery('.my-checkbox').removeAttr('disabled');
} else {
jQuery('.my-checkbox').attr('disabled', 'disabled');
}
});
@mikeott
mikeott / close-yoast-metabox.php
Last active July 11, 2023 14:40
Force the Yoast metabox to be closed by default.
/* Close the Yoast metabox */
function shut_your_mouth_yoast() {
echo '<script>jQuery( document ).ready(function() { jQuery(".yoast.wpseo-metabox").addClass("closed"); });</script>';
}
add_action( 'admin_head', 'shut_your_mouth_yoast' );
@mikeott
mikeott / wp_is_mobile.php
Last active July 29, 2022 07:39
WordPress: If WordPress is mobile
<?php if ( wp_is_mobile() ) {
// Do something for mobile devices
} else {
// Do something for desktop
}
@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'];
}
@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 / 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 / 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 / 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 */