prefix = $prefix; $this->height = $height; $this->notices = get_option( $this->prefix . '_side_notices', array() ); // Load the administrative Stylesheets and JavaScript add_action( 'admin_enqueue_scripts', WP_Side_Notice::add_stylesheets_and_javascript() ); // Process responses to the notices add_action( 'admin_init', WP_Side_Notice::process_response() ); } // end constructor /*---------------------------------------------------------------------------------* * Public Functions *---------------------------------------------------------------------------------*/ /** * Registers the plugin's administrative stylesheets and JavaScript * * @since 1.0 */ public function add_stylesheets_and_javascript() { wp_enqueue_style( 'wp-side-notice-style', plugin_dir_url( __FILE__ ) . 'wpsn.css', array(), $this->version, 'screen' ); wp_enqueue_script( 'wp-side-notice-js', plugin_dir_url( __FILE__ ) . 'wpsn.js' , array(), $this->version, FALSE ); } // end add_stylesheets_and_javascript /** * Add a notice to the array during plugin activation. * * @since 1.0 */ public function add( $args ) { $this->notices[ $args['name'] ] = $args; update_option( $this->prefix . '_side_notices', $this->notices ); } /** * Remove notices from the array. * * @since 1.0 */ public function remove( $args = 'all' ) { if ( 'all' == $args ) { foreach ( $this->notices as $name => $notice ) { unset( $this->notices[ $name ] ); } } else { foreach ( $args as $name ) { unset( $this->notices[ $name ] ); } } update_option( $this->prefix . '_side_notices', $this->notices ); } /** * Returns the active plugin notices for display on the settings page summary. * * @since 1.0 */ public function display() { global $pagenow; $current_user = wp_get_current_user(); // Get the notice options from the user $user_notices = get_user_meta( $current_user->ID, $this->prefix . '_user_side_notices', TRUE ); // If not yet set, then set the usermeta as an array ! is_array( $user_notices ) ? add_user_meta( $current_user->ID, $this->prefix . '_user_side_notices', array() ) : FALSE; // Create specific notices if they do not exist, otherwise set to current notice state foreach ( $this->notices as $name => $notice ) { if ( ! isset( $user_notices[ $name ] ) ) { $user_notices[ $name ] = array( 'trigger' => TRUE, 'time' => $notice['time'], ); } } // Update the users meta update_user_meta( $current_user->ID, $this->prefix . '_user_side_notices', $user_notices ); // Set the variable that will hold the html $html = '
'; $html .= apply_filters( $name . '_side_notice_content', $notice['content'], $notice, $current_user ); $html .= $this->get_dismissals( $name ); $html .= '
'; $html .= '