Version Description
Download this release
Release Info
Developer | artstorm |
Plugin | Post Snippets |
Version | 2.5 |
Comparing to | |
See all releases |
Code changes from version 2.4 to 2.5
- post-snippets.php +4 -2
- readme.txt +7 -1
- src/PostSnippets/Admin.php +135 -39
- src/PostSnippets/WPEditor.php +17 -1
- views/admin_options.php +7 -0
post-snippets.php
CHANGED
@@ -5,12 +5,12 @@ Plugin URI: https://johansteen.se/code/post-snippets/
|
|
5 |
Description: Build a library with snippets of HTML, PHP code or reoccurring text that you often use in your posts. Variables to replace parts of the snippet on insert can be used. The snippets can be inserted as-is or as shortcodes.
|
6 |
Author: Johan Steen
|
7 |
Author URI: https://johansteen.se/
|
8 |
-
Version: 2.
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: post-snippets
|
11 |
Domain Path: /lang
|
12 |
|
13 |
-
Copyright 2009-
|
14 |
|
15 |
This program is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
@@ -44,6 +44,7 @@ class PostSnippets
|
|
44 |
/** Define plugin constants */
|
45 |
const MIN_PHP_VERSION = '5.3.0';
|
46 |
const MIN_WP_VERSION = '3.3';
|
|
|
47 |
const OPTION_KEY = 'post_snippets_options';
|
48 |
const USER_META_KEY = 'post_snippets';
|
49 |
const FILE = __FILE__;
|
@@ -73,6 +74,7 @@ class PostSnippets
|
|
73 |
false,
|
74 |
dirname(plugin_basename(__FILE__)).'/lang/'
|
75 |
);
|
|
|
76 |
register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
|
77 |
add_action('after_setup_theme', array(&$this, 'phpExecState'));
|
78 |
|
5 |
Description: Build a library with snippets of HTML, PHP code or reoccurring text that you often use in your posts. Variables to replace parts of the snippet on insert can be used. The snippets can be inserted as-is or as shortcodes.
|
6 |
Author: Johan Steen
|
7 |
Author URI: https://johansteen.se/
|
8 |
+
Version: 2.5
|
9 |
License: GPLv2 or later
|
10 |
Text Domain: post-snippets
|
11 |
Domain Path: /lang
|
12 |
|
13 |
+
Copyright 2009-2016 Johan Steen (email : artstorm [at] gmail [dot] com)
|
14 |
|
15 |
This program is free software; you can redistribute it and/or modify
|
16 |
it under the terms of the GNU General Public License as published by
|
44 |
/** Define plugin constants */
|
45 |
const MIN_PHP_VERSION = '5.3.0';
|
46 |
const MIN_WP_VERSION = '3.3';
|
47 |
+
const SETTINGS = 'post_snippets';
|
48 |
const OPTION_KEY = 'post_snippets_options';
|
49 |
const USER_META_KEY = 'post_snippets';
|
50 |
const FILE = __FILE__;
|
74 |
false,
|
75 |
dirname(plugin_basename(__FILE__)).'/lang/'
|
76 |
);
|
77 |
+
|
78 |
register_uninstall_hook(__FILE__, array(__CLASS__, 'uninstall'));
|
79 |
add_action('after_setup_theme', array(&$this, 'phpExecState'));
|
80 |
|
readme.txt
CHANGED
@@ -4,7 +4,7 @@ Donate link: https://johansteen.se/donate/
|
|
4 |
Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.4
|
7 |
-
Stable tag: 2.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -128,6 +128,12 @@ Contributions are appreciated and encouraged.
|
|
128 |
|
129 |
== Changelog ==
|
130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
= Version 2.4 - 18 Dec 2015 =
|
132 |
* Fixes potential conflict with WP Editor on none post screens.
|
133 |
* Removes notice message on some screens if WordPress debug mode is enabled.
|
4 |
Tags: post, admin, snippet, shortcode, html, custom, page, dynamic, editor, php, code
|
5 |
Requires at least: 3.3
|
6 |
Tested up to: 4.4
|
7 |
+
Stable tag: 2.5
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
128 |
|
129 |
== Changelog ==
|
130 |
|
131 |
+
= Version 2.5 - 21 Jan 2016 =
|
132 |
+
* Implements an options tab to handle plugin settings.
|
133 |
+
* Reverts the change implemented in version 2.3.9 to exclude post snippets from
|
134 |
+
custom editors by default, and instead adds it as an optional setting.
|
135 |
+
* Fixes a conflict with plugins that adds custom editors on the frontend.
|
136 |
+
|
137 |
= Version 2.4 - 18 Dec 2015 =
|
138 |
* Fixes potential conflict with WP Editor on none post screens.
|
139 |
* Removes notice message on some screens if WordPress debug mode is enabled.
|
src/PostSnippets/Admin.php
CHANGED
@@ -10,12 +10,22 @@
|
|
10 |
*/
|
11 |
class PostSnippets_Admin
|
12 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
public function __construct()
|
14 |
{
|
15 |
-
add_filter('plugin_action_links', array(&$this, 'actionLinks'), 10, 2);
|
16 |
-
add_action('admin_init', array(&$this, 'init'));
|
17 |
add_action('admin_menu', array(&$this, 'menu'));
|
|
|
18 |
add_action('current_screen', array(&$this, 'addHeaderXss'));
|
|
|
19 |
}
|
20 |
|
21 |
|
@@ -23,41 +33,6 @@ class PostSnippets_Admin
|
|
23 |
// Setup
|
24 |
// -------------------------------------------------------------------------
|
25 |
|
26 |
-
/**
|
27 |
-
* Quick link to the Post Snippets Settings page from the Plugins page.
|
28 |
-
*
|
29 |
-
* @param array Array of all plugin links
|
30 |
-
* @param string The current plugin file we're filtering.
|
31 |
-
* @return Array with all the plugin's action links
|
32 |
-
*/
|
33 |
-
public function actionLinks($links, $file)
|
34 |
-
{
|
35 |
-
$pluginFile = plugin_basename(dirname(PostSnippets::FILE));
|
36 |
-
$pluginFile .= '/post-snippets.php';
|
37 |
-
|
38 |
-
if ($file == $pluginFile) {
|
39 |
-
$url = 'options-general.php?page=post-snippets/post-snippets.php';
|
40 |
-
$link = "<a href='{$url}'>";
|
41 |
-
$link .= __('Settings', 'post-snippets').'</a>';
|
42 |
-
$links[] = $link;
|
43 |
-
}
|
44 |
-
return $links;
|
45 |
-
}
|
46 |
-
|
47 |
-
/**
|
48 |
-
* Initialize assets for the administration page.
|
49 |
-
*
|
50 |
-
* @return void
|
51 |
-
*/
|
52 |
-
public function init()
|
53 |
-
{
|
54 |
-
wp_register_script(
|
55 |
-
'post-snippets',
|
56 |
-
plugins_url('/assets/post-snippets.js', PostSnippets::FILE),
|
57 |
-
array('jquery')
|
58 |
-
);
|
59 |
-
}
|
60 |
-
|
61 |
/**
|
62 |
* Register the administration page.
|
63 |
*
|
@@ -98,6 +73,22 @@ class PostSnippets_Admin
|
|
98 |
);
|
99 |
}
|
100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
/**
|
102 |
* Enqueue scripts to be loaded.
|
103 |
*
|
@@ -122,6 +113,27 @@ class PostSnippets_Admin
|
|
122 |
}
|
123 |
}
|
124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
// -------------------------------------------------------------------------
|
127 |
// Handle form submissions
|
@@ -308,7 +320,11 @@ class PostSnippets_Admin
|
|
308 |
// Tabs
|
309 |
$active_tab = isset($_GET[ 'tab' ]) ? $_GET[ 'tab' ] : 'snippets';
|
310 |
$base_url = '?page=post-snippets/post-snippets.php&tab=';
|
311 |
-
$tabs = array(
|
|
|
|
|
|
|
|
|
312 |
echo '<h2 class="nav-tab-wrapper">';
|
313 |
foreach ($tabs as $tab => $title) {
|
314 |
$active = ($active_tab == $tab) ? ' nav-tab-active' : '';
|
@@ -322,6 +338,8 @@ class PostSnippets_Admin
|
|
322 |
// Tab content
|
323 |
if ($active_tab == 'snippets') {
|
324 |
$this->tabSnippets();
|
|
|
|
|
325 |
} else {
|
326 |
$this->tabTools();
|
327 |
}
|
@@ -341,6 +359,17 @@ class PostSnippets_Admin
|
|
341 |
echo PostSnippets_View::render('admin_snippets', $data);
|
342 |
}
|
343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
344 |
/**
|
345 |
* Tab for Import/Export
|
346 |
*
|
@@ -442,7 +471,70 @@ class PostSnippets_Admin
|
|
442 |
|
443 |
|
444 |
// -------------------------------------------------------------------------
|
445 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
446 |
// -------------------------------------------------------------------------
|
447 |
|
448 |
/**
|
@@ -453,6 +545,8 @@ class PostSnippets_Admin
|
|
453 |
* @param string $label The label rendered to screen
|
454 |
* @param string $name The unique name and id to identify the input
|
455 |
* @param boolean $checked If the input is checked or not
|
|
|
|
|
456 |
*/
|
457 |
public static function checkbox($label, $name, $checked)
|
458 |
{
|
@@ -475,6 +569,8 @@ class PostSnippets_Admin
|
|
475 |
* @param string $label The label rendered on the button
|
476 |
* @param string $class Optional. Button class. Default: button-primary
|
477 |
* @param boolean $wrap Optional. Wrap in a submit div. Default: true
|
|
|
|
|
478 |
*/
|
479 |
public static function submit($name, $label, $class = 'button-primary', $wrap = true)
|
480 |
{
|
10 |
*/
|
11 |
class PostSnippets_Admin
|
12 |
{
|
13 |
+
/**
|
14 |
+
* Plugin settings.
|
15 |
+
*
|
16 |
+
* @var array
|
17 |
+
*/
|
18 |
+
protected $settings;
|
19 |
+
|
20 |
+
/**
|
21 |
+
* Defines hooks and filters for admin page.
|
22 |
+
*/
|
23 |
public function __construct()
|
24 |
{
|
|
|
|
|
25 |
add_action('admin_menu', array(&$this, 'menu'));
|
26 |
+
add_action('admin_init', array(&$this, 'init'));
|
27 |
add_action('current_screen', array(&$this, 'addHeaderXss'));
|
28 |
+
add_filter('plugin_action_links', array(&$this, 'actionLinks'), 10, 2);
|
29 |
}
|
30 |
|
31 |
|
33 |
// Setup
|
34 |
// -------------------------------------------------------------------------
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
/**
|
37 |
* Register the administration page.
|
38 |
*
|
73 |
);
|
74 |
}
|
75 |
|
76 |
+
/**
|
77 |
+
* Initialize assets for the administration page.
|
78 |
+
*
|
79 |
+
* @return void
|
80 |
+
*/
|
81 |
+
public function init()
|
82 |
+
{
|
83 |
+
wp_register_script(
|
84 |
+
'post-snippets',
|
85 |
+
plugins_url('/assets/post-snippets.js', PostSnippets::FILE),
|
86 |
+
array('jquery')
|
87 |
+
);
|
88 |
+
|
89 |
+
$this->registerSettings();
|
90 |
+
}
|
91 |
+
|
92 |
/**
|
93 |
* Enqueue scripts to be loaded.
|
94 |
*
|
113 |
}
|
114 |
}
|
115 |
|
116 |
+
/**
|
117 |
+
* Quick link to the Post Snippets Settings page from the Plugins page.
|
118 |
+
*
|
119 |
+
* @param array Array of all plugin links
|
120 |
+
* @param string The current plugin file we're filtering.
|
121 |
+
* @return Array with all the plugin's action links
|
122 |
+
*/
|
123 |
+
public function actionLinks($links, $file)
|
124 |
+
{
|
125 |
+
$pluginFile = plugin_basename(dirname(PostSnippets::FILE));
|
126 |
+
$pluginFile .= '/post-snippets.php';
|
127 |
+
|
128 |
+
if ($file == $pluginFile) {
|
129 |
+
$url = 'options-general.php?page=post-snippets/post-snippets.php';
|
130 |
+
$link = "<a href='{$url}'>";
|
131 |
+
$link .= __('Settings', 'post-snippets').'</a>';
|
132 |
+
$links[] = $link;
|
133 |
+
}
|
134 |
+
return $links;
|
135 |
+
}
|
136 |
+
|
137 |
|
138 |
// -------------------------------------------------------------------------
|
139 |
// Handle form submissions
|
320 |
// Tabs
|
321 |
$active_tab = isset($_GET[ 'tab' ]) ? $_GET[ 'tab' ] : 'snippets';
|
322 |
$base_url = '?page=post-snippets/post-snippets.php&tab=';
|
323 |
+
$tabs = array(
|
324 |
+
'snippets' => __('Manage Snippets', 'post-snippets'),
|
325 |
+
'options' => __('Options', 'post-snippets'),
|
326 |
+
'tools' => __('Import/Export', 'post-snippets')
|
327 |
+
);
|
328 |
echo '<h2 class="nav-tab-wrapper">';
|
329 |
foreach ($tabs as $tab => $title) {
|
330 |
$active = ($active_tab == $tab) ? ' nav-tab-active' : '';
|
338 |
// Tab content
|
339 |
if ($active_tab == 'snippets') {
|
340 |
$this->tabSnippets();
|
341 |
+
} elseif ($active_tab == 'options') {
|
342 |
+
$this->tabOptions();
|
343 |
} else {
|
344 |
$this->tabTools();
|
345 |
}
|
359 |
echo PostSnippets_View::render('admin_snippets', $data);
|
360 |
}
|
361 |
|
362 |
+
/**
|
363 |
+
* Tab to set options for the plugin.
|
364 |
+
*
|
365 |
+
* @return void
|
366 |
+
*/
|
367 |
+
private function tabOptions()
|
368 |
+
{
|
369 |
+
$data = array();
|
370 |
+
echo PostSnippets_View::render('admin_options', $data);
|
371 |
+
}
|
372 |
+
|
373 |
/**
|
374 |
* Tab for Import/Export
|
375 |
*
|
471 |
|
472 |
|
473 |
// -------------------------------------------------------------------------
|
474 |
+
// Register and callbacks for the options tab
|
475 |
+
// -------------------------------------------------------------------------
|
476 |
+
|
477 |
+
/**
|
478 |
+
* Register settings for the options tab.
|
479 |
+
*
|
480 |
+
* @return void
|
481 |
+
*/
|
482 |
+
protected function registerSettings()
|
483 |
+
{
|
484 |
+
$this->settings = get_option(PostSnippets::SETTINGS);
|
485 |
+
|
486 |
+
register_setting(
|
487 |
+
PostSnippets::SETTINGS,
|
488 |
+
PostSnippets::SETTINGS
|
489 |
+
);
|
490 |
+
|
491 |
+
add_settings_section(
|
492 |
+
'general_section',
|
493 |
+
__('General', 'post-snippets'),
|
494 |
+
null,
|
495 |
+
'post-snippets'
|
496 |
+
);
|
497 |
+
|
498 |
+
add_settings_field(
|
499 |
+
'exclude_from_custom_editors',
|
500 |
+
'Exclude from Custom Editors',
|
501 |
+
array($this, 'cbExcludeFromCustomEditors'),
|
502 |
+
'post-snippets',
|
503 |
+
'general_section',
|
504 |
+
array(
|
505 |
+
'id' => 'exclude_from_custom_editors',
|
506 |
+
'label_for' => 'exclude_from_custom_editors',
|
507 |
+
'description' => __('Checking this only includes Post Snippets on standard WordPress post editing screens.')
|
508 |
+
)
|
509 |
+
);
|
510 |
+
}
|
511 |
+
|
512 |
+
/**
|
513 |
+
* Callback for HTML generator for exlusion of custom editors.
|
514 |
+
*
|
515 |
+
* @param array $args
|
516 |
+
*
|
517 |
+
* @return void
|
518 |
+
*/
|
519 |
+
public function cbExcludeFromCustomEditors($args)
|
520 |
+
{
|
521 |
+
$checked = isset($this->settings[$args['id']]) ?
|
522 |
+
$this->settings[$args['id']] :
|
523 |
+
false;
|
524 |
+
|
525 |
+
echo "<input type='checkbox' id='{$args['id']}' ";
|
526 |
+
echo "name='".PostSnippets::SETTINGS."[{$args['id']}]' value='1' ";
|
527 |
+
if ($checked) {
|
528 |
+
echo 'checked ';
|
529 |
+
}
|
530 |
+
echo " />";
|
531 |
+
|
532 |
+
echo "<span class='description'>{$args['description']}</span>";
|
533 |
+
}
|
534 |
+
|
535 |
+
|
536 |
+
// -------------------------------------------------------------------------
|
537 |
+
// HTML and Form element methods for Snippets form
|
538 |
// -------------------------------------------------------------------------
|
539 |
|
540 |
/**
|
545 |
* @param string $label The label rendered to screen
|
546 |
* @param string $name The unique name and id to identify the input
|
547 |
* @param boolean $checked If the input is checked or not
|
548 |
+
*
|
549 |
+
* @return void
|
550 |
*/
|
551 |
public static function checkbox($label, $name, $checked)
|
552 |
{
|
569 |
* @param string $label The label rendered on the button
|
570 |
* @param string $class Optional. Button class. Default: button-primary
|
571 |
* @param boolean $wrap Optional. Wrap in a submit div. Default: true
|
572 |
+
*
|
573 |
+
* @return void
|
574 |
*/
|
575 |
public static function submit($name, $label, $class = 'button-primary', $wrap = true)
|
576 |
{
|
src/PostSnippets/WPEditor.php
CHANGED
@@ -344,7 +344,23 @@ class PostSnippets_WPEditor
|
|
344 |
*/
|
345 |
protected function isEditingPost()
|
346 |
{
|
347 |
-
$
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
348 |
|
349 |
return is_object($screen) ? $screen->base == 'post' : false;
|
350 |
}
|
344 |
*/
|
345 |
protected function isEditingPost()
|
346 |
{
|
347 |
+
$settings = get_option(PostSnippets::SETTINGS);
|
348 |
+
$exclude = isset($settings['exclude_from_custom_editors']) ?
|
349 |
+
$settings['exclude_from_custom_editors'] :
|
350 |
+
false;
|
351 |
+
|
352 |
+
// If we are not excluding from custom editors, always return true.
|
353 |
+
if (!$exclude) {
|
354 |
+
return true;
|
355 |
+
}
|
356 |
+
|
357 |
+
// If get_current_screen doesn't exist, we're on the frontend,
|
358 |
+
// so return false, as it's then definately a custom editor
|
359 |
+
if (function_exists('get_current_screen')) {
|
360 |
+
$screen = get_current_screen();
|
361 |
+
} else {
|
362 |
+
$screen = false;
|
363 |
+
}
|
364 |
|
365 |
return is_object($screen) ? $screen->base == 'post' : false;
|
366 |
}
|
views/admin_options.php
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<form method="post" action="options.php">
|
2 |
+
<?php
|
3 |
+
settings_fields(PostSnippets::SETTINGS);
|
4 |
+
do_settings_sections('post-snippets');
|
5 |
+
submit_button();
|
6 |
+
?>
|
7 |
+
</form>
|