Skip to content

Commit

Permalink
v1.01
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgm committed Nov 21, 2024
1 parent 48ba166 commit 99b6003
Show file tree
Hide file tree
Showing 12 changed files with 182 additions and 128 deletions.
12 changes: 11 additions & 1 deletion assets/css/pw.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 9 additions & 30 deletions inc/disable/post-revisions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,14 @@
die;
}

if(!function_exists("pw_revisions_enabled")){
function pw_revisions_enabled(){
$post_types = apply_filters('pw_revisions_post_type', get_option("pw_revisions_enabled") ? get_post_types() : []);
if(!empty($post_types)){
foreach($post_types as $post_type){
remove_post_type_support( $post_type, 'revisions' );
}
}
return $post_types;
}
}
if(!defined("WP_POST_REVISIONS")){
// The configuration can be overridden by defining 'WP_POST_REVISIONS' in the wp-config.php file.
define("WP_POST_REVISIONS", false);

add_action('admin_init', function(){
add_settings_field(
'pw_post_revisions_label',
__('Post Revisions', 'perpetual-wp'),
'pw_revisions',
'writing'
);
});

if(!function_exists("pw_revisions")){
function pw_revisions(){
echo '<fieldset>
<label for="enable_post_revisions">
<input name="pw_enable_post_revisions" type="checkbox" id="enable_post_revisions" value="0">
'.__("Enable").'
</label>
<p class="description">'.__("Revisions are disabled by default for all post types.", "perpetual-wp").'</p>
</fieldset>';
}
add_action("admin_init", function(){
// Might be improved with more options in the future.
foreach(apply_filters('pw_revisions_post_types', get_post_types()) as $post_type){
remove_post_type_support( $post_type, 'revisions' );
}
});
}
32 changes: 23 additions & 9 deletions inc/improve/environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
define("WP_ENVIRONMENT_TYPE", "production");
}

// TO-DO: Red adminbar.

add_action('admin_bar_menu', function($admin_bar){
// Don not show in production.
if(wp_get_environment_type() == "production") return;
Expand All @@ -18,13 +16,29 @@

// Only available for admin.
$user = wp_get_current_user();
if(!in_array("admin", (array)$user->roles)) return;
if(!in_array("administrator", (array)$user->roles)) return;

$admin_bar->add_node($args = array(
'parent' => 'top-secondary',
$admin_bar->add_menu([
'id' => 'pw-environment-type',
'title' => wp_get_environment_type(),
'parent' => 'top-secondary',
'title' => esc_html(wp_get_environment_type()).' <span class="ab-icon dashicons dashicons-marker"></span>',
'href' => false,
'meta' => false
));
}, -PHP_INT_MAX);
'meta' => [
'title' => __("Your site environment is different from production.", "perpetual-wp")
]
]);
});

if(!function_exists("pw_staging_adminbar_bg_color")){
function pw_staging_adminbar_bg_color(){
if(wp_get_environment_type() == "production" || !is_admin_bar_showing() || !is_user_logged_in()) return;

$bg_color = apply_filters("pw_staging_adminbar_bg_color", "#ff5b3f");
if($bg_color && is_string($bg_color) && preg_match('/^#[a-f0-9]{6}$/i', $bg_color)){
echo '<style>#wpadminbar{background:'.$bg_color.' !important;}</style>';
}
}
}

add_action("admin_footer", "pw_staging_adminbar_bg_color");
add_action("wp_footer", "pw_staging_adminbar_bg_color");
29 changes: 29 additions & 0 deletions inc/improve/heartbeat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
if(!defined("ABSPATH")){
http_response_code(403);
die;
}

/* Limit heartbeat control. */
add_filter( 'heartbeat_settings', function(){
// Set the interval to 60 seconds (default is 15 seconds).
$seconds = apply_filters("pw_heartbeat_seconds", 60);
if(!is_numeric($seconds) || $seconds < 10){
if(is_admin()){
wp_die(
__("The heartbeat interval must be a numeric value and cannot be set to less than 10 seconds, as doing so may significantly impact your site's performance.", "perpetual-wp"),
__("Invalid heartbeat value", "perpetual-wp"),
[
"response" => 503,
"exit" => true
]
);
}else{
$seconds = 60;
}
}

$settings['interval'] = $seconds;

return $settings;
}, PHP_INT_MAX);
3 changes: 3 additions & 0 deletions inc/improve/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
http_response_code(403);
die;
15 changes: 15 additions & 0 deletions inc/improve/media.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
if(!defined("ABSPATH")){
http_response_code(403);
die;
}

// Users will no longer see the option to filter media files by upload month.
// TO-DO: Only display this option when there is at least one year available or a substantial number of files.
add_filter( 'media_library_months_with_files', function() { return array(); });

// Disables the ability to create audio playlists.
add_filter( 'media_library_show_audio_playlist', function() { return false; });

// Disables the ability to create video playlists.
add_filter( 'media_library_show_video_playlist', function() { return false; });
100 changes: 43 additions & 57 deletions inc/improve/wp-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,6 @@
return '';
});

add_action('wp_before_admin_bar_render', function(){
global $wp_admin_bar;

// Remove the WordPress logo.
$wp_admin_bar->remove_menu('wp-logo');

// Remove the search button from the "wpadminbar" element.
$wp_admin_bar->remove_node('search');

// Remove "my account".
$wp_admin_bar->remove_node('my-account');
});

add_action("admin_menu", function(){
// Ensures that the WordPress version is removed from the footer text,
// even if the 'admin_footer_text' filter is manually modified by the user.
Expand Down Expand Up @@ -105,34 +92,7 @@ function pw_admin_redirect(){
// Avoid displaying the language selection dropdown on the login screen.
add_filter("login_display_language_dropdown", "__return_false");

add_action('login_enqueue_scripts', function(){
echo '<style type="text/css">
#login h1 a {
background-image: url(\''.plugin_dir_url(PW_PLUGIN_FILE).'assets/images/icon.svg?v=a\');
background-repeat: no-repeat;
}
#login{
padding: 0px !important;
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
}
</style>';
}, PHP_INT_MAX);

add_action( 'admin_bar_menu', function(\WP_Admin_Bar $admin_bar){
$admin_bar->add_node([
'id' => 'pw-logo',
'title' => '<span class="ab-icon pw-logo"></span>',
'href' => PW_HOMEPAGE,
'meta' => array(
'target' => '_blank',
'rel' => 'nofollow',
'title' => __( 'About Perpetual WP', 'perpetual-wp' ),
)
]);

// Simplify account button.
$profile_url = false;
$current_user = wp_get_current_user();
Expand Down Expand Up @@ -180,7 +140,20 @@ function pw_admin_redirect(){
'href' => wp_logout_url(),
)
);
}, PHP_INT_MIN);

// Remove the WordPress logo.
$admin_bar->remove_menu('wp-logo');

// Remove the search button from the "wpadminbar" element.
$admin_bar->remove_node('search');

// Remove "my account".
$admin_bar->remove_node('my-account');

// Remove "Visit Site" from the "site-name" menu as it is redundant.
// TO-DO: Add title="" tag with __("Visit Site")
$admin_bar->remove_node("view-site");
}, PHP_INT_MAX);

add_action('wp_dashboard_setup', function(){
global $wp_meta_boxes;
Expand All @@ -201,20 +174,33 @@ function pw_admin_redirect(){
}
});

/* Limit heartbeat control. */
add_filter( 'heartbeat_settings', function(){
$settings['interval'] = 60;
return $settings;
});

/* Disable thumbnail previews. */
add_filter('fallback_intermediate_image_sizes', function(){
$fallbacksizes = array();
return $fallbacksizes;
});
if(defined("PW_REPLACE_WP_BRANDING") && PW_REPLACE_WP_BRANDING == true){
add_action('login_enqueue_scripts', function(){
echo '<style type="text/css">
#login h1 a {
background-image: url(\''.plugin_dir_url(PW_PLUGIN_FILE).'assets/images/icon.svg\');
background-repeat: no-repeat;
}
#login{
padding: 0px !important;
height: 100vh;
display: flex;
justify-content: center;
flex-direction: column;
}
</style>';
}, PHP_INT_MAX);

/* Speed up WordPress admin area */
add_filter( 'postmeta_form_keys', function() { return array(); });
add_filter( 'media_library_months_with_files', function() { return array(); });
add_filter( 'media_library_show_audio_playlist', function() { return false; });
add_filter( 'media_library_show_video_playlist', function() { return false; });
add_action( 'admin_bar_menu', function(\WP_Admin_Bar $admin_bar){
$admin_bar->add_node([
'id' => 'pw-logo',
'title' => '<span class="ab-icon pw-logo"></span>',
'href' => PW_HOMEPAGE,
'meta' => array(
'target' => '_blank',
'rel' => 'nofollow',
'title' => __( 'About Perpetual WP', 'perpetual-wp' ),
)
]);
}, PHP_INT_MIN);
}
9 changes: 9 additions & 0 deletions inc/languages.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
if(!defined("ABSPATH")){
http_response_code(403);
die;
}

add_action("init", function(){
load_plugin_textdomain('perpetual-wp', false, 'perpetual-wp/lang/' );
});
10 changes: 10 additions & 0 deletions inc/security/disallow-file-edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
if(!defined("ABSPATH")){
http_response_code(403);
die;
}

if(!defined('DISALLOW_FILE_EDIT')){
// Disables the built-in WordPress file editor for themes and plugins in the admin dashboard for enhanced security.
define('DISALLOW_FILE_EDIT', TRUE);
}
19 changes: 19 additions & 0 deletions inc/security/force-ssl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
if(!defined("ABSPATH")){
http_response_code(403);
die;
}

if(!defined("FORCE_SSL_ADMIN")){
// Forces SSL on the admin panel
define("FORCE_SSL_ADMIN", TRUE);

if(isset($_SERVER["HTTP_X_FORWARDED_PROTO"]) && strpos($_SERVER["HTTP_X_FORWARDED_PROTO"], "https") !== FALSE){
$_SERVER['HTTPS'] = 'on';
}
}

if(!defined("FORCE_SSL_LOGIN")){
// Forces SSL on 'wp-login.php'
define("FORCE_SSL_LOGIN", true);
}
3 changes: 3 additions & 0 deletions inc/security/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
http_response_code(403);
exit;
Loading

0 comments on commit 99b6003

Please sign in to comment.