Skip to content

Instantly share code, notes, and snippets.

<?php
// URL of the sitemap
$sitemapUrl = "https://www.example.com/sitemap.xml";
// Load the sitemap XML into a SimpleXML object
$sitemapXml = simplexml_load_file($sitemapUrl);
// Iterate over each URL in the sitemap
foreach ($sitemapXml->url as $url) {
@JRMorris77
JRMorris77 / json-encode-mysql.php
Created August 22, 2018 08:29
JSON encode a MySQL result using PHP
<?php
$dbhost = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "dbname";
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
@JRMorris77
JRMorris77 / hbapicheck.php
Created June 23, 2018 08:04
Hummingbird API Quick Diagnostics
<?php
/**
* Script Name: Hummingbird API Quick Diagnostics
* Script URI: https://premium.wpmudev.org/
* Description: Misc diagnostic tools used by WPMU DEV SLS Tech Support
* Author: James Morris @ WPMU DEV
* Version: 0.1
* Author URI: https://premium.wpmudev.org/
*
*/
@JRMorris77
JRMorris77 / tos-pp-bp-registration.php
Created April 4, 2018 03:34
Add TOS/PP checkbox To BuddyPress Registration
<?php
/*
Plugin Name: Add TOS/PP checkbox To BuddyPress Registration
Plugin URI: https://premium.wpmudev.org/
Description: Inserts text links and checkbox to BuddyPress regtration form to confirm acceptance of terms and privacy policy prior to registration. Submit button is disabled if check box is not selected. To install on your site, upload to wp-content/mu-plugins/
Author: James Morris @ WPMUDEV
Author URI: https://premium.wpmudev.org/
License: GPLv2 or later
*/
add_action('bp_before_registration_submit_buttons', 'bph_show_privacy_link');
@JRMorris77
JRMorris77 / getcleanfeed.php
Created March 15, 2018 10:14
Remove invalid line breaks and returns from invalid source XML feed
<?php
/*
Script Name: getcleanfeed
Plugin URI: https://premium.wpmudev.org/
Description: Removes invalid line breaks and returns from source feed
Author: James Morris @ WPMUDEV
Author URI: https://premium.wpmudev.org/
License: GPLv2 or later
*/
$ch = curl_init();
@JRMorris77
JRMorris77 / force_mp_variation_modal_full_width.php
Last active January 9, 2018 03:59
Force MarketPress Variation Modal 100% Width
<?php
/* The following code forces the WPMU DEV MarketPress plugin variation
* modal (popup) to use 100% of the active window width. This works for
* both desktop and mobile. The code also applies custom CSS that makes
* the product image take 100% width of the parent container. The code
* applies to both the Store homepage and Products page. This should be
* added to the active theme's functions.php AFTER MarketPress has been
* installed and activated.
*/
add_action( 'wp_footer', function(){
@JRMorris77
JRMorris77 / realIP.php
Created December 20, 2017 07:59
Get True Outgoing IP Address of a Web Server
/*
There are times when you need to find out of the IP address your domain maps to in DNS is the same
as the IP address of your web server's outgoing interface. This is particularly useful when dealing
with APIs such as eNOM. The following just performs a simple query agains http://ipecho.net/plain to
optain your server's outgoing IP. This can be modified with any number of similar services.
*/
$realIP = file_get_contents("http://ipecho.net/plain");
echo $realIP;
@JRMorris77
JRMorris77 / wpmudev-debug-tools.php
Last active January 3, 2018 06:44 — forked from wpmudev-sls/wpmudev-debug-tools.php
[WordPress - General] Show additional server information. Useful for debugging website.
<?php
/*
Plugin Name: WPMU DEV Tools
Plugin URI: https://premium.wpmudev.org/
Version: 0.5.2
Description: Shows diagnostic information about the current server environment as well as tests cURL connectivity to <a href="https://premium.wpmudev.org" target="_blank">premium.wpmudev.org</a> and displays the debug.log. <br /><strong>Notice</strong>: This plugin utilizes <a href="http://php.net/manual/en/function.shell-exec.php" target="_blank">shell_exec()</a>. This must be enabled in PHP for full functionality.
Author: WPMU DEV
Author URI: https://premium.wpmudev.org/
License: GPLv2 or later
*/
@JRMorris77
JRMorris77 / remove-admin-notices.php
Created November 22, 2017 06:24
Remove Notices from WordPress Admin Pages
<?php
// Removes Notices from WordPress Admin pages.
function remove_admin_notices() {
remove_all_actions( 'admin_notices' );
echo "<style>.wp-admin .notice {display:none !important;}</style>";
}
add_action( 'admin_head', 'remove_admin_notices' );
@JRMorris77
JRMorris77 / before-after-content.php
Created November 18, 2017 08:41
Add HTML or Shortcode before or after the_content() - WordPress mu-plugin
<?php
// This particular example adds Hustle Social Sharing shortcode after content without editing template files on single posts/pages only.
function jmorris_before_after($content) {
$beforecontent = '';
if ( is_single() ) {
$aftercontent = '[wd_hustle_ss id="jmorris-online"]';
} else {
$aftercontent = '';
}
$fullcontent = $beforecontent . $content . $aftercontent;