_init();
}
$this->_getSettings();
if ( is_callable( array($this, '_postSettingsInit') ) ) {
$this->_postSettingsInit();
}
add_filter( 'init', array( $this, 'init_locale' ) );
add_action( 'admin_init', array( $this, 'registerOptions' ) );
add_filter( 'plugin_action_links', array( $this, 'addPluginPageLinks' ), 10, 2 );
add_filter( 'plugin_row_meta', array( $this, 'addPluginMetaLinks' ), 10, 2 );
add_action( 'admin_menu', array( $this, 'registerOptionsPage' ) );
if ( is_callable(array( $this, 'addOptionsMetaBoxes' )) ) {
add_action( 'admin_init', array( $this, 'addOptionsMetaBoxes' ) );
}
add_action( 'admin_init', array( $this, 'addDefaultOptionsMetaBoxes' ) );
add_action( 'wp_dashboard_setup', array( $this, 'addDashboardWidgets' ), null, 9 );
add_action( 'admin_print_scripts', array( $this,'optionsPageScripts' ) );
add_action( 'admin_print_styles', array( $this,'optionsPageStyles' ) );
/**
* Add update messages that can be attached to the CURRENT release (not
* this one), but only for 2.8+
*/
global $wp_version;
if ( version_compare('2.8', $wp_version, '<=') ) {
add_action ( 'in_plugin_update_message-'.$this->_file , array ( $this , 'changelog' ), null, 2 );
}
}
/**
* Function to instantiate our class and make it a singleton
*/
abstract public static function getInstance();
public function init_locale() {
$lang_dir = basename(dirname(__FILE__)) . '/languages';
load_plugin_textdomain( $this->_slug, 'wp-content/plugins/' . $lang_dir, $lang_dir);
}
protected function _getSettings() {
foreach ( $this->_optionNames as $opt ) {
$this->_settings[$opt] = apply_filters($this->_slug.'-opt-'.$opt, get_option($opt));
}
}
public function registerOptions() {
foreach ( $this->_optionNames as $opt ) {
if ( !empty($this->_optionCallbacks[$opt]) && is_callable( $this->_optionCallbacks[$opt] ) ) {
$callback = $this->_optionCallbacks[$opt];
} else {
$callback = '';
}
register_setting( $this->_optionGroup, $opt, $callback );
}
}
public function changelog ($pluginData, $newPluginData) {
require_once( ABSPATH . 'wp-admin/includes/plugin-install.php' );
$plugin = plugins_api( 'plugin_information', array( 'slug' => $newPluginData->slug ) );
if ( !$plugin || is_wp_error( $plugin ) || empty( $plugin->sections['changelog'] ) ) {
return;
}
$changes = $plugin->sections['changelog'];
$pos = strpos( $changes, '
' . preg_replace('/[^\d\.]/', '', $pluginData['Version'] ) );
if ( $pos !== false ) {
$changes = trim( substr( $changes, 0, $pos ) );
}
$replace = array(
'' => '',
'' => '',
);
echo str_replace( array_keys($replace), $replace, $changes );
}
public function registerOptionsPage() {
if ( apply_filters( 'xpf-options_page-'.$this->_slug, true ) && is_callable( array( $this, 'options_page' ) ) ) {
add_options_page( $this->_pageTitle, $this->_menuTitle, $this->_accessLevel, $this->_hook, array( $this, 'options_page' ) );
}
}
protected function _filterBoxesMain($boxName) {
if ( 'main' == strtolower($boxName) ) {
return false;
}
return $this->_filterBoxesHelper($boxName, 'main');
}
protected function _filterBoxesSidebar($boxName) {
return $this->_filterBoxesHelper($boxName, 'sidebar');
}
protected function _filterBoxesHelper($boxName, $test) {
return ( strpos( strtolower($boxName), strtolower($test) ) !== false );
}
public function options_page() {
global $wp_meta_boxes;
$allBoxes = array_keys( $wp_meta_boxes['xavisys-'.$this->_slug] );
$mainBoxes = array_filter( $allBoxes, array( $this, '_filterBoxesMain' ) );
unset($mainBoxes['main']);
sort($mainBoxes);
$sidebarBoxes = array_filter( $allBoxes, array( $this, '_filterBoxesSidebar' ) );
unset($sidebarBoxes['sidebar']);
sort($sidebarBoxes);
$main_width = empty( $sidebarBoxes )? '100%' : '75%';
?>
screenIconLink(); ?>
_pageTitle); ?>
_file ) {
// Add Widget Page link to our plugin
$link = $this->getOptionsLink();
array_unshift( $links, $link );
// Add Support Forum link to our plugin
$link = $this->getSupportForumLink();
array_unshift( $links, $link );
}
return $links;
}
public function addPluginMetaLinks( $meta, $file ){
if ( $file == $this->_file ) {
// Add Widget Page link to our plugin
$meta[] = $this->getDonateLink(__('Donate'));
}
return $meta;
}
public function getSupportForumLink( $linkText = '' ) {
if ( empty($linkText) ) {
$linkText = __( 'Support Forum', $this->_slug );
}
return '' . $linkText . '';
}
public function getDonateLink( $linkText = '' ) {
$url = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=' . $this->_paypalButtonId;
if ( empty($linkText) ) {
$linkText = __( 'Donate to show your appreciation.', $this->_slug );
}
return "{$linkText}";
}
public function getSupportForumUrl() {
return 'http://xavisys.com/support/forum/'.$this->_slug;
}
public function getOptionsLink( $linkText = '' ) {
if ( empty($linkText) ) {
$linkText = __( 'Settings', $this->_slug );
}
return '' . $linkText . '';
}
public function getOptionsUrl() {
return admin_url( 'options-general.php?page=' . $this->_hook );
}
public function optionsPageStyles() {
if (isset($_GET['page']) && $_GET['page'] == $this->_hook) {
wp_enqueue_style('dashboard');
wp_enqueue_style('xavisys-options-css', plugin_dir_url( __FILE__ ) . 'xavisys-plugin-framework.css');
}
}
public function addDefaultOptionsMetaBoxes() {
if ( apply_filters( 'show-xavisys-like-this', true ) ) {
add_meta_box( $this->_slug . '-like-this', __('Like this Plugin?', $this->_slug), array($this, 'likeThisMetaBox'), 'xavisys-' . $this->_slug, 'sidebar');
}
if ( apply_filters( 'show-xavisys-support', true ) ) {
add_meta_box( $this->_slug . '-support', __('Need Support?', $this->_slug), array($this, 'supportMetaBox'), 'xavisys-' . $this->_slug, 'sidebar');
}
if ( apply_filters( 'show-xavisys-feed', true ) ) {
add_meta_box( $this->_slug . '-xavisys-feed', __('Latest news from Xavisys', $this->_slug), array($this, 'xavisysFeedMetaBox'), 'xavisys-' . $this->_slug, 'sidebar');
}
}
public function likeThisMetaBox() {
echo '
';
_e('Then please do any or all of the following:', $this->_slug);
echo '
';
}
public function supportMetaBox() {
echo '';
echo sprintf(__('If you have any problems with this plugin or ideas for improvements or enhancements, please use the Xavisys Support Forums.', $this->_slug), $this->getSupportForumUrl() );
echo '
';
}
public function xavisysFeedMetaBox() {
$args = array(
'url' => $this->_feed_url,
'items' => '5',
);
echo '";
}
public function addDashboardWidgets() {
if ( apply_filters( 'xpf-dashboard-widget', true ) ) {
wp_add_dashboard_widget( 'dashboardb_xavisys' , 'The Latest News From Xavisys' , array( $this, 'dashboardWidget' ) );
}
}
public function dashboardWidget() {
$args = array(
'url' => $this->_feed_url,
'items' => '3',
'show_date' => 1,
'show_summary' => 1,
);
echo '";
}
public function screenIconLink($name = 'xavisys') {
$link = '';
if ( function_exists( 'get_screen_icon' ) ) {
$link .= get_screen_icon( $name );
} else {
ob_start();
screen_icon($name);
$link .= ob_get_clean();
}
$link .= '';
echo apply_filters('xpf-screenIconLink', $link, $name );
}
public function optionsPageScripts() {
if (isset($_GET['page']) && $_GET['page'] == $this->_hook) {
wp_enqueue_script('postbox');
wp_enqueue_script('dashboard');
}
}
}
}