How To Get Email Alerts For 404 Pages In WordPress
Using the following lines of codes, you will be able to get an email alerts for 404 pages in your WordPress website.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<?php // WP 404 ALERTS @ http://wp-mix.com/wordpress-404-email-alerts/ // set status header("HTTP/1.1 404 Not Found"); header("Status: 404 Not Found"); // site info $blog = get_bloginfo('name'); $site = get_bloginfo('url') . '/'; $email = get_bloginfo('admin_email'); // theme info if (!empty($_COOKIE["nkthemeswitch" . COOKIEHASH])) { $theme = clean($_COOKIE["nkthemeswitch" . COOKIEHASH]); } else { $theme_data = wp_get_theme(); $theme = clean($theme_data->Name); } // referrer if (isset($_SERVER['HTTP_REFERER'])) { $referer = clean($_SERVER['HTTP_REFERER']); } else { $referer = "undefined"; } // request URI if (isset($_SERVER['REQUEST_URI']) && isset($_SERVER["HTTP_HOST"])) { $request = clean('http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]); } else { $request = "undefined"; } // query string if (isset($_SERVER['QUERY_STRING'])) { $string = clean($_SERVER['QUERY_STRING']); } else { $string = "undefined"; } // IP address if (isset($_SERVER['REMOTE_ADDR'])) { $address = clean($_SERVER['REMOTE_ADDR']); } else { $address = "undefined"; } // user agent if (isset($_SERVER['HTTP_USER_AGENT'])) { $agent = clean($_SERVER['HTTP_USER_AGENT']); } else { $agent = "undefined"; } // identity if (isset($_SERVER['REMOTE_IDENT'])) { $remote = clean($_SERVER['REMOTE_IDENT']); } else { $remote = "undefined"; } // log time $time = clean(date("F jS Y, h:ia", time())); // sanitize function clean($string) { $string = rtrim($string); $string = ltrim($string); $string = htmlentities($string, ENT_QUOTES); $string = str_replace("\n", "<br>", $string); if (get_magic_quotes_gpc()) { $string = stripslashes($string); } return $string; } $message = "TIME: " . $time . "\n" . "*404: " . $request . "\n" . "SITE: " . $site . "\n" . "THEME: " . $theme . "\n" . "REFERRER: " . $referer . "\n" . "QUERY STRING: " . $string . "\n" . "REMOTE ADDRESS: " . $address . "\n" . "REMOTE IDENTITY: " . $remote . "\n" . "USER AGENT: " . $agent . "\n\n\n"; mail($email, "404 Alert: " . $blog . " [" . $theme . "]", $message, "From: $email"); ?> |
Snippet Source/Credit: WP Mix
How To Modify Size Of Embedded Videos In WordPress
Simply paste the following snippet on your functions.php file and you will be able to modify the size of embedded videos as per your requirements.
1 2 3 4 5 6 |
function mycustom_embed_defaults($embed_size){ $embed_size['width'] = 586; // Adjust values to your needs $embed_size['height'] = 500; return $embed_size; } add_filter('embed_defaults', 'mycustom_embed_defaults'); |
Snippet Source/Credit: Shailan
Sharing Databases Between Two Domains In WordPress
The following snippet will let you share databases between two domains in WordPress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
define('CUSTOM_CAPABILITIES_PREFIX', 'wp_'); define('CUSTOM_USER_TABLE', 'wp_users'); define('CUSTOM_USER_META_TABLE', 'wp_usermeta'); In wp-includes/capabilities.php: /** * Set up capability object properties. * * Will set the value for the 'cap_key' property to current database table * prefix, followed by 'capabilities'. Will then check to see if the * property matching the 'cap_key' exists and is an array. If so, it will be * used. * * @since 2.1.0 * * @param string $cap_key Optional capability key * @access protected */ function _init_caps( $cap_key = '' ) { global $wpdb; if ( empty($cap_key) ) if (defined ('CUSTOM_CAPABILITIES_PREFIX')) { $this->cap_key = CUSTOM_CAPABILITIES_PREFIX . 'capabilities'; } else { $this->cap_key = $wpdb->prefix . 'capabilities'; } else $this->cap_key = $cap_key; $this->caps = &$this->{$this->cap_key}; if ( ! is_array( $this->caps ) ) $this->caps = array(); $this->get_role_caps(); } |
In the active theme’s functions.php:
1 2 3 4 5 6 7 |
function table_prefix_switch() { global $wpdb; $options = $wpdb->options; //Save the site 2 options table $wpdb->set_prefix('wp_'); //The prefix to site 1 $wpdb->options = $options; //Put the options table back } add_action('init', 'table_prefix_switch'); |
Snippet Source/Credit: WordPress.org
How To Test Whether A Plugin Is Active Or Not In WordPress
The following snippet will let you test that whether a plugin is active or not in WordPress.
1 2 3 4 5 |
<?php if (is_plugin_active('plugin-directory/plugin-file.php')) { // the plugin is active } ?> |
Snippet Credit/Source: CatsWhoCode