* @copyright (c) 2013, OnePress Ltd * * @package factory-notices * @since 1.0.0 */ // creating a license manager for each plugin created via the factory add_action('factory_notices_323_plugin_created', 'factory_notices_323_plugin_created'); function factory_notices_323_plugin_created( $plugin ) { new FactoryNotices323( $plugin ); } /** * A class to manage notices. * * @since 1.0.0 */ class FactoryNotices323 { public function __construct( $plugin ) { $this->plugin = $plugin; add_action('current_screen', array( $this, 'currentScreenAction') ); } public function currentScreenAction() { $this->notices = apply_filters('factory_notices_' . $this->plugin->pluginName, array()); if ( count( $this->notices ) == 0 ) return; $screen = get_current_screen(); $this->hasNotices = false; foreach ($this->notices as $notice) { $where = empty( $notice['where'] ) ? array('plugins','dashboard','edit') : $notice['where']; $screen = get_current_screen(); if ( in_array($screen->base, $where) ) { $this->hasNotices = true; break; }; } if ( $this->hasNotices ) { add_action('factory_bootstrap_enqueue_scripts_' . $this->plugin->pluginName, array( $this, 'enqueueBootstrapScripts' )); add_action('admin_enqueue_scripts', array( $this, 'enqueueScripts' )); add_action('admin_notices', array( $this, 'showNotices' )); } } public function enqueueBootstrapScripts() { $this->plugin->bootstrap->enqueueStyle('bootstrap.core'); } public function enqueueScripts() { wp_enqueue_style('factory-notices-323-css', FACTORY_NOTICES_323_URL . '/assets/css/notices.css'); wp_enqueue_script('factory-notices-323-js', FACTORY_NOTICES_323_URL . '/assets/js/notices.js'); } public function showNotices() { if ( count( $this->notices ) == 0 ) return; if ( !current_user_can('activate_plugins') || !current_user_can('edit_plugins') || !current_user_can('install_plugins')) return; ?> hasNotices ) { ?>
notices as $notice) { $this->showNotice($notice); } ?>
an id of the notice * "where" => a place where the notice should be visible (plugins, dashboard and so on) * "header" => a header of the notice * "message" => a message of the notice * "class" => an extra class to add to the notice * "close" => if true, then the close icon will be available to dissmish the notice * * @since 1.0.0 * @param type $data * @return void */ public function showNotice( $data ) { $type = empty( $data['type'] ) ? 'offer' : $data['type']; $subtype = empty( $data['subtype'] ) ? 'none' : $data['subtype']; $position = empty( $data['position'] ) ? 'notice' : $data['position']; $layout = empty( $data['layout'] ) ? 'standard' : $data['layout']; // checking if we should show a notice on a current page $where = empty( $data['where'] ) ? array('plugins','dashboard', 'edit') : $data['where']; $screen = get_current_screen(); if ( !in_array($screen->base, $where) ) return; // setups a content of the notice to display $header = empty( $data['header'] ) ? null : $data['header']; $message = empty( $data['message'] ) ? null : $data['message']; $hasHeader = !empty( $header ); $hasMessage = !empty( $message ); $hasClose = isset( $data['close'] ) ? $data['close'] : false; $hasIcon = isset( $data['icon'] ); if ( !isset( $data['buttons'] ) ) $data['buttons'] = array(); $classes = array(); if ( !empty( $data['class'] ) ) $classes[] = $data['class']; if ( !empty( $data['plugin'] ) ) $classes[] = 'notice-' . $data['plugin']; if ( $hasIcon ) $classes[] = 'factory-has-icon'; ?>

renderNoticeButton( $buttonData, $data['id'] ) ?>