Skip to content

Instantly share code, notes, and snippets.

View DuckDivers's full-sized avatar

Howard DuckDivers

  • Duck Diver Marketing
  • Florida
View GitHub Profile
@DuckDivers
DuckDivers / ajax.js
Created July 15, 2022 14:58
WP-Ajax Loadmore Posts
jQuery(function($){
let canBeLoaded = true,
bottomOffset = 2000;
$(window).on( 'scroll', function(){
let data = {
'action': 'loadmore',
'query': ajaxposts.posts,
'page' : ajaxposts.current_page
};
@DuckDivers
DuckDivers / cf7-custom-select-states.php
Last active November 25, 2021 19:55
A custom form tag for contact form 7 with option to read current user profile to get state.
<?php
add_action(
'wpcf7_init',
function () {
wpcf7_add_form_tag( array( 'dd_states', 'dd_states*' ), 'cf7_state_dropdown', true );
}
);
/**
* Custom Select Form Tag Callback for Contact Form 7.
*
@DuckDivers
DuckDivers / acf-canadian-provinces-select.txt
Created September 16, 2021 21:19
List of Canadian Provinces for Advanced Custom Fields WordPress (ACF)
AB : Alberta
BC : British Columbia
MB : Manitoba
NB : New Brunswick
NL : Newfoundland and Labrador
NT : Northwest Territories
NS : Nova Scotia
NU : Nunavut
ON : Ontario
PE : Prince Edward Island
<?php
function dd_modal_link( $atts ) {
$atts = shortcode_atts( array(
'text' => '',
'target' => '',
'class' => '',
), $atts, 'dd_modal_link' );
$output = '<a href="#' . $atts[ 'target' ] . '"';
if ( $atts[ 'class' ] ) {
@DuckDivers
DuckDivers / class-wc-endpoints.php
Created March 18, 2021 11:21
Adding WC Endpoints OOP
<?php
class Adv_Reg_WC_Endpoint {
/**
* Custom endpoint name.
*
* @var string
*/
public static $registrations = 'registered-products';
@DuckDivers
DuckDivers / us_states_function.php
Last active December 7, 2020 16:27
US States Dropdown with WordPress selected Function
<?php
function get_us_state_options($selected = '') {
?>
<select name="state" id="state">
<option value="" >Select a State</option>
<option value="AL"<?php selected($selected, 'AL') ?>>Alabama</option>
<option value="AK"<?php selected($selected, 'AK');?>>Alaska</option>
<option value="AZ"<?php selected($selected, 'AZ');?>>Arizona</option>
<option value="AR"<?php selected($selected, 'AR');?>>Arkansas</option>
<option value="CA"<?php selected($selected, 'CA');?>>California</option>
<?php
add_action('wpcf7_init', function (){
wpcf7_add_form_tag( 'country_name' , 'cf7_ip_to_country_form_tag' );
});
function cf7_ip_to_country_form_tag($tag){
// Your API Key for https://ipstack.com
$api_key = 'your_api_key';
// Get API Response
$url = 'http://api.ipstack.com/' . $_SERVER['REMOTE_ADDR'] . '?access_key=' . $api_key;
@DuckDivers
DuckDivers / Debug Contact Form 7 Output
Created September 30, 2020 13:11
Sends CF7 Output to the error log - wherever that is
<?php
// include in functions.php or in a plugin.
// Use var_export, print_r, var_dump, whatever
add_action( 'wpcf7_before_send_mail', 'he_debug_cf7_output');
function he_debug_cf7_output( $contact_form ) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
$posted_data = $submission->get_posted_data();
// Dump output to error log
@DuckDivers
DuckDivers / form-html.html
Created July 25, 2020 21:08
Simple Ajax PHP Form Submission
<form id="contact" class="form-request" method="post" name="contact_form" action="process-form.php">
<input type="text" name="name" placeholder="Your Name:">
<input type="text" name="email" placeholder="Your Email:">
<input type="text" name="phone" placeholder="Your Phone:">
<textarea name="message" placeholder="Your Message:"></textarea>
<div class="g-recaptcha mb-3" data-sitekey="site_key"></div>
<input class="btn-submit" type="submit" value="Contact Dive Patches">
</form>
<div id="response"></div>