| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Ultimate Dashboard |
| 4 |
* Plugin URI: https://ultimatedashboard.io/ |
| 5 |
* Description: Create a Custom WordPress Dashboard. |
| 6 |
* Version: 2.5 |
| 7 |
* Author: David Vongries |
| 8 |
* Author URI: https://mapsteps.com/ |
| 9 |
* Text Domain: ultimate-dashboard |
| 10 |
* |
| 11 |
* @package Ultimate Dashboard |
| 12 |
*/ |
| 13 |
|
| 14 |
defined( 'ABSPATH' ) || die( "Can't access directly" ); |
| 15 |
|
| 16 |
// Plugin constants. |
| 17 |
define( 'ULTIMATE_DASHBOARD_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 18 |
define( 'ULTIMATE_DASHBOARD_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); |
| 19 |
|
| 20 |
/** |
| 21 |
* Admin scripts & styles. |
| 22 |
*/ |
| 23 |
function udb_admin_scripts() { |
| 24 |
|
| 25 |
global $pagenow, $typenow; |
| 26 |
|
| 27 |
$plugin_data = get_plugin_data( __FILE__ ); |
| 28 |
|
| 29 |
// Widget edit screen & create a new widget screen. |
| 30 |
if ( ( 'post.php' === $pagenow || 'post-new.php' === $pagenow ) && 'udb_widgets' === $typenow ) { |
| 31 |
|
| 32 |
// FontAwesome CSS. |
| 33 |
wp_register_style( 'font-awesome', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/font-awesome.min.css', array(), '4.7.0' ); |
| 34 |
wp_enqueue_style( 'font-awesome' ); |
| 35 |
|
| 36 |
// Select2 CSS. |
| 37 |
wp_register_style( 'select2', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/select2.min.css', array(), '4.0.6-rc.1' ); |
| 38 |
wp_enqueue_style( 'select2' ); |
| 39 |
|
| 40 |
// Custom Post Type CSS. |
| 41 |
wp_register_style( 'ultimate-dashboard-cpt', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/ultimate-dashboard-cpt.css', array(), $plugin_data['Version'] ); |
| 42 |
wp_enqueue_style( 'ultimate-dashboard-cpt' ); |
| 43 |
|
| 44 |
// Select2 JS. |
| 45 |
wp_register_script( 'select2', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/js/select2.min.js', array( 'jquery' ), '4.0.6-rc.1', true ); |
| 46 |
wp_enqueue_script( 'select2' ); |
| 47 |
|
| 48 |
// Custom Post Type JS. |
| 49 |
wp_register_script( 'ultimate-dashboard-cpt', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/js/ultimate-dashboard-cpt.js', array( 'jquery' ), $plugin_data['Version'], true ); |
| 50 |
wp_enqueue_script( 'ultimate-dashboard-cpt' ); |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
// Dashboard widget overview & settings. |
| 55 |
if ( 'edit.php' === $pagenow && 'udb_widgets' === $typenow ) { |
| 56 |
|
| 57 |
// FontAwesome CSS. |
| 58 |
wp_register_style( 'font-awesome', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/font-awesome.min.css', array(), '4.7.0' ); |
| 59 |
wp_enqueue_style( 'font-awesome' ); |
| 60 |
|
| 61 |
// Settings CSS. |
| 62 |
wp_register_style( 'ultimate-dashboard-settings', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/ultimate-dashboard-settings.css', array(), $plugin_data['Version'] ); |
| 63 |
wp_enqueue_style( 'ultimate-dashboard-settings' ); |
| 64 |
|
| 65 |
// CodeMirror. |
| 66 |
wp_enqueue_code_editor( array( 'type' => 'text/html' ) ); |
| 67 |
|
| 68 |
// Settings Page JS. |
| 69 |
wp_register_script( 'ultimate-dashboard-settings', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/js/ultimate-dashboard-settings.js', array( 'jquery' ), $plugin_data['Version'], true ); |
| 70 |
wp_enqueue_script( 'ultimate-dashboard-settings' ); |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
// WordPress dashboard. |
| 75 |
if ( 'index.php' === $pagenow ) { |
| 76 |
|
| 77 |
// FontAwesome CSS. |
| 78 |
wp_register_style( 'font-awesome', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/font-awesome.min.css', array(), '4.7.0' ); |
| 79 |
wp_enqueue_style( 'font-awesome' ); |
| 80 |
|
| 81 |
// Dashboard CSS. |
| 82 |
wp_register_style( 'ultimate-dashboard-index', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/css/ultimate-dashboard-index.css', array(), $plugin_data['Version'] ); |
| 83 |
wp_enqueue_style( 'ultimate-dashboard-index' ); |
| 84 |
|
| 85 |
// Dashboard JS. |
| 86 |
wp_register_script( 'ultimate-dashboard-index', ULTIMATE_DASHBOARD_PLUGIN_URL . 'assets/js/ultimate-dashboard-index.js', array( 'jquery' ), $plugin_data['Version'], true ); |
| 87 |
wp_enqueue_script( 'ultimate-dashboard-index' ); |
| 88 |
|
| 89 |
} |
| 90 |
|
| 91 |
// Highlight PRO link in sub-menu. |
| 92 |
echo '<style>#adminmenu #menu-posts-udb_widgets a[href="https://ultimatedashboard.io/pro/"] { color: tomato; }</style>'; |
| 93 |
|
| 94 |
} |
| 95 |
add_action( 'admin_enqueue_scripts', 'udb_admin_scripts' ); |
| 96 |
|
| 97 |
|
| 98 |
/** |
| 99 |
* Action links. |
| 100 |
* |
| 101 |
* @param array $links The action links array. |
| 102 |
* |
| 103 |
* @return array The action links array. |
| 104 |
*/ |
| 105 |
function udb_add_action_links( $links ) { |
| 106 |
|
| 107 |
$settings = array( '<a href="' . admin_url( 'edit.php?post_type=udb_widgets&page=settings' ) . '">' . __( 'Settings', 'ultimate-dashboard' ) . '</a>' ); |
| 108 |
|
| 109 |
return array_merge( $links, $settings ); |
| 110 |
|
| 111 |
} |
| 112 |
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'udb_add_action_links' ); |
| 113 |
|
| 114 |
/** |
| 115 |
* Plugin deactivation. |
| 116 |
*/ |
| 117 |
function udb_deactivate() { |
| 118 |
|
| 119 |
$udb_settings = get_option( 'udb_settings' ); |
| 120 |
|
| 121 |
if ( isset( $udb_settings['remove-on-uninstall'] ) ) { |
| 122 |
|
| 123 |
delete_option( 'udb_settings' ); |
| 124 |
delete_option( 'udb_pro_settings' ); |
| 125 |
delete_option( 'udb_import' ); |
| 126 |
delete_option( 'udb_compact_widget_widget_type' ); |
| 127 |
|
| 128 |
} |
| 129 |
|
| 130 |
} |
| 131 |
register_deactivation_hook( plugin_basename( __FILE__ ), 'udb_deactivate' ); |
| 132 |
|
| 133 |
// Required files. |
| 134 |
require_once ULTIMATE_DASHBOARD_PLUGIN_DIR . 'inc/init.php'; |
| 135 |
|