options = get_option( 'aiwp_settings', array() ); // initialize custom room name $this->options['room'] = isset( $this->options['room'] ) ? $this->options['room'] : ''; // register the settings add_action( 'admin_init', array( $this, 'register_settings' ) ); // call to enqueue admin scripts and styles add_action( 'admin_enqueue_scripts', array( $this, 'add_stylesheets_and_javascript' ) ); } // end constructor /*---------------------------------------------------------------------------------* * Public Functions *---------------------------------------------------------------------------------*/ /** * Return an instance of this class. * * @since 1.0 * * @return object A single instance of this class. */ public static function get_instance() { // If the single instance hasn't been set, set it now. if ( null == self::$instance ) { self::$instance = new self; } // end if return self::$instance; } // end get_instance /** * Displays a plugin message as soon as the plugin is activated. * * @since 1.0 */ public function display_plugin_activation_message() { if ( ! get_option( 'aiwp_activated' ) ) { // Show the notice $html = '
'; $html .= ''; $html .= '

'; $html .= __( "Yes! One more thing. Click here to customize your appear.in WP settings.", 'aiwp-locale' ); $html .= '

'; $html .= '
'; echo $html; update_option( 'aiwp_activated', TRUE ); } // end if } // end display_plugin_activation_message /** * Deletes activation marker so it can be displayed when the plugin is reinstalled or reactivated * * @since 1.0 */ public static function remove_activation_marker() { delete_option( 'aiwp_activated' ); } // end remove_activation_marker /** * Check for plugin update and updates notices * * @since 1.0 */ public function check_plugin_update() { // if current version greater than previous version stored in database, then update notices (float) AIWP_VERSION > (float) get_option( 'aiwp_db_version' ) ? $this->add_wpsn_notices() : FALSE; } // end check_plugin_update /** * Initialize the stats * * @since 1.0 */ public function initialize_stats() { // retrieve the stats $ai_stats = get_option( 'aiwp_stats' ); // if stats did not previously exist, initialize them if ( '' == $ai_stats ) { $ai_initialize_stats = array( 'public' => array( 'rooms_triggered' => 0, 'invites_sent' => 0, 'invites_accepted' => 0 ), 'private' => array( 'rooms_triggered' => 0, 'invites_sent' => 0, 'invites_accepted' => 0 ), ); add_option( 'aiwp_stats', $ai_initialize_stats ); } } // end initialize_stats /** * Define WP Side Notices for use in plugin * * @since 1.0 */ public function add_wpsn_notices() { // Initialize a new side notice $wpsn = new WP_Side_Notice( 'aiwp' ); // Define the notices $aiwp_notices = array( 'ai-info' => array( 'name' => 'ai-info', 'trigger' => TRUE, 'time' => time() - 5, 'dismiss' => 'none', 'content' => 'appear.in WP plugin developed by UaMV.', 'style' => array( 'height' => '72px', 'color' => '#85ae9b', 'icon' => 'f348' ), 'location' => array( 'options-media.php' ), ), 'ai-support' => array( 'name' => 'ai-support', 'trigger' => TRUE, 'time' => time() - 5, 'dismiss' => 'none', 'content' => 'Require assistance? Visit our support forum.   •   All is well? Consider reviewing the plugin.', 'style' => array( 'height' => '72px', 'color' => '#85ae9b', 'icon' => 'f240' ), 'location' => array( 'options-media.php' ), ), 'ai-stats' => array( 'name' => 'ai-stats', 'trigger' => TRUE, 'time' => time() - 5, 'dismiss' => 'none', 'content' => '', 'style' => array( 'height' => '130px', 'color' => '#85ae9b', 'icon' => 'f185' ), 'location' => array( 'options-media.php' ), ), ); // Add each notice foreach ( $aiwp_notices as $notice => $args ) { $wpsn->add( $args ); } // Update the aiwp database version update_option( 'aiwp_db_version', AIWP_VERSION ); } // end add_wpsn_notices /** * Add stats to the content section of stats notice. * * @since 1.0 */ public function add_stats_content( $content, $notice, $current_user ) { $aiwp_stats = get_option( 'aiwp_stats' ); $html = 'Public Rooms'; $html .= '   •   '; $html .= '' . $aiwp_stats['public']['rooms_triggered'] . ' rooms triggered'; $html .= '   •   '; $html .= '' . $aiwp_stats['public']['invites_accepted'] . ' of ' . $aiwp_stats['public']['invites_sent'] . ' invites accepted'; $html .= ' ' . round( 100 * ( $aiwp_stats['public']['invites_accepted'] / $aiwp_stats['public']['invites_sent'] ), 2 ) . '%'; $html .= '   •   '; $html .= '' . round( ( $aiwp_stats['public']['rooms_triggered'] + $aiwp_stats['public']['invites_accepted'] ) / $aiwp_stats['public']['rooms_triggered'], 2 ) . ' average users per room'; $html .= '
'; $html .= 'Private Rooms'; $html .= '   •   '; $html .= '' . $aiwp_stats['private']['rooms_triggered'] . ' rooms triggered'; $html .= '   •   '; $html .= '' . $aiwp_stats['private']['invites_accepted'] . ' of ' . $aiwp_stats['private']['invites_sent'] . ' invites accepted'; $html .= ' ' . round( 100 * ( $aiwp_stats['private']['invites_accepted'] / $aiwp_stats['private']['invites_sent'] ), 2 ) . '%'; $html .= '   •   '; $html .= '' . round( ( $aiwp_stats['private']['rooms_triggered'] + $aiwp_stats['private']['invites_accepted'] ) / $aiwp_stats['private']['rooms_triggered'], 2 ) . ' average users per room'; return $html; } /** * Schedules the cron for expiring and resetting a daily public room name. * * @since 1.0 */ public function schedule_cron() { // on plugin activation, get random room code $random_room = aiwp_random_room(); // assign to public room add_option( 'aiwp_public_room', $random_room ); // schedule default public room name to reset each day at midnight wp_schedule_event( strtotime('today midnight'), 'daily', 'expireroom' ); } // end schedule_cron /** * Unschedules the cron when plugin is disabled * * @since 1.0 */ public function unschedule_cron() { // get the cron array $crons = _get_cron_array(); // loop through the cron schedule foreach ( $crons as $time => $cron_data ) { // loop through the cron events foreach ( $cron_data as $cron_event => $data ) { // if it's the expireroom event, unschedule it 'expireroom' == $cron_event ? wp_unschedule_event( $time, $cron_event ) : FALSE; } // end foreach } // end foreach // remove the current room code delete_option( 'aiwp_public_room' ); } // end unschedule cron /** * Registers the admin stylesheets and scripts * * @since 1.0 */ public function add_stylesheets_and_javascript() { wp_enqueue_style( 'aiwp-admin-style', AIWP_DIR_URL . 'aiwp-admin.css', array(), AIWP_VERSION, 'screen' ); } /** * Registers the settings fields with the WordPress Settings API. * * @since 1.0 */ public function register_settings() { // First, register a settings section add_settings_section( 'aiwp', 'appear.in', array( $this, 'display_section' ), 'media' ); // Then, register the settings for the Pressgram fields register_setting( 'media', 'aiwp_settings' ); // Now introduce the settings fields add_settings_field( 'aiwp_settings', __( '
' , 'aiwp-locale' ), array( $this, 'display_settings' ) , 'media', 'aiwp' ); } // end register_settings /** * Renders the intro to the settings section. * * @since 1.0 */ public function display_section() { // get the aiwp side notices setting height of 500px $notices = new WP_Side_Notice( 'aiwp', 700 ); add_filter( 'ai-stats_side_notice_content', array( $this, 'add_stats_content' ), 10, 3 ); // display the notices $notices->display(); } /** * Renders the setting fields. * * @since 1.0 */ public function display_settings() { // build the fields $html = '
'; // allow types of rooms (both, public, private) $html .= ''; $html .= '   •   '; // allow default public room name $html .= ''; $html .= '
'; $html .= ' ' . __( '(if not defined here or in shortcode, public room is given random name that expires daily)' , 'aiwp-locale' ) . ''; $html .= '

'; // allow some number of invites for public and private rooms $html .= 'Enable some number of email invitations upon entering...   '; $html .= ''; $html .= __( 'the public room', 'aiwp-locale' ); $html .= ' '; $html .= '   •   '; $html .= __( 'the private room', 'aiwp-locale' ); $html .= ' '; $html .= ''; $html .= '



'; $html .= '
'; echo $html; } // end display_settings } // end class