Skip to content

Instantly share code, notes, and snippets.

View someguy9's full-sized avatar
🏠
Working from home

Andy Feliciotti someguy9

🏠
Working from home
View GitHub Profile
// Function to check if an email is disposable using multiple API services
async function isDisposableEmail(email, ip = null) {
try {
// Construct API URLs with email and optionally IP for StopForumSpam
const debounceUrl = `https://disposable.debounce.io/?email=${email}`;
const verifyMailUrl = `https://verifymail.io/api/${email.split('@')[1]}?key=${process.env.VERIFYMAIL_API_KEY}`;
const stopForumSpamUrl = `https://api.stopforumspam.org/api?email=${email}&json=true${ip ? `&ip=${ip}` : ""}`;
// Make parallel requests to the APIs
const [debounceResponse, verifyMailResponse, stopForumSpamResponse] = await Promise.all([
@someguy9
someguy9 / meta-cheerio.js
Created September 28, 2024 21:42
Getting meta title, description, and og:image using cheerio and Node.js
import * as cheerio from 'cheerio'
export async function getMetadata(url) {
// Ensure the URL starts with http:// or https://
if (!url.startsWith('http://') && !url.startsWith('https://')) {
url = `https://${url}`;
}
try {
// Fetch the HTML content of the URL
@someguy9
someguy9 / limit-comment-length-by-post-id.php
Created July 29, 2024 15:16
Limit comment length in WordPress by post ID
<?php
// Limit the comment length to 6000 characters and a minimum of 50 characters in WordPress for a specific post
add_filter('preprocess_comment', 'smartwp_limit_comment_length');
function smartwp_limit_comment_length($comment) {
// Specify the post ID where you want this function to run
$specific_post_id = 123; // Replace 123 with your desired post ID
// Check if the current post is the specific post we want to target
if (get_the_ID() == $specific_post_id) {
@someguy9
someguy9 / front-end-is-plugin-active.php
Last active July 4, 2024 14:27
See if WordPress plugin is active on the front end
<?php
// Checking if a WordPress plugin is active on the front end
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'plugin-directory/main-plugin-file.php' ) ) {
// plugin is active
}
@someguy9
someguy9 / admin-area-is-plugin-active.php
Last active July 4, 2024 14:27
Is WordPress plugin active for admin
<?php
// Checking if a WordPress plugin is active in the admin dashboard
if ( is_plugin_active( 'plugin-directory/main-plugin-file.php' ) ) {
// plugin is active
}
@someguy9
someguy9 / wordpress-active.php
Last active July 4, 2024 14:28
Check if WordPress plugin is active
<?php
// Checking if a WordPress plugin (works for admin or front end)
if ( in_array( 'plugin-directory/main-plugin-file.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Plugin is active
}
@someguy9
someguy9 / limit-comment-length.php
Created April 18, 2024 14:09
Limit comment length in WordPress
<?php
// Limit the comment length to 6000 characters and a minimum of 50 characters in WordPress
add_filter( 'preprocess_comment', 'smartwp_limit_comment_length' );
function smartwp_limit_comment_length( $comment ) {
// Limit the comments to 6000 characters
if ( strlen( $comment['comment_content'] ) > 6000 ) {
wp_die('Comment is too long. Comments must be under 6000 characters.');
}
@someguy9
someguy9 / style.css
Created November 19, 2023 20:42
Child theme style.css example in WordPress https://smartwp.com/child-theme/
/*
Theme Name: Twenty Fifteen Child
Description: Twenty Fifteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfifteen
Version: 1.0.0
Text Domain: twentyfifteenchild
*/
<?php
global $product;
echo 'The current product ID is: '.$product->get_id();
php_value memory_limit 256M