| 1 |
<?php |
| 2 |
/** |
| 3 |
* Post Snippets Help. |
| 4 |
* |
| 5 |
* Class to handle the help texts and tabs on the settings screen. |
| 6 |
* |
| 7 |
* @package Post Snippets |
| 8 |
* @author Johan Steen <artstorm at gmail dot com> |
| 9 |
* @since Post Snippets 1.8.9 |
| 10 |
*/ |
| 11 |
class Post_Snippets_Help |
| 12 |
{ |
| 13 |
/** |
| 14 |
* Constructor. |
| 15 |
* @since Post Snippets 1.8.9 |
| 16 |
* @param string The option page to load the help text on |
| 17 |
*/ |
| 18 |
public function __construct( $option_page ) |
| 19 |
{ |
| 20 |
// If WordPress is 3.3 or higher, use the new Help API, otherwise call |
| 21 |
// the old pre 3.3 help function. |
| 22 |
global $wp_version; |
| 23 |
if ( version_compare($wp_version, '3.3', '>=') ) { |
| 24 |
add_action( 'load-' . $option_page, array(&$this,'add_help_tabs') ); |
| 25 |
} else { |
| 26 |
add_action( 'contextual_help', array(&$this,'add_help'), 10, 3 ); |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Setup the help tabs and sidebar. |
| 32 |
* @since Post Snippets 1.8.9 |
| 33 |
*/ |
| 34 |
public function add_help_tabs() { |
| 35 |
$screen = get_current_screen(); |
| 36 |
$screen->set_help_sidebar( $this->help_sidebar() ); |
| 37 |
$screen->add_help_tab( array( |
| 38 |
'id' => 'additional-plugin-help', // This should be unique for the screen. |
| 39 |
'title' => 'Plugin Usage', |
| 40 |
'content' => $this->contextual_help_wp_pre33() |
| 41 |
// Use 'callback' instead of 'content' for a function callback that renders the tab content. |
| 42 |
) ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* The right sidebar help text. |
| 47 |
* |
| 48 |
* @since Post Snippets 1.8.9 |
| 49 |
* @return string The help text |
| 50 |
*/ |
| 51 |
public function help_sidebar() |
| 52 |
{ |
| 53 |
$content = '<p><strong>'.__('For more information:').'</strong></p>'; |
| 54 |
$content .= '<p><a href="http://wpstorm.net/wordpress-plugins/post-snippets/" target="_blank">'.__('Post Snippets Documentation').'</a></p>'; |
| 55 |
$content .= '<p><a href="http://wordpress.org/tags/post-snippets?forum_id=10" target="_blank">'.__('Support Forums').'</a></p>'; |
| 56 |
return $content; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
// ------------------------------------------------------------------------- |
| 61 |
// Deprecated Methods |
| 62 |
// ------------------------------------------------------------------------- |
| 63 |
|
| 64 |
/** |
| 65 |
* Display contextual help in the help drop down menu at the options page. |
| 66 |
* |
| 67 |
* @deprecated Since WordPress 3.3 |
| 68 |
* @since Post Snippets 1.7.1 |
| 69 |
* @return string The Contextual Help |
| 70 |
*/ |
| 71 |
public function add_help($contextual_help, $screen_id, $screen) { |
| 72 |
if ( $screen->id == 'settings_page_post-snippets/post-snippets' ) { |
| 73 |
$contextual_help = $this->contextual_help_wp_pre33(); |
| 74 |
} |
| 75 |
return $contextual_help; |
| 76 |
} |
| 77 |
|
| 78 |
/** |
| 79 |
* The contextual help text displayed in WordPress older than 3.3. |
| 80 |
* |
| 81 |
* @deprecated Since WordPress 3.3 |
| 82 |
* @since Post Snippets 1.8. |
| 83 |
* @return string The Contextual Help |
| 84 |
*/ |
| 85 |
public function contextual_help_wp_pre33() |
| 86 |
{ |
| 87 |
$contextual_help = |
| 88 |
'<p><strong>' . __('Title', 'post-snippets') . '</strong></p>' . |
| 89 |
'<p>' . __('Give the snippet a title that helps you identify it in the post editor. If you make it into a shortcode, this is the name of the shortcode as well.', 'post-snippets') . '</p>' . |
| 90 |
|
| 91 |
'<p><strong>' . __('Variables', 'post-snippets') . '</strong></p>' . |
| 92 |
'<p>' . __('A comma separated list of custom variables you can reference in your snippet.<br/><br/>Example:<br/>url,name', 'post-snippets') . '</p>' . |
| 93 |
|
| 94 |
'<p><strong>' . __('Snippet', 'post-snippets') . '</strong></p>' . |
| 95 |
'<p>' . __('This is the block of text or HTML to insert in the post when you select the snippet from the insert button in the TinyMCE panel in the post editor. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.<br/><br/>Example:<br/>To reference the variables in the example above, you would enter {url} and {name}.<br/><br/>So if you enter this snippet:<br/><i>This is the website of <a href="{url}">{name}</a></i><br/>You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets') . '</p>' . |
| 96 |
|
| 97 |
'<p><strong>' . __('Description', 'post-snippets') . '</strong></p>' . |
| 98 |
'<p>' . __('An optional description for the Snippet. If entered it will be displayed in the snippets popup window in the post editor.', 'post-snippets') . '</p>' . |
| 99 |
|
| 100 |
'<p><strong>' . __('Shortcode', 'post-snippets') . '</strong></p>' . |
| 101 |
'<p>' . __('Treats the snippet as a shortcode. The name for the shortcode is the same as the title of the snippet (spaces not allowed) and will be used on insert. If you enclose the shortcode in your posts, you can access the enclosed content by using the variable {content} in your snippet. The content variable is reserved, so don\'t use it in the variables field.', 'post-snippets') . '</p>' . |
| 102 |
|
| 103 |
'<p><strong>' . __('Advanced', 'post-snippets') . '</strong></p>' . |
| 104 |
'<p>' . __('The snippets can be retrieved directly from PHP, in a theme for instance, with the get_post_snippet() function. Visit the Post Snippets link under more information for instructions.', 'post-snippets') . '</p>' . |
| 105 |
|
| 106 |
'<p><strong>' . __('For more information:', 'post-snippets') . '</strong></p>' . |
| 107 |
'<p>' . __('Visit my <a href="http://wpstorm.net/wordpress-plugins/post-snippets/">Post Snippets</a> page for additional information.', 'post-snippets') . '</p>'; |
| 108 |
return $contextual_help; |
| 109 |
} |
| 110 |
} |
| 111 |
|