Skip to content

Instantly share code, notes, and snippets.

@annalinneajohansson
Last active December 29, 2015 21:19
Show Gist options
  • Save annalinneajohansson/7729586 to your computer and use it in GitHub Desktop.
Save annalinneajohansson/7729586 to your computer and use it in GitHub Desktop.
A collection of helpful notices shown in WordPress admin.
jQuery(document).ready(function($){
var status = notices.post_status,
savePostBtn = $("#save-post"),
publishPostBtn = $("#publishing-action #publish");
if( status != "publish" && status != 0 ) {
publishPostBtn.removeClass("button-primary");
savePostBtn.addClass("button-primary");
}
});
<?php
/*
Plugin Name: Hippies Notices
Plugin URI:
Description: A collection of helpful notices shown in admin. Tells the user if a post is in draft mode, if noindex is set and more.
Version: 1
Author: Hippies
Author URI: http://hippies.se/
**************************************************************************
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*************************************************************************
*/
function hip_notices_init() {
load_plugin_textdomain( 'hip-notices', false, dirname( plugin_basename( __FILE__ ) ) );
}
add_action('plugins_loaded', 'hip_notices_init');
add_action('admin_enqueue_scripts','hip_notices_scripts');
function hip_notices_scripts( $hook ) {
if( 'post.php' != $hook )
return;
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'hip-notices', plugins_url( 'hip-notices.js', __FILE__ ), array( 'jquery' ), '2013-12-01' );
global $post;
$status = ( is_object( $post ) ) ? $post->post_status : 0;
$translation_array = array(
"post_status" => $status
);
wp_localize_script( "hip-notices", "notices", $translation_array );
}
function hip_admin_notices() {
global $pagenow;
if( $pagenow == "post.php" ) {
global $post;
if( is_object( $post ) ) {
$status = $post->post_status;
if( $status != "publish" ) {
// Using WordPress deafult strings as labels
switch ( $status ) {
case 'private':
$label = __('Privately Published');
break;
case 'future':
$label = __('Scheduled');
break;
case 'pending':
$label = __('Pending Review');
break;
case 'auto-draft':
case 'draft':
$label = __('Draft');
break;
}
echo '<div class="updated"><p>';
echo __( 'Post status currently set to', 'hip-notices' ) . " <strong>$label</strong>";
echo '</p></div>';
}
}
}
}
add_action( 'admin_notices', 'hip_admin_notices', 99 );
// Add Toolbar Menus
function hip_custom_toolbar() {
$blog_public = get_option( 'blog_public' );
if( $blog_public == 0 ) {
global $wp_admin_bar;
$args = array(
'id' => 'blog_public',
'title' => '<span style="color:red">' . __( 'This site is not being indexed by Google.', 'hip-notices' ) . '</span>',
'href' => get_bloginfo('wpurl') . '/wp-admin/options-reading.php',
);
$wp_admin_bar->add_menu( $args );
}
}
add_action( 'wp_before_admin_bar_render', 'hip_custom_toolbar', 999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment