Skip to content

Instantly share code, notes, and snippets.

@davidfcarr
davidfcarr / dashboard-similarweb.php
Created July 18, 2023 14:14
WordPress Plugin for Similarweb Data Lookups
View dashboard-similarweb.php
<?php
/*
Plugin Name: Dashboard Screen for Similarweb
*/
// see https://developer.wordpress.org/reference/
add_action('admin_menu','menu_for_similarweb');
function menu_for_similarweb() {
//anyone who can create blog posts can access this screen
View sqlfix.php
//adds intval sanitization
if(!empty($_POST['resend']))
{
echo '<div class="notice"><p>Resending email requesting confirmation</p></div>';
$mail['from'] = get_option('admin_email');
$mail['fromname'] = get_option('blogname');
$mail['subject'] = 'Please confirm your subscription to the email list for '.$mail['fromname'];
foreach($_POST['resend'] as $id) {
$sql = "select email from $table where id = ".intval($id);
$mail['to'] = $wpdb->get_var($sql);
View json_to_block.php
<?php
function rsvpBlockDataOutput($block, $post_id) {
if(empty($block))
return;
$attrs = ($block->attrs) ? json_encode($block->attrs) : '';
if(!empty($block->innerHTML) || (!empty($block->innerBlocks) && sizeof($block->innerBlocks)) ) {
$output = sprintf('<!-- wp:%s %s -->',$block->blockName,$attrs)."\n";
if(!empty($block->innerHTML))
$output .= $block->innerHTML."\n";
if(!empty($block->innerBlocks) && is_array($block->innerBlocks) && sizeof($block->innerBlocks)) {
View functions.php
<?php
function my_edit_site_menu($wp_admin_bar) {
$args = array(
'parent' => 'site-editor',
'id' => 'theme-header',
'title' => __('Header / Menu','twentytwentytwo-tm'),
'href' => admin_url('site-editor.php?postType=wp_template_part&postId=twentytwentytwo-tm%2F%2Fheader'),
'meta' => array( 'class' => 'twentytwentytwo-tm')
);
View rsvpmaker-block-theme-template
<?php
/*
* Adds variation on a block theme's single template for custom post type
* called on plugin activation or after_theme_switch action
*/
register_activation_hook( __FILE__, 'rsvpmaker_single_block_template' );
add_action('after_switch_theme','rsvpmaker_single_block_template');
function rsvpmaker_single_block_template() {
View Toastmaster Meeting 2021 Model Agenda
<!-- wp:wp4toastmasters/agendaedit {"editable":"Welcome and Introductions","uid":"editable16181528933590.29714489144034184","time_allowed":"5","inline":true} /-->
<!-- wp:wp4toastmasters/role {"role":"Toastmaster of the Day","agenda_note":"Introduces supporting roles. Leads the meeting.","time_allowed":"4","padding_time":"5"} /-->
<!-- wp:wp4toastmasters/role {"role":"Ah Counter"} /-->
<!-- wp:wp4toastmasters/role {"role":"Timer"} /-->
<!-- wp:wp4toastmasters/role {"role":"Vote Counter"} /-->
View mailpoet-multisite.php
<?php
/*
Plugin Name: Multisite Hacks for MailPoet
Version: 1.1
Description: Example but DOES NOT SEEM TO WORK WITH THE LATEST MAILPOET VERSION. My recommended alternative to MailPoet https://rsvpmaker.com/blog/2022/08/27/rsvpmaker-postmark-free-email-marketing/
*/
function mailpoet_site_subscribers () {
if(!strpos($_SERVER['REQUEST_URI'],'mailpoet'))
return;
View rsvpmaker-mailpoet.php
<?php
add_filter('mailpoet_newsletter_shortcode', 'mailpoet_rsvpmaker_shortcode', 10, 5);
function mailpoet_rsvpmaker_shortcode($shortcode, $newsletter, $subscriber, $queue, $newsletter_body) {
// always return the shortcode if it doesn't match your own!
if (!strpos($shortcode,'rsvpmaker') && !strpos($shortcode,'event_listing') ) return $shortcode;
global $email_context;
$email_context = true;
$shortcode = str_replace('custom:','',$shortcode);
View wordpress-wizard-password-widget.php
<?php
/*
Sample code for including the WordPress password reset function, including password strength meter, on a custom admin page
*/
/*include the javascript from the user profile page on your own custom admin page*/
add_action( 'wp_enqueue_scripts', 'password_strength_scripts' );
function password_strength_scripts() {
if( isset($_REQUEST["page"]) && ($_REQUEST["page"] == 'my_admin_wizard')) {
wp_enqueue_script('password-strength-meter');
View Timezone Conversion Demo
<!DOCTYPE html>
<html lang="en-US" class="no-js no-svg">
<head>
<meta charset="UTF-8">
<title>Timezone Conversion Demo</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<body>
<h3 class="dateblock"><span class="event-date">Saturday December 5, 2020</span> <span class="event_time">8:15 AM</span> EST</span></h3>
<div id="timezone_converted"></div>