diff --git a/assets/css/pw.css b/assets/css/pw.css index e4083f6..f2b2f11 100644 --- a/assets/css/pw.css +++ b/assets/css/pw.css @@ -1,6 +1,15 @@ #wpadminbar .quicklinks #wp-admin-bar-pw-my-account .ab-icon{ margin:0px; } +#wpadminbar .quicklinks #wp-admin-bar-pw-environment-type:hover>.ab-item{ + background:transparent; + color:white; + cursor:help; +} +#wpadminbar .quicklinks li#wp-admin-bar-pw-environment-type .ab-icon:before{ + color:rgba(240,246,252,.6) !important; +} +#wpadminbar .quicklinks #wp-admin-bar-pw-environment-type div.ab-item, #wpadminbar .quicklinks #wp-admin-bar-pw-my-account div.ab-item{ display:flex; flex-direction:row; @@ -10,6 +19,7 @@ #wpadminbar .quicklinks .menupop ul li .ab-item{ min-width:100px !important; } +#wpadminbar #wp-admin-bar-pw-environment-type .ab-icon, #wpadminbar .ab-icon.pw-logo{ margin:0px !important; } @@ -21,7 +31,7 @@ .pw-logo:before{ content:""; display:block; - background-image:url('data:image/svg+xml,'); + background-image:url('data:image/svg+xml,'); background-size:20px 20px; height:20px; width:20px; diff --git a/inc/disable/post-revisions.php b/inc/disable/post-revisions.php index 8b67022..1c81bd9 100644 --- a/inc/disable/post-revisions.php +++ b/inc/disable/post-revisions.php @@ -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 '
- -

'.__("Revisions are disabled by default for all post types.", "perpetual-wp").'

-
'; - } + 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' ); + } + }); } diff --git a/inc/improve/environment.php b/inc/improve/environment.php index fb5d14c..5fb7369 100644 --- a/inc/improve/environment.php +++ b/inc/improve/environment.php @@ -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; @@ -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()).' ', '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 ''; + } + } +} + +add_action("admin_footer", "pw_staging_adminbar_bg_color"); +add_action("wp_footer", "pw_staging_adminbar_bg_color"); diff --git a/inc/improve/heartbeat.php b/inc/improve/heartbeat.php new file mode 100644 index 0000000..7bffa02 --- /dev/null +++ b/inc/improve/heartbeat.php @@ -0,0 +1,29 @@ + 503, + "exit" => true + ] + ); + }else{ + $seconds = 60; + } + } + + $settings['interval'] = $seconds; + + return $settings; +}, PHP_INT_MAX); diff --git a/inc/improve/index.php b/inc/improve/index.php new file mode 100644 index 0000000..8b6139d --- /dev/null +++ b/inc/improve/index.php @@ -0,0 +1,3 @@ +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. @@ -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 ''; -}, PHP_INT_MAX); - add_action( 'admin_bar_menu', function(\WP_Admin_Bar $admin_bar){ - $admin_bar->add_node([ - 'id' => 'pw-logo', - 'title' => '', - '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(); @@ -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; @@ -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 ''; + }, 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; }); \ No newline at end of file + add_action( 'admin_bar_menu', function(\WP_Admin_Bar $admin_bar){ + $admin_bar->add_node([ + 'id' => 'pw-logo', + 'title' => '', + 'href' => PW_HOMEPAGE, + 'meta' => array( + 'target' => '_blank', + 'rel' => 'nofollow', + 'title' => __( 'About Perpetual WP', 'perpetual-wp' ), + ) + ]); + }, PHP_INT_MIN); +} diff --git a/inc/languages.php b/inc/languages.php new file mode 100644 index 0000000..0e96a92 --- /dev/null +++ b/inc/languages.php @@ -0,0 +1,9 @@ +