';
echo '
Post Snippets
';
echo '
';
_e('This is an overview of all snippets defined for this site. These snippets are inserted into posts from the post editor using the Post Snippets button. You can choose to see the snippets here as-is or as they are actually rendered on the website. Enabling rendered snippets for this overview might look strange if the snippet have dependencies on variables, CSS or other parameters only available on the frontend. If that is the case it is recommended to keep this option disabled.', 'post-snippets');
echo '
';
// Form
$this->setUserOptions();
$render = $this->getUserOptions();
echo '
';
// Snippet List
$snippets = get_option(\PostSnippets::OPTION_KEY);
if (!empty($snippets)) {
foreach ($snippets as $key => $snippet) {
echo "
";
echo "
{$snippet['title']}";
if ($snippet['description']) {
echo " {$snippet['description']}";
}
echo "
";
if ($snippet['vars']) {
printf("
%s: {$snippet['vars']}
", __('Variables', 'post-snippets'));
}
// echo "
Variables: {$snippet['vars']}
";
$options = array();
if ($snippet['shortcode']) {
array_push($options, 'Shortcode');
}
if ($snippet['php']) {
array_push($options, 'PHP');
}
if ($snippet['wptexturize']) {
array_push($options, 'wptexturize');
}
if ($options) {
printf("
%s: %s
", __('Options', 'post-snippets'), implode(', ', $options));
}
printf("
%s:", __('Snippet', 'post-snippets'));
if ($render) {
echo do_shortcode($snippet['snippet']);
} else {
echo "
";
echo nl2br(htmlspecialchars($snippet['snippet'], ENT_NOQUOTES));
echo "";
}
}
}
// Close
echo '
';
}
// -------------------------------------------------------------------------
// Register and callbacks for the options tab
// -------------------------------------------------------------------------
/**
* Register settings for the options tab.
*
* @return void
*/
protected function registerSettings()
{
$this->settings = get_option(\PostSnippets::SETTINGS);
register_setting(
\PostSnippets::SETTINGS,
\PostSnippets::SETTINGS
);
add_settings_section(
'general_section',
__('General', 'post-snippets'),
null,
'post-snippets'
);
add_settings_field(
'exclude_from_custom_editors',
__('Exclude from Custom Editors', 'post-snippets'),
array($this, 'cbExcludeFromCustomEditors'),
'post-snippets',
'general_section',
array(
'id' => 'exclude_from_custom_editors',
'label_for' => 'exclude_from_custom_editors',
'description' => __('Checking this only includes Post Snippets on standard WordPress post editing screens.', 'post-snippets')
)
);
add_settings_field(
'complete_uninstall',
__('Complete Uninstall', 'post-snippets'),
array($this, 'cbCompleteUninstall'),
'post-snippets',
'general_section',
array(
'id' => 'complete_uninstall',
'label_for' => 'complete_uninstall',
'description' => __('When the plugin is deleted, also delete all snippets and plugin settings.', 'post-snippets')
)
);
add_settings_section(
'duplicate_section',
__('Duplicate Snippets', 'post-snippets'),
null,
'post-snippets'
);
add_settings_field(
'allow_duplicate',
__('Allow Duplicate', 'post-snippets'),
array($this, 'cbAllowDuplicate'),
'post-snippets',
'duplicate_section',
array(
'id' => 'allow_duplicate',
'label_for' => 'allow_duplicate',
'description' => __('Allow duplicate snippets: import all snippets from the file regardless and leave all existing snippets unchanged.', 'post-snippets')
)
);
add_settings_field(
'replace_duplicate',
__('Replace Duplicate', 'post-snippets'),
array($this, 'cbReplaceDuplicate'),
'post-snippets',
'duplicate_section',
array(
'id' => 'replace_duplicate',
'label_for' => 'replace_duplicate',
'description' => __('Replace any existing snippets with a newly imported snippet of the same name.', 'post-snippets')
)
);
add_settings_field(
'skip_duplicate',
__('Do not Import Duplicate', 'post-snippets'),
array($this, 'cbSkipDuplicate'),
'post-snippets',
'duplicate_section',
array(
'id' => 'skip_duplicate',
'label_for' => 'skip_duplicate',
'description' => __('Do not import any duplicate snippets; leave all existing snippets unchanged.', 'post-snippets')
)
);
}
/**
* Callback for HTML generator for exlusion of custom editors.
*
* @param array $args
*
* @return void
*/
public function cbExcludeFromCustomEditors($args)
{
$checked = isset($this->settings[$args['id']]) ?
$this->settings[$args['id']] :
false;
echo "