'This post hasn\'t been updated in over 2 years.', 'years' => 2, 'post' => 1 ); 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']; $this -> _post = $options['post']; $this -> _page = $options['page']; } // 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' ); add_settings_field('notification_location', '', array($this, 'aop_notification_location'), '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 ''; } public function aop_notification_location() { $this -> databaseValues(); echo '_post, 1, false) . '"/>'; echo ''; echo "

"; echo '_page, 1, false) . '">'; 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 $postz = $this->_post; $pagez = $this->_page; $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 ( $postz == 1 ) { if (is_single()) : if ($year >= $setYear) { echo '
'; echo ' ! '; echo "$notification"; echo '
'; } endif; } // display notification in page if configured if ( $pagez == 1 ) { if (is_page()) : if ($year >= $setYear) { echo '
'; echo ' ! '; echo "$notification"; echo '
'; } endif; } return $content; } } // instantiate the class new AlertOldPost;