Skip to content

Instantly share code, notes, and snippets.

@sudar
sudar / wp-increase-timeout.php
Created Feb 13, 2013
Increase the curl timeout in WordPress
View wp-increase-timeout.php
<?php
Copied from http://fatlabmusic.com/blog/2009/08/12/how-to-fix-wp-http-error-name-lookup-timed-out/
//adjustments to wp-includes/http.php timeout values to workaround slow server responses
add_filter('http_request_args', 'bal_http_request_args', 100, 1);
function bal_http_request_args($r) //called on line 237
{
$r['timeout'] = 15;
return $r;
}
View store-post-meta-gutenberg.js
const { domReady } = wp;
const { useMemo } = wp.element;
const { TextControl } = wp.components;
const { select, useSelect, useDispatch } = wp.data;
const { PluginDocumentSettingPanel } = wp.editPost;
const { registerPlugin } = wp.plugins;
const { __ } = wp.i18n;
/**
* Output the Meta panel for Report pages.
@sudar
sudar / kses.php
Created Aug 4, 2020
Sample code to demonstrate the issue with wp_kses and allowed_html for sanitizing svg's that contain attributes with numbers at the end
View kses.php
<?php
/**
* Sample code to demonstrate the issue with wp_kses and allowed_html for sanitizing svg's that contain attributes with numbers at the end.
*/
$svg = <<<SVG
<svg>
<path x1="10" y1="10"/>
</svg>
SVG;
View error_msg.php
<?php
/**
* Display an error message at the top of the post edit screen explaining that ratings is required.
*
* Doing this prevents users from getting confused when their new posts aren't published, as we
* require a valid rating custom taxonomy.
*
* @param WP_Post The current post object.
*/
function show_required_field_error_msg( $post ) {
@sudar
sudar / 1.php
Last active Jun 3, 2020
How To Properly Create Tables In WordPress Multisite Plugins. Explanation at http://sudarmuthu.com/blog/how-to-properly-create-tables-in-wordpress-multisite-plugins/
View 1.php
<?php
// Creating tables in Single site installations
function on_activate() {
create_table();
}
function create_table() {
global $wpdb;
$table_name = $wpdb->prefix . 'table_name';
@sudar
sudar / backup.sh
Created Apr 14, 2020
Bash script to backup WordPress sites. Add this to a cron job and run it every day
View backup.sh
#!/bin/bash
NOW=$(date +%Y-%m-%d-%H-%M-%S)
SQL_FILE=${NOW}_db.sql
# Backup database
/usr/local/bin/wp db export ../backups/$SQL_FILE --add-drop-table
# Compress the database file
gzip ../backups/$SQL_FILE
@sudar
sudar / apache-error-mailer.py
Last active Mar 8, 2020
Automatically send unique errors (with count) from Apache error log as email. Details at http://sudarmuthu.com/blog/automatically-send-unique-errors-with-count-from-apache-error-log-as-email/
View apache-error-mailer.py
#!/usr/bin/env python
import sys
import mandrill
MANDRILL_API_KEY = "api-key"
EMAIL_FROM = "your@email.com"
EMAIL_TO = "your@email.com"
EMAIL_SUBJECT = "Error Log"
@sudar
sudar / mspdebug
Created Jun 3, 2012
Using mspdebug to flash a firmware in ez430
View mspdebug
sudar@sudar-desktop:~/code/watch/openchronos-ng-modular$ mspdebug rf2500
MSPDebug version 0.18 - debugging tool for MSP430 MCUs
Copyright (C) 2009-2011 Daniel Beer <dlbeer@gmail.com>
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Trying to open interface 1 on 002
rf2500: warning: can't detach kernel driver: No data available
Initializing FET...
FET protocol version is 30001000
@sudar
sudar / url-encode.c
Created Aug 20, 2012
URLEncoding in C
View url-encode.c
int c;
char *hex = "0123456789abcdef";
while( (c = getchar()) != EOF ){
if( ('a' <= c && c <= 'z')
|| ('A' <= c && c <= 'Z')
|| ('0' <= c && c <= '9') ){
putchar(c);
} else {
putchar('%');
View get-multiple-posts-by-title.php
/**
* Retrieve posts ids given their title.
* Use this function if there are more than one post with the same title.
*/
function get_multiple_posts_by_title($title) {
global $wpdb;
$posts_ids = array();
$posts = $wpdb->get_results( $wpdb->prepare( “SELECT ID FROM $wpdb->posts WHERE post_title = %s AND post_type=’post_type’”, $title), OBJECT );
foreach ($posts as $post) {
You can’t perform that action at this time.