/lib/gftb-admin-extras.php

  1. <?php 
  2. /** 
  3. * Helper functions for the admin - plugin links. 
  4. * 
  5. * @package Gravity Forms Toolbar 
  6. * @subpackage Admin 
  7. * @author David Decker - DECKERWEB 
  8. * @copyright Copyright (c) 2012-2014, David Decker - DECKERWEB 
  9. * @license http://www.opensource.org/licenses/gpl-license.php GPL-2.0+ 
  10. * @link http://genesisthemes.de/en/wp-plugins/gravity-forms-toolbar/ 
  11. * @link http://deckerweb.de/twitter 
  12. * 
  13. * @since 1.0.0 
  14. */ 
  15.  
  16. /** 
  17. * Exit if accessed directly. 
  18. * 
  19. * @since 1.6.0 
  20. */ 
  21. if ( ! defined( 'WPINC' ) ) { 
  22. exit( 'Sorry, you are not allowed to access this file directly.' ); 
  23.  
  24.  
  25. /** 
  26. * Add "Settings" link to plugin page. 
  27. * 
  28. * @since 1.4.0 
  29. * 
  30. * @param $gftb_links 
  31. * @param $gftb_settings_link 
  32. * 
  33. * @return strings settings link 
  34. */ 
  35. function ddw_gftb_settings_page_link( $gftb_links ) { 
  36.  
  37. /** Plugin's settings page link */ 
  38. $gftb_settings_link = sprintf( 
  39. '<a href="%s" title="%s">%s</a>',  
  40. admin_url( 'options-general.php?page=ddw_gftb_options_page' ),  
  41. esc_html__( 'Go to the settings page', 'gravity-forms-toolbar' ),  
  42. esc_attr__( 'Settings', 'gravity-forms-toolbar' ) 
  43. ); 
  44.  
  45. /** Set the order of the links */ 
  46. array_unshift( $gftb_links, $gftb_settings_link ); 
  47.  
  48. /** Display plugin settings links */ 
  49. return apply_filters( 'gftb_filter_settings_page_link', $gftb_links ); 
  50.  
  51. } // end of function ddw_gftb_settings_page_link 
  52.  
  53.  
  54. add_filter( 'plugin_row_meta', 'ddw_gftb_plugin_links', 10, 2 ); 
  55. /** 
  56. * Add various support links to plugin page 
  57. * 
  58. * @since 1.0.0 
  59. * 
  60. * @uses ddw_gftb_info_values() 
  61. * 
  62. * @param $gftb_links 
  63. * @param $gftb_file 
  64. * 
  65. * @return strings plugin links 
  66. */ 
  67. function ddw_gftb_plugin_links( $gftb_links, $gftb_file ) { 
  68.  
  69. /** Capability check */ 
  70. if ( ! current_user_can( 'install_plugins' ) ) { 
  71.  
  72. return $gftb_links; 
  73.  
  74. } // end if cap check 
  75.  
  76. /** List additional links only for this plugin */ 
  77. if ( $gftb_file == GFTB_PLUGIN_BASEDIR . 'gravity-forms-toolbar.php' ) { 
  78.  
  79. $gftb_info = (array) ddw_gftb_info_values(); 
  80.  
  81. $gftb_links[] = '<a href="' . esc_url( $gftb_info[ 'url_wporg_faq' ] ) . '" target="_new" title="' . __( 'FAQ', 'gravity-forms-toolbar' ) . '">' . __( 'FAQ', 'gravity-forms-toolbar' ) . '</a>'; 
  82.  
  83. $gftb_links[] = '<a href="' . esc_url( $gftb_info[ 'url_wporg_forum' ] ) . '" target="_new" title="' . __( 'Support', 'gravity-forms-toolbar' ) . '">' . __( 'Support', 'gravity-forms-toolbar' ) . '</a>'; 
  84.  
  85. $gftb_links[] = '<a href="' . esc_url( $gftb_info[ 'url_snippets' ] ) . '" target="_new" title="' . __( 'Code Snippets for Customization', 'gravity-forms-toolbar' ) . '">' . __( 'Code Snippets', 'gravity-forms-toolbar' ) . '</a>'; 
  86.  
  87. $gftb_links[] = '<a href="' . esc_url( $gftb_info[ 'url_translate' ] ) . '" target="_new" title="' . __( 'Translations', 'gravity-forms-toolbar' ) . '">' . __( 'Translations', 'gravity-forms-toolbar' ) . '</a>'; 
  88.  
  89. $gftb_links[] = '<a href="' . esc_url( $gftb_info[ 'url_donate' ] ) . '" target="_new" title="' . __( 'Donate', 'gravity-forms-toolbar' ) . '"><strong>' . __( 'Donate', 'gravity-forms-toolbar' ) . '</strong></a>'; 
  90.  
  91. } // end if plugin links 
  92.  
  93. /** Output the links */ 
  94. return apply_filters( 'gftb_filter_plugin_links', $gftb_links ); 
  95.  
  96. } // end of function ddw_gftb_plugin_links 
  97.  
  98.  
  99. add_action( 'load-settings_page_ddw_gftb_options_page', 'ddw_gftb_gravityforms_help_tab' ); 
  100. /** 
  101. * Create and display plugin help tab. 
  102. * 
  103. * @since 1.5.0 
  104. * 
  105. * @uses get_current_screen() 
  106. * @uses WP_Screen::add_help_tab() 
  107. * @uses WP_Screen::set_help_sidebar() 
  108. * @uses ddw_gftb_help_sidebar_content() 
  109. * @uses ddw_gftb_help_sidebar_content_extra() 
  110. * 
  111. * @global mixed $gftb_gravityforms_screen 
  112. */ 
  113. function ddw_gftb_gravityforms_help_tab() { 
  114.  
  115. global $gftb_gravityforms_screen; 
  116.  
  117. $gftb_gravityforms_screen = get_current_screen(); 
  118.  
  119. /** Display help tabs only for WordPress 3.3 or higher */ 
  120. if ( ! class_exists( 'WP_Screen' ) 
  121. || ! $gftb_gravityforms_screen 
  122. || ( defined( 'GFTB_DISPLAY' ) && ! GFTB_DISPLAY ) 
  123. ) { 
  124.  
  125. return; 
  126.  
  127. } // end if 
  128.  
  129. /** Add the help tab */ 
  130. $gftb_gravityforms_screen->add_help_tab( array( 
  131. 'id' => 'gftb-gravityforms-help',  
  132. 'title' => __( 'Gravity Forms Toolbar', 'gravity-forms-toolbar' ),  
  133. 'callback' => apply_filters( 'gftb_filter_help_tab_content', 'ddw_gftb_gravityforms_help_tab_content' ),  
  134. ) ); 
  135.  
  136. /** Add help sidebar */ 
  137. $gftb_gravityforms_screen->set_help_sidebar( ddw_gftb_help_sidebar_content_extra() . ddw_gftb_help_sidebar_content() ); 
  138.  
  139. } // end of function ddw_gftb_gravityforms_help_tab 
  140.  
  141.  
  142. /** 
  143. * Create and display plugin help tab content. 
  144. * 
  145. * @since 1.5.0 
  146. * 
  147. * @uses ddw_gftb_info_values() 
  148. * @uses ddw_gftb_plugin_get_data() 
  149. */ 
  150. function ddw_gftb_gravityforms_help_tab_content() { 
  151.  
  152. $gftb_info = (array) ddw_gftb_info_values(); 
  153.  
  154. echo '<h3>' . __( 'Plugin', 'gravity-forms-toolbar' ) . ': ' . __( 'Gravity Forms Toolbar', 'gravity-forms-toolbar' ) . ' <small>v' . esc_attr( ddw_gftb_plugin_get_data( 'Version' ) ) . '</small></h3>'; 
  155.  
  156. echo '<ul>' .  
  157. '<li><a href="' . esc_url( $gftb_info[ 'url_suggestions' ] ) . '" target="_new" title="' . __( 'Suggest new resource items or Add-Ons/ plugins for support', 'gravity-forms-toolbar' ) . '">' . __( 'Suggest new resource items or Add-Ons/ plugins for support', 'gravity-forms-toolbar' ) . '</a></li>' . 
  158. '<li><a href="' . esc_url( $gftb_info[ 'url_snippets' ] ) . '" target="_new" title="' . __( 'Code snippets for customizing & branding', 'gravity-forms-toolbar' ) . '">' . __( 'Code snippets for customizing & branding', 'gravity-forms-toolbar' ) . '</a></li>'; 
  159.  
  160. /** Optional: recommended plugins */ 
  161. if ( ! class_exists( 'GFCPTAddon' ) 
  162. || ! class_exists( 'GFReadyClassesAddon' ) 
  163. || ! function_exists( 'gfe_init' ) /** ! class_exists( 'GFEntryDetail' ) */ 
  164. ) { 
  165.  
  166. echo '<li><em>' . __( 'Other, recommended Gravity Forms plugins', 'gravity-forms-toolbar' ) . '</em>:'; 
  167.  
  168. if ( ! class_exists( 'GFCPTAddon' ) ) { 
  169.  
  170. echo '<br />» <a href="http://wordpress.org/plugins/gravity-forms-custom-post-types/" target="_new" title="Gravity Forms + Custom Post Types">Gravity Forms + Custom Post Types</a> — ' . __( 'map forms that create posts to a custom post type, also map dropdown select, radio buttons list and checkboxes lists to a custom taxonomy', 'gravity-forms-toolbar' ); 
  171.  
  172. } // end if plugin check 
  173.  
  174. if ( ! class_exists( 'GFReadyClassesAddon' ) ) { 
  175.  
  176. echo '<br />» <a href="http://wordpress.org/plugins/gravity-forms-css-ready-selector/" target="_new" title="Gravity Forms CSS Ready Class Selector">Gravity Forms CSS Ready Class Selector</a> — ' . __( 'easily select a CSS "Ready Class" for your fields within Gravity Forms', 'gravity-forms-toolbar' ); 
  177.  
  178. } // end if plugin check 
  179.  
  180. if ( ! function_exists( 'gfe_init' ) ) { 
  181.  
  182. echo '<br />» <a href="http://wordpress.org/plugins/gravity-forms-pdf-extended/" target="_new" title="Gravity Forms PDF Extended">Gravity Forms PDF Extended</a> — ' . __( 'save/view/download a PDF from the front- and back-end, and automate PDF creation on form submission', 'gravity-forms-toolbar' ); 
  183.  
  184. } // end if plugin check 
  185.  
  186. echo '</li>'; 
  187.  
  188. } // end if plugins check 
  189.  
  190. echo '<li><em>' . __( 'Miscellaneous', 'gravity-forms-toolbar' ) . ':</em>' . 
  191. '<br /><a href="http://friendfeed.com/gravityforms-news" target="_new" title="' . __( 'Gravity Forms News Planet', 'gravity-forms-toolbar' ) . '">' . __( 'Gravity Forms News Planet (official and community news via FriendFeed service)', 'gravity-forms-toolbar' ) . 
  192. '</li>'; 
  193.  
  194. /** Set first release year */ 
  195. $release_first_year = ( '' != $gftb_info[ 'first_release' ] && date( 'Y' ) != $gftb_info[ 'first_release' ] ) ? $gftb_info[ 'first_release' ] . '–' : ''; 
  196.  
  197. echo '</ul>' . 
  198. '<p><h4>' . __( 'Important plugin links:', 'gravity-forms-toolbar' ) . '</h4>' . 
  199.  
  200. '<a class="button" href="' . esc_url( $gftb_info[ 'url_plugin' ] ) . '" target="_new" title="' . __( 'Plugin website', 'gravity-forms-toolbar' ) . '">' . __( 'Plugin website', 'gravity-forms-toolbar' ) . '</a>' . 
  201.  
  202. '  <a class="button" href="' . esc_url( $gftb_info[ 'url_wporg_faq' ] ) . '" target="_new" title="' . __( 'FAQ', 'gravity-forms-toolbar' ) . '">' . __( 'FAQ', 'gravity-forms-toolbar' ) . '</a>' . 
  203.  
  204. '  <a class="button" href="' . esc_url( $gftb_info[ 'url_wporg_forum' ] ) . '" target="_new" title="' . _x( 'Support', 'Translators: Plugin support links', 'gravity-forms-toolbar' ) . '">' . _x( 'Support', 'Translators: Plugin support links', 'gravity-forms-toolbar' ) . '</a>' . 
  205.  
  206. '  <a class="button" href="' . esc_url( $gftb_info[ 'url_snippets' ] ) . '" target="_new" title="' . __( 'Code Snippets for Customization', 'gravity-forms-toolbar' ) . '">' . __( 'Code Snippets', 'gravity-forms-toolbar' ) . '</a>' . 
  207.  
  208. '  <a class="button" href="' . esc_url( $gftb_info[ 'url_translate' ] ) . '" target="_new" title="' . __( 'Translations', 'gravity-forms-toolbar' ) . '">' . __( 'Translations', 'gravity-forms-toolbar' ) . '</a>' . 
  209.  
  210. '  <a class="button" href="' . esc_url( $gftb_info[ 'url_donate' ] ) . '" target="_new" title="' . __( 'Donate', 'gravity-forms-toolbar' ) . '"><strong>' . __( 'Donate', 'gravity-forms-toolbar' ) . '</strong></a></p>'; 
  211.  
  212. echo '<p><a href="' . esc_url( $gftb_info[ 'url_license' ] ). '" target="_new" title="' . esc_attr( $gftb_info[ 'license' ] ). '">' . esc_attr( $gftb_info[ 'license' ] ). '</a> © ' . $release_first_year . date( 'Y' ) . ' <a href="' . esc_url( ddw_gftb_plugin_get_data( 'AuthorURI' ) ) . '" target="_new" title="' . esc_attr__( ddw_gftb_plugin_get_data( 'Author' ) ) . '">' . esc_attr__( ddw_gftb_plugin_get_data( 'Author' ) ) . '</a></p>'; 
  213.  
  214. } // end of function ddw_gftb_gravityforms_help_tab_content 
  215.  
  216.  
  217. /** 
  218. * Helper function for returning the Help Sidebar content. 
  219. * 
  220. * @since 1.6.0 
  221. * 
  222. * @uses ddw_gftb_info_values() 
  223. * @uses ddw_gftb_plugin_get_data() 
  224. * 
  225. * @return string HTML content for help sidebar. 
  226. */ 
  227. function ddw_gftb_help_sidebar_content() { 
  228.  
  229. $gftb_info = (array) ddw_gftb_info_values(); 
  230.  
  231. $gftb_help_sidebar = '<p><strong>' . __( 'More about the plugin author', 'gravity-forms-toolbar' ) . '</strong></p>' . 
  232. '<p>' . __( 'Social:', 'gravity-forms-toolbar' ) . '<br /><a href="https://twitter.com/deckerweb" target="_blank" title="@ Twitter">Twitter</a> | <a href="https://www.facebook.com/deckerweb.service" target="_blank" title="@ Facebook">Facebook</a> | <a href="http://deckerweb.de/gplus" target="_blank" title="@ Google+">Google+</a> | <a href="' . esc_url( ddw_gftb_plugin_get_data( 'AuthorURI' ) ) . '" target="_blank" title="@ deckerweb.de">deckerweb</a></p>' . 
  233. '<p><a href="' . esc_url( $gftb_info[ 'url_wporg_profile' ] ) . '" target="_blank" title="@ WordPress.org">@ WordPress.org</a></p>'; 
  234.  
  235. return apply_filters( 'gftb_filter_help_sidebar_content', $gftb_help_sidebar ); 
  236.  
  237. } // end of function ddw_gftb_help_sidebar_content 
  238.  
  239.  
  240. /** 
  241. * Helper function for returning the Help Sidebar content - extra for plugin setting page. 
  242. * 
  243. * @since 1.7.0 
  244. * 
  245. * @uses ddw_gftb_info_values() 
  246. * 
  247. * @return string Extra HTML content for help sidebar. 
  248. */ 
  249. function ddw_gftb_help_sidebar_content_extra() { 
  250.  
  251. $gftb_info = (array) ddw_gftb_info_values(); 
  252.  
  253. $gftb_help_sidebar_content_extra = '<p><strong>' . __( 'Actions', 'gravity-forms-toolbar' ) . '</strong></p>' . 
  254. '<p><a class="button button-primary" href="' . esc_url( $gftb_info[ 'url_donate' ] ) . '" target="_new">→ ' . __( 'Donate', 'gravity-forms-toolbar' ) . '</a></p>' . 
  255. '<p><a class="button button-secondary" href="' . esc_url( $gftb_info[ 'url_wporg_forum' ] ) . '" target="_new">→ ' . __( 'Support Forum', 'gravity-forms-toolbar' ) . '</a></p><br />'; 
  256.  
  257. return apply_filters( 'gftb_filter_help_sidebar_content_extra', $gftb_help_sidebar_content_extra ); 
  258.  
  259. } // end of function ddw_gftb_help_sidebar_content_extra 
  260.  
  261.  
  262. add_action( 'admin_notices', 'ddw_gftb_plugin_advise_activation' ); 
  263. /** 
  264. * Show user message if Gravity Forms base plugin is not active yet. 
  265. * 
  266. * @since 1.6.1 
  267. * 
  268. * @uses get_option() 
  269. * @uses get_current_screen() 
  270. */ 
  271. function ddw_gftb_plugin_advise_activation() { 
  272.  
  273. /** Bail early if message was shown already */ 
  274. if ( TRUE === get_option( 'gftb-display-activation-message' ) ) { 
  275.  
  276. return; 
  277.  
  278. } // end if 
  279.  
  280. /** Get current screen hook */ 
  281. $screen = get_current_screen(); 
  282.  
  283. /** If message was not shown yet, just show it: */ 
  284. if ( FALSE === get_option( 'gftb-display-activation-message' ) 
  285. && ! class_exists( 'RGForms' ) 
  286. && 'plugins' === $screen->id 
  287. ) { 
  288.  
  289. /** Add our helper option */ 
  290. add_option( 'gftb-display-activation-message', TRUE ); 
  291.  
  292. /** Setup user notice */ 
  293. $gftb_notice = '<div class="error"><p>'; 
  294. $gftb_notice .= sprintf( 
  295. __( 'To have %s plugin doing anything you need the %s base plugin installed and activated. You can buy the best form plugin for WordPress at %s.', 'gravity-forms-toolbar' ),  
  296. '<em>' . __( 'Gravity Forms Toolbar', 'gravity-forms-toolbar' ) . '</em>',  
  297. '<a href="http://ddwb.me/getgravityforms" target="_new">gravityforms.com</a>',  
  298. '<a href="http://ddwb.me/getgravityforms" target="_new"><strong>Gravity Forms</strong></a>' 
  299. ); 
  300. $gftb_notice .= '<div class="alignright"><small>(' . __( 'This message will only be shown once. Go to any other page/ screen here and it will disappear.', 'gravity-forms-toolbar' ) . ')</small></div><div class="clear"></div>'; 
  301. $gftb_notice .= '</p></div><!-- /.error -->'; 
  302.  
  303. /** Output the user message */ 
  304. echo $gftb_notice; 
  305.  
  306. } // end if 
  307.  
  308. } // end of function 
.