Skip to content

Instantly share code, notes, and snippets.

@wpmu-authors
wpmu-authors / dependency.php
Created February 5, 2021 13:32
dependency.php
if( !function_exists( 'the_field' ) ) {
add_action( 'admin_notices', 'my_acf_notice' );
}
function my_acf_notice() {
?>
<div class="update-nag notice">
<p><?php _e( 'Please install Advanced Custom Fields, it is required for this plugin to work properly!', 'my_plugin_textdomain' ); ?></p>
</div>
<?php
@wpmu-authors
wpmu-authors / acf-notice.php
Created February 5, 2021 13:35
acf-notice.php
if( !function_exists( 'the_field' ) && empty( get_option( 'my-acf-notice-dismissed' ) ) ) {
add_action( 'admin_notices', 'my_acf_admin_notice' );
}
function my_acf_admin_notice() {
?>
<div class="notice error my-acf-notice is-dismissible" >
<p><?php _e( 'ACF is not necessary for this plugin, but it will make your experience better, install it now!', 'my-text-domain' ); ?></p>
</div>
@wpmu-authors
wpmu-authors / enqueue.php
Created February 5, 2021 13:37
enqueue.php
add_action( 'wp_enqueue_scripts', 'my_plugin_assets' );
function my_plugin_assets() {
wp_enqueue_script( 'my-notice-update', plugins_url( '/js/notice-update.js', __FILE__ ), array( 'jquery' ), '1.0', true );
}
@wpmu-authors
wpmu-authors / dismiss.js
Created February 5, 2021 13:38
dismiss.js
jQuery(document).on( 'click', '.my-acf-notice .notice-dismiss', function() {
jQuery.ajax({
url: ajaxurl,
data: {
action: 'my_dismiss_acf_notice'
}
})
})
@wpmu-authors
wpmu-authors / remove-option.php
Created February 5, 2021 14:06
remove-option.php
add_action( 'admin_init', 'my_detect_acf' );
function my_detect_acf() {
if( !function_exists( 'the_field' )) {
delete_option( 'my-acf-notice-dismissed' );
}
}
@wpmu-authors
wpmu-authors / skeleton.php
Created February 8, 2021 13:26
skeleton.php
add_action( 'wp_dashboard_setup', 'register_my_dashboard_widget' );
function register_my_dashboard_widget() {
wp_add_dashboard_widget(
'my_dashboard_widget',
'My Dashboard Widget',
'my_dashboard_widget_display'
);
}
@wpmu-authors
wpmu-authors / example.php
Created February 8, 2021 13:28
example.php
function register_my_dashboard_widget() {
global $wp_meta_boxes;
wp_add_dashboard_widget(
'my_dashboard_widget',
'Publication Schedule',
'my_dashboard_widget_display'
);
$dashboard = $wp_meta_boxes['dashboard']['normal']['core'];
@wpmu-authors
wpmu-authors / html.html
Created February 8, 2021 13:30
html.html
<div class="comment-stat-bars">
<div class="comment-stat-bar"></div>
<div class="comment-stat-bar"></div>
<!-- etc... -->
</div>
<div class="comment-stat-labels">
<div class="comment-stat-label">comment count here</div>
</div>
<div class='comment-stat-caption'>Comments in the past 5 weeks</div>
@wpmu-authors
wpmu-authors / enqueue.php
Created February 8, 2021 13:33
enqueue.php
add_action( 'admin_enqueue_scripts', 'dashboard_widget_display_enqueues' );
function dashboard_widget_display_enqueues( $hook ) {
if( 'index.php' != $hook ) {
return;
}
wp_enqueue_style( 'dashboard-widget-styles', plugins_url( '', __FILE__ ) . '/widgets.css' );
}
@wpmu-authors
wpmu-authors / style.css
Created February 8, 2021 13:55
style.css
.comment-stat-bars {
overflow:hidden
}
.comment-stat-bar {
margin:0 1%;
background-color: #2ea2cc;
border-top-color: #fff;
border-top-style: solid;
float:left;