'This post hasn\'t been updated in over 2 years.', 'years' => 2 ); update_option('apo_alert_old_post', $aop_plugin_options); } // get option value from the database public function databaseValues() { $options = get_option('apo_alert_old_post'); $this -> _notification = $options['notification']; $this -> _years = $options['years']; } // Adding Submenu to settings public function aop_settings_menu() { add_options_page('Alert Post is Old', 'Alert Post is Old', 'manage_options', 'aop-alert-post-old', array($this, 'alert_post_old_function') ); } // setttings form public function alert_post_old_function() { echo '
'; screen_icon(); echo '

Alert Post is Old

'; echo '
'; do_settings_sections('aop-alert-post-old'); settings_fields('aop_settings_group'); submit_button(); } // plugin field and sections public function pluginOption() { add_settings_section('aop_settings_section', 'Plugin Options', null, 'aop-alert-post-old' ); add_settings_field('notification', '', array($this, 'aop_notification'), 'aop-alert-post-old', 'aop_settings_section' ); add_settings_field('years', '', array($this, 'aop_years'), 'aop-alert-post-old', 'aop_settings_section' ); // register settings register_setting('aop_settings_group', 'apo_alert_old_post'); } // ------------------------------------------------------------------ // Settings section callback function // ------------------------------------------------------------------ public function aop_notification() { // call database values just like global in procedural $this -> databaseValues(); echo ''; } public function aop_years() { // call database values $this -> databaseValues(); echo ''; } // ------------------------------------------------------------------ // Plugin functions // ------------------------------------------------------------------ // plugin Stylesheet public function stylesheet() { echo << HTML; } // display notification above post public function displayNotification($content) { global $post; // call database values $this -> databaseValues(); // get settings year $setYear = $this -> _years; // get notification text $notification = $this -> _notification; // calculate post age $year = date('Y') - get_post_time('Y', true, $post -> ID); // show notification only on post if (is_single()) : if ($year >= $setYear) { echo '
'; echo ' ! '; echo "$notification"; echo '
'; } endif; return $content; } } // instantiate the class new AlertOldPost;