Browse Source

Add files via upload

main 1.4.2
Nathan DeGruchy 9 months ago committed by GitHub
parent
commit
496f8789c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG
  2. 2
      README.md
  3. 262
      degruchy-core.php
  4. 2
      readme.txt

3
CHANGELOG

@ -1,3 +1,6 @@
1.4.1:
- Remove application passwords
1.3.11:
- In hindsight, probably just better to run WP toolbelt

2
README.md

@ -14,6 +14,8 @@ I wouldn't recommend implementing this on your site unless you make substantial
* Enables uploads of SVG and webp/a/m files
* Re-enables the Link/blogroll system and adds a shortcode for displaying them
* Turns off Login error strings that would be displayed after a bad login attempt
* Turns off Application passwords
* Turns off XMLRPC
## License

262
degruchy-core.php

@ -12,7 +12,7 @@
* Plugin Name: DeGruchy Core Plugin
* Plugin URI: https://github.com/ndegruchy/degruchy-core
* Description: Core functionality plugin for WordPress on DeGruchy.org.
* Version: 1.4.0
* Version: 1.4.2
* Requires at least: 5.2
* Requires PHP: 7.2
* Author: Nathan DeGruchy
@ -23,48 +23,14 @@
* GitHub Plugin URI: ndegruchy/degruchy-core
*/
const CACHELIFETIME = 3600;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) )
{
exit;
}
const CACHELIFETIME = 3600;
/**
* Disable plugin/theme editor
*/
if ( ! defined( 'DISALLOW_FILE_EDIT' ) )
{
define( 'DISALLOW_FILE_EDIT', TRUE );
}
/**
* degruchy_custom_fields_metabox
*
* Remove Ancient Custom Fields metabox from post editor
* because it uses a very slow query meta_key sort query
* so on sites with large postmeta tables it is super slow
* and is rarely useful anymore on any site
*
* @return TRUE This always happens
*/
function degruchy_custom_fields_metabox(): bool
{
foreach ( get_post_types() as $post_type )
{
remove_meta_box( 'postcustom', $post_type, 'normal' );
}
return TRUE;
}
/*
* Adds the removal of the metabox features function from anywhere
* where the admin menu would appear
*/
add_action( 'admin_menu', 'degruchy_custom_fields_metabox' );
/**
* Display Old Post Notification on Content
*
@ -72,77 +38,80 @@ add_action( 'admin_menu', 'degruchy_custom_fields_metabox' );
*
* @return string The maybe modified content
*/
function degruchy_maybe_add_banner( string $content ): string
if( ! function_exists( 'degruchy_core_maybe_add_banner' ) )
{
if ( ! is_singular( 'post' ) ||
in_category( 'garrett-quotes' ) )
function degruchy_core_maybe_add_banner( string $content ): string
{
// Skip if we're a singe post type, or in the category 'garrett-quotes'
return $content;
}
if ( ! is_singular( 'post' ) ||
in_category( 'garrett-quotes' ) )
{
// Skip if we're not a singe post type, or in the category 'garrett-quotes'
return $content;
}
$postd = get_the_date( 'U' );
$today = date( 'U' );
$oneyr = 60 * 60 * 24 * 365;
$postd = get_the_date( 'U' );
$today = date( 'U' );
$oneyr = 60 * 60 * 24 * 365;
if ( ( ( $today - $postd ) >= $oneyr ) )
{ // If we're a year or more old
if ( ( ( $today - $postd ) >= $oneyr ) )
{ // If we're a year or more old
$_banner_cache = wp_cache_get(
'degruchy-core-old-banner',
'degruchy-core'
); // Retrieve cache of the banner to avoid doing it repeatedly
$_banner_cache = wp_cache_get(
'degruchy-core-old-banner',
'degruchy-core'
); // Retrieve cache of the banner to avoid doing it repeatedly
if ( FALSE == $_banner_cache )
{
// If the banner cache is empty, generate it
// Some guard rails in case some part is missing
if ( file_exists( __DIR__ . '/vendor/parsedown/Parsedown.php' ) &&
file_exists( __DIR__ . '/templates/banner.md') )
if ( FALSE == $_banner_cache )
{
// Add parsedown.
require_once __DIR__ . '/vendor/parsedown/Parsedown.php';
$Parsedown = new Parsedown;
// Set some options
$Parsedown->setSafeMode( TRUE );
// Load the banner message file
$banner_file = __DIR__ . '/templates/banner.md';
$banner = file_get_contents( $banner_file );
$banner = $Parsedown->text( $banner );
$banner = "<section id=\"old\">$banner</section>";
// Cache the result for an hour
wp_cache_set(
'degruchy-core-old-banner',
$banner,
'degruchy-core',
CACHELIFETIME
);
// If the banner cache is empty, generate it
// Some guard rails in case some part is missing
if ( file_exists( __DIR__ . '/vendor/parsedown/Parsedown.php' ) &&
file_exists( __DIR__ . '/templates/banner.md') )
{
// Add parsedown.
require_once __DIR__ . '/vendor/parsedown/Parsedown.php';
$Parsedown = new Parsedown;
// Set some options
$Parsedown->setSafeMode( TRUE );
// Load the banner message file
$banner_file = __DIR__ . '/templates/banner.md';
$banner = file_get_contents( $banner_file );
$banner = $Parsedown->text( $banner );
$banner = "<section id=\"old\">$banner</section>";
// Cache the result for an hour
wp_cache_set(
'degruchy-core-old-banner',
$banner,
'degruchy-core',
CACHELIFETIME
);
}
else
{
return $content; //abort, something is missing
}
}
else
{
return $content; //abort, something is missing
// Cache is warm, use that.
$banner = $_banner_cache;
}
}
else
{
// Cache is warm, use that.
$banner = $_banner_cache;
}
$content = $banner . $content;
// Show the banner
$content = $banner . $content;
// Show the banner
}
return $content;
}
return $content;
}
}
// Add banner to the content, maybe.
add_filter( 'the_content', 'degruchy_maybe_add_banner', 99 );
add_filter( 'the_content', 'degruchy_core_maybe_add_banner', 99 );
/**
* degruchy_mime_types
@ -151,50 +120,99 @@ add_filter( 'the_content', 'degruchy_maybe_add_banner', 99 );
*
* @return array An appended list of safe mimetypes for uploads
*/
function degruchy_mime_types( array $mimes ): array
if ( ! function_exists( 'degruchy_core_mime_types' ) )
{
$mimes[ 'svg' ] = 'image/svg';
$mimes[ 'webp' ] = 'image/webp';
$mimes[ 'webm' ] = 'video/webm';
$mimes[ 'weba' ] = 'audio/weba';
function degruchy_core_mime_types( array $mimes ): array
{
$mimes[ 'svg' ] = 'image/svg';
$mimes[ 'webp' ] = 'image/webp';
$mimes[ 'webm' ] = 'video/webm';
$mimes[ 'weba' ] = 'audio/weba';
return $mimes;
return $mimes;
}
}
// Hook onto the upload_mimes function and allow my custom mimetypes
add_filter( 'upload_mimes', 'degruchy_mime_types', 1, 99 );
add_filter( 'upload_mimes', 'degruchy_core_mime_types', 1, 99 );
// Add the Link Manager option back into the system
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
/**
* Blogroll Shortcode
* Disable features
*
* @return string A formatted blogroll, suitable for a shortcode
* - XMLRPC
* - Login error messages
* - Application passwords
* - XML Sitemaps
* - Metaboxes
* - Theme/plugin editor
*/
function degruchy_core_sc_blogroll(): string
{
$blogroll = wp_list_bookmarks(
array(
'orderby' => 'name',
'echo' => FALSE,
'title_li' => '',
'title_before' => '',
'title_after' => '',
'show_images' => '',
'categorize' => 0,
)
);
return "<ul>$blogroll</ul>";
}
// Add shortcode for inserting the blogroll
add_shortcode( 'blogroll', 'degruchy_core_sc_blogroll' );
// Add the blogroll option back into the system
add_filter( 'pre_option_link_manager_enabled', '__return_true' );
// Disable XMLRPC
/**
* Disable XML-RPC
*
* A feature I don't use, nor need.
*/
add_filter( 'xmlrpc_enabled', '__return_false' );
/**
* Remove error messages from login window
*/
add_filter( 'login_errors', '__return_false' );
/**
* Remove Application Password functionality
*
* I don't really need these, since I don't utilize my site as anything other than a site
*
* @since 1.4.1
*/
add_filter('wp_is_application_passwords_available', '__return_false');
/**
* Remove XML Sitemaps
*
* I don't care about SEO or whatever
*
* @since 1.4.1
*/
add_filter( 'wp_sitemaps_enabled', '__return_false' );
/**
* Disable plugin/theme editor
*/
if ( ! defined( 'DISALLOW_FILE_EDIT' ) )
{
define( 'DISALLOW_FILE_EDIT', TRUE );
}
/**
* degruchy_custom_fields_metabox
*
* Remove Ancient Custom Fields metabox from post editor
* because it uses a very slow query meta_key sort query
* so on sites with large postmeta tables it is super slow
* and is rarely useful anymore on any site
*
* @return TRUE This always happens
*/
if ( ! function_exists( 'degruchy_core_custom_fields_metabox' ) )
{
function degruchy_core_custom_fields_metabox(): bool
{
foreach ( get_post_types() as $post_type )
{
remove_meta_box( 'postcustom', $post_type, 'normal' );
}
return TRUE;
}
}
/*
* Adds the removal of the metabox features function from anywhere
* where the admin menu would appear
*/
add_action( 'admin_menu', 'degruchy_core_custom_fields_metabox' );

2
readme.txt

@ -6,7 +6,7 @@ Requires at least: 5.4.2
Tested up to: 5.8.0
Requires PHP: 7.3.0
Stable tag: trunk
Version: 1.4.0
Version: 1.4.2
License: GPL v3+
License URI: https://www.gnu.org/licenses/gpl-3.0.en.html

Loading…
Cancel
Save