Jimmy Peña

.

/>

' . $tta . ''; } else { // plugin enabled but nothing entered? return $default; } } else { // plugin disabled, show whatever was there before return $default; } } // show admin messages to plugin user add_action('admin_notices', 'alt_showAdminMessages'); function alt_showAdminMessages() { // http://wptheming.com/2011/08/admin-notices-in-wordpress/ global $pagenow; if (current_user_can(ALT_PERMISSIONS_LEVEL)) { // user has privilege if ($pagenow == 'options-general.php') { // we are on Settings menu if (isset($_GET['page'])) { if ($_GET['page'] == alt_get_slug()) { // we are on this plugin's settings page $options = alt_getpluginoptions(); if (!empty($options)) { $enabled = (bool)$options[ALT_DEFAULT_ENABLED_NAME]; if (!$enabled) { echo '
' . ALT_PLUGIN_NAME . ' ' . __('is currently disabled.', alt_get_local()) . '
'; } } } } } // end page check } // end privilege check } // end admin msgs function // enqueue admin CSS if we are on the plugin options page add_action('admin_head', 'insert_alt_admin_css'); function insert_alt_admin_css() { global $pagenow; if (current_user_can(ALT_PERMISSIONS_LEVEL)) { // user has privilege if ($pagenow == 'options-general.php') { // we are on Settings menu if (isset($_GET['page'])) { if ($_GET['page'] == alt_get_slug()) { // we are on this plugin's settings page alt_admin_styles(); } } } } } // add helpful links to plugin page next to plugin name // http://bavotasan.com/2009/a-settings-link-for-your-wordpress-plugins/ // http://wpengineer.com/1295/meta-links-for-wordpress-plugins/ add_filter('plugin_action_links_' . plugin_basename(__FILE__), 'alt_plugin_settings_link'); add_filter('plugin_row_meta', 'alt_meta_links', 10, 2); function alt_plugin_settings_link($links) { return alt_settingslink($links, alt_get_slug(), alt_get_local()); } function alt_meta_links($links, $file) { if ($file == plugin_basename(__FILE__)) { $links = array_merge($links, array( sprintf(__('Support', alt_get_local()), alt_get_slug()), sprintf(__('Documentation', alt_get_local()), alt_get_slug()), sprintf(__('FAQ', alt_get_local()), alt_get_slug()) )); } return $links; } // enqueue/register the admin CSS file function alt_admin_styles() { wp_enqueue_style('alt_admin_style'); } function register_alt_admin_style() { wp_register_style('alt_admin_style', plugins_url(alt_get_path() . '/css/admin.css'), array(), ALT_VERSION . "_" . date('njYHis', filemtime(dirname(__FILE__) . '/css/admin.css')), 'all'); } // when plugin is activated, create options array and populate with defaults register_activation_hook(__FILE__, 'alt_activate'); function alt_activate() { $options = alt_getpluginoptions(); update_option(alt_get_option(), $options); // delete option when plugin is uninstalled register_uninstall_hook(__FILE__, 'uninstall_alt_plugin'); } function uninstall_alt_plugin() { delete_option(alt_get_option()); } // generic function that returns plugin options from DB // if option does not exist, returns plugin defaults function alt_getpluginoptions() { return get_option(alt_get_option(), array( ALT_DEFAULT_ENABLED_NAME => ALT_DEFAULT_ENABLED, ALT_DEFAULT_TEXT_NAME => ALT_DEFAULT_TEXT )); } function alt_settingslink($linklist, $slugname = '', $localname = '') { $settings_link = sprintf( __('Settings', $localname), $slugname); array_unshift($linklist, $settings_link); return $linklist; } // encapsulate these and call them throughout the plugin instead of hardcoding the constants everywhere function alt_get_slug() { return ALT_SLUG; } function alt_get_local() { return ALT_LOCAL; } function alt_get_option() { return ALT_OPTION; } function alt_get_path() { return ALT_PATH; } function alt_getsupportinfo($slugname = '', $localname = '') { $output = __('Do you need help with this plugin? Check out the following resources:', $localname); $output .= '
    '; $output .= '
  1. ' . sprintf( __('Documentation', $localname), $slugname) . '
  2. '; $output .= '
  3. ' . sprintf( __('FAQ
    ', $localname), $slugname) . '
  4. '; $output .= '
  5. ' . sprintf( __('Support Forum
    ', $localname), $slugname) . '
  6. '; $output .= '
  7. ' . sprintf( __('Plugin Homepage / Demo
    ', $localname), $slugname) . '
  8. '; $output .= '
  9. ' . sprintf( __('Development
    ', $localname), $slugname) . '
  10. '; $output .= '
  11. ' . sprintf( __('Changelog
    ', $localname), $slugname) . '
  12. '; $output .= '
'; $output .= sprintf( __('If you like this plugin, please rate it on WordPress.org', $localname), $slugname); $output .= sprintf( __(' and click the Works button. ', $localname), $slugname); $output .= '


'; $output .= __('Your donations encourage further development and support. ', $localname); $output .= 'Donate with PayPal'; $output .= '

'; return $output; } function alt_checkifset($optionname, $optiondefault, $optionsarr) { return (isset($optionsarr[$optionname]) ? $optionsarr[$optionname] : $optiondefault); } function alt_getlinebreak() { echo ''; } function alt_explanationrow($msg = '') { echo '' . $msg . ''; } function alt_getimagefilename($fname = '') { return plugins_url(alt_get_path() . '/images/' . $fname); } ?>