Version Description
Download this release
Release Info
Developer | wpexpertsio |
Plugin | Post Snippets |
Version | 3.1.4 |
Comparing to | |
See all releases |
Code changes from version 3.1.3 to 3.1.4
- post-snippets.php +278 -284
- readme.txt +6 -2
- src/PostSnippets/Admin.php +1086 -1072
- src/PostSnippets/Features.php +5 -6
- src/PostSnippets/Help.php +96 -101
- src/PostSnippets/ImportExport.php +248 -220
- src/PostSnippets/Shortcode.php +80 -84
- src/PostSnippets/View.php +18 -20
- src/PostSnippets/WPEditor.php +285 -296
- src/init.php +5 -5
- views/admin_news.php +23 -23
- views/admin_notice_get_started.php +12 -12
- views/admin_notice_newsletter.php +14 -14
- views/admin_options.php +3 -3
- views/admin_snippets.php +300 -309
- views/help/advanced.php +9 -9
- views/help/filters.php +10 -10
- views/help/php.php +6 -6
- views/help/post.php +5 -5
- views/help/sidebar.php +16 -10
- views/help/usage.php +22 -22
- views/jquery_ui_dialog_footer.php +92 -78
- views/jquery_ui_dialog_head.php +104 -92
post-snippets.php
CHANGED
@@ -3,302 +3,296 @@
|
|
3 |
/**
|
4 |
* Post Snippets
|
5 |
*
|
6 |
-
* @package
|
7 |
-
* @author
|
8 |
-
* @license
|
9 |
-
* @link
|
10 |
*
|
11 |
* @wordpress-plugin
|
12 |
* Plugin Name: Post Snippets
|
13 |
* Plugin URI: https://www.postsnippets.com
|
14 |
* Description: Create a library of reusable content and insert it into your posts and pages. Navigate to "Settings > Post Snippets" to get started.
|
15 |
-
* Version: 3.1.
|
16 |
* Author: Postsnippets
|
17 |
* Author URI: https://www.postsnippets.com
|
18 |
* License: GPL-2.0+
|
19 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
20 |
* Text Domain: post-snippets
|
21 |
* Domain Path: /lang
|
22 |
-
*
|
23 |
*/
|
24 |
|
25 |
-
if ( !function_exists( 'postsnippets_fs' ) ) {
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
const SETTINGS = 'post_snippets' ;
|
119 |
-
const OPTION_KEY = 'post_snippets_options' ;
|
120 |
-
const USER_META_KEY = 'post_snippets' ;
|
121 |
-
const FILE = __FILE__ ;
|
122 |
-
/**
|
123 |
-
* Singleton class
|
124 |
-
*/
|
125 |
-
public static function getInstance()
|
126 |
-
{
|
127 |
-
if ( !self::$instance ) {
|
128 |
-
self::$instance = new self();
|
129 |
-
}
|
130 |
-
return self::$instance;
|
131 |
-
}
|
132 |
-
|
133 |
-
/**
|
134 |
-
* Initializes the plugin.
|
135 |
-
*/
|
136 |
-
private function __construct()
|
137 |
-
{
|
138 |
-
if ( !$this->testHost() ) {
|
139 |
-
return;
|
140 |
-
}
|
141 |
-
load_plugin_textdomain( 'post-snippets', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
142 |
-
add_action( 'after_setup_theme', array( &$this, 'phpExecState' ) );
|
143 |
-
new \PostSnippets\Admin();
|
144 |
-
new \PostSnippets\WPEditor();
|
145 |
-
new \PostSnippets\Shortcode();
|
146 |
-
}
|
147 |
-
|
148 |
-
/**
|
149 |
-
* PSR-0 compliant autoloader to load classes as needed.
|
150 |
-
*
|
151 |
-
* @param string $classname
|
152 |
-
*
|
153 |
-
* @return void
|
154 |
-
*/
|
155 |
-
public static function autoload( $className )
|
156 |
-
{
|
157 |
-
if ( __CLASS__ !== mb_substr( $className, 0, strlen( __CLASS__ ) ) ) {
|
158 |
-
return;
|
159 |
-
}
|
160 |
-
$className = ltrim( $className, '\\' );
|
161 |
-
$fileName = '';
|
162 |
-
$namespace = '';
|
163 |
-
|
164 |
-
if ( $lastNsPos = strrpos( $className, '\\' ) ) {
|
165 |
-
$namespace = substr( $className, 0, $lastNsPos );
|
166 |
-
$className = substr( $className, $lastNsPos + 1 );
|
167 |
-
$fileName = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace );
|
168 |
-
$fileName .= DIRECTORY_SEPARATOR;
|
169 |
-
}
|
170 |
-
|
171 |
-
$fileName .= str_replace( '_', DIRECTORY_SEPARATOR, $className );
|
172 |
-
require 'src' . DIRECTORY_SEPARATOR . $fileName . '.php';
|
173 |
-
}
|
174 |
-
|
175 |
-
// -------------------------------------------------------------------------
|
176 |
-
// Helpers
|
177 |
-
// -------------------------------------------------------------------------
|
178 |
-
/**
|
179 |
-
* Allow snippets to be retrieved directly from PHP.
|
180 |
-
*
|
181 |
-
* @since Post Snippets 1.8.9.1
|
182 |
-
*
|
183 |
-
* @param string $name The name of the snippet to retrieve
|
184 |
-
* @param string|array $variables The variables to pass to the snippet,
|
185 |
-
* formatted as a query string or an associative array.
|
186 |
-
*
|
187 |
-
* @return string The Snippet
|
188 |
-
*/
|
189 |
-
public static function getSnippet( $name, $variables = '' )
|
190 |
-
{
|
191 |
-
$snippets = get_option( self::OPTION_KEY, array() );
|
192 |
-
for ( $i = 0 ; $i < count( $snippets ) ; $i++ ) {
|
193 |
-
|
194 |
-
if ( $snippets[$i]['title'] == $name ) {
|
195 |
-
if ( !is_array( $variables ) ) {
|
196 |
-
parse_str( htmlspecialchars_decode( $variables ), $variables );
|
197 |
-
}
|
198 |
-
$snippet = $snippets[$i]['snippet'];
|
199 |
-
$var_arr = explode( ",", $snippets[$i]['vars'] );
|
200 |
-
if ( !empty($var_arr[0]) ) {
|
201 |
-
for ( $j = 0 ; $j < count( $var_arr ) ; $j++ ) {
|
202 |
-
$snippet = str_replace( "{" . $var_arr[$j] . "}", $variables[$var_arr[$j]], $snippet );
|
203 |
-
}
|
204 |
-
}
|
205 |
-
break;
|
206 |
-
}
|
207 |
-
|
208 |
-
}
|
209 |
-
return do_shortcode( $snippet );
|
210 |
-
}
|
211 |
-
|
212 |
-
// -------------------------------------------------------------------------
|
213 |
-
// Environment Checks
|
214 |
-
// -------------------------------------------------------------------------
|
215 |
-
/**
|
216 |
-
* Checks PHP and WordPress versions.
|
217 |
-
*/
|
218 |
-
private function testHost()
|
219 |
-
{
|
220 |
-
// Check if PHP is too old
|
221 |
-
|
222 |
-
if ( version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '<' ) ) {
|
223 |
-
// Display notice
|
224 |
-
add_action( 'admin_notices', array( &$this, 'phpVersionError' ) );
|
225 |
-
return false;
|
226 |
-
}
|
227 |
-
|
228 |
-
// Check if WordPress is too old
|
229 |
-
global $wp_version ;
|
230 |
-
|
231 |
-
if ( version_compare( $wp_version, self::MIN_WP_VERSION, '<' ) ) {
|
232 |
-
add_action( 'admin_notices', array( &$this, 'wpVersionError' ) );
|
233 |
-
return false;
|
234 |
-
}
|
235 |
-
|
236 |
-
return true;
|
237 |
-
}
|
238 |
-
|
239 |
-
/**
|
240 |
-
* Displays a warning when installed on an old PHP version.
|
241 |
-
*/
|
242 |
-
public function phpVersionError()
|
243 |
-
{
|
244 |
-
echo '<div class="error"><p><strong>' ;
|
245 |
-
printf(
|
246 |
-
'Error: %3$s requires PHP version %1$s or greater.<br/>' . 'Your installed PHP version: %2$s',
|
247 |
-
self::MIN_PHP_VERSION,
|
248 |
-
PHP_VERSION,
|
249 |
-
$this->getPluginName()
|
250 |
-
);
|
251 |
-
echo '</strong></p></div>' ;
|
252 |
-
}
|
253 |
-
|
254 |
-
/**
|
255 |
-
* Displays a warning when installed in an old WordPress version.
|
256 |
-
*/
|
257 |
-
public function wpVersionError()
|
258 |
-
{
|
259 |
-
echo '<div class="error"><p><strong>' ;
|
260 |
-
printf( 'Error: %2$s requires WordPress version %1$s or greater.', self::MIN_WP_VERSION, $this->getPluginName() );
|
261 |
-
echo '</strong></p></div>' ;
|
262 |
-
}
|
263 |
-
|
264 |
-
/**
|
265 |
-
* Get the name of this plugin.
|
266 |
-
*
|
267 |
-
* @return string The plugin name.
|
268 |
-
*/
|
269 |
-
private function getPluginName()
|
270 |
-
{
|
271 |
-
$data = get_plugin_data( self::FILE );
|
272 |
-
return $data['Name'];
|
273 |
-
}
|
274 |
-
|
275 |
-
// -------------------------------------------------------------------------
|
276 |
-
// Deprecated methods
|
277 |
-
// -------------------------------------------------------------------------
|
278 |
-
/**
|
279 |
-
* Allow plugins to disable the PHP Code execution feature with a filter.
|
280 |
-
* Deprecated: Use the POST_SNIPPETS_DISABLE_PHP global constant to disable
|
281 |
-
* PHP instead.
|
282 |
-
*
|
283 |
-
* @see http://wordpress.org/extend/plugins/post-snippets/faq/
|
284 |
-
* @since 2.1
|
285 |
-
* @deprecated 2.3
|
286 |
*/
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
}
|
3 |
/**
|
4 |
* Post Snippets
|
5 |
*
|
6 |
+
* @package PS
|
7 |
+
* @author Postsnippets <support@wpexperts.io>
|
8 |
+
* @license GPL-2.0+
|
9 |
+
* @link https://www.postsnippets.com
|
10 |
*
|
11 |
* @wordpress-plugin
|
12 |
* Plugin Name: Post Snippets
|
13 |
* Plugin URI: https://www.postsnippets.com
|
14 |
* Description: Create a library of reusable content and insert it into your posts and pages. Navigate to "Settings > Post Snippets" to get started.
|
15 |
+
* Version: 3.1.4
|
16 |
* Author: Postsnippets
|
17 |
* Author URI: https://www.postsnippets.com
|
18 |
* License: GPL-2.0+
|
19 |
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
|
20 |
* Text Domain: post-snippets
|
21 |
* Domain Path: /lang
|
|
|
22 |
*/
|
23 |
|
24 |
+
if ( ! function_exists( 'postsnippets_fs' ) ) {
|
25 |
+
// Create a helper function for easy SDK access.
|
26 |
+
function postsnippets_fs() {
|
27 |
+
global $postsnippets_fs;
|
28 |
+
|
29 |
+
if ( ! isset( $postsnippets_fs ) ) {
|
30 |
+
// Include Freemius SDK.
|
31 |
+
include_once dirname( __FILE__ ) . '/freemius/start.php';
|
32 |
+
$postsnippets_fs = fs_dynamic_init(
|
33 |
+
array(
|
34 |
+
'id' => '1576',
|
35 |
+
'slug' => 'post-snippets',
|
36 |
+
'type' => 'plugin',
|
37 |
+
'public_key' => 'pk_58a2ec84c44485a459aae07bfaf5f',
|
38 |
+
'is_premium' => false,
|
39 |
+
'has_addons' => false,
|
40 |
+
'has_paid_plans' => true,
|
41 |
+
'trial' => array(
|
42 |
+
'days' => 14,
|
43 |
+
'is_require_payment' => true,
|
44 |
+
),
|
45 |
+
'menu' => array(
|
46 |
+
'slug' => 'post-snippets',
|
47 |
+
'contact' => false,
|
48 |
+
'support' => false,
|
49 |
+
),
|
50 |
+
'is_live' => true,
|
51 |
+
)
|
52 |
+
);
|
53 |
+
}
|
54 |
+
|
55 |
+
return $postsnippets_fs;
|
56 |
+
}
|
57 |
+
|
58 |
+
// Init Freemius.
|
59 |
+
postsnippets_fs();
|
60 |
+
// Signal that SDK was initiated.
|
61 |
+
do_action( 'postsnippets_fs_loaded' );
|
62 |
+
function postsnippets_fs_settings_url() {
|
63 |
+
return admin_url( 'admin.php?page=post-snippets' );
|
64 |
+
}
|
65 |
+
|
66 |
+
// postsnippets_fs()->add_filter( 'connect_url', 'postsnippets_fs_settings_url' );
|
67 |
+
// postsnippets_fs()->add_filter( 'after_skip_url', 'postsnippets_fs_settings_url' );
|
68 |
+
// postsnippets_fs()->add_filter( 'after_connect_url', 'postsnippets_fs_settings_url' );
|
69 |
+
// postsnippets_fs()->add_filter( 'after_pending_connect_url', 'postsnippets_fs_settings_url' );
|
70 |
+
/**
|
71 |
+
* Only show Post Snippets submenu when PS is open, not on all Settings pages
|
72 |
+
*/
|
73 |
+
function postsnippets_show_submenu( $is_visible ) {
|
74 |
+
if ( isset( $_REQUEST['page'] ) ) {
|
75 |
+
if ( $is_visible && false !== strpos( sanitize_key( $_REQUEST['page'] ), 'post-snippets' ) ) {
|
76 |
+
return true;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
return false;
|
80 |
+
}
|
81 |
+
|
82 |
+
postsnippets_fs()->add_filter(
|
83 |
+
'is_submenu_visible',
|
84 |
+
'postsnippets_show_submenu',
|
85 |
+
10,
|
86 |
+
2
|
87 |
+
);
|
88 |
+
if ( ! defined( 'PS_MAIN_FILE' ) ) {
|
89 |
+
define( 'PS_MAIN_FILE', basename( __FILE__ ) );
|
90 |
+
}
|
91 |
+
if ( ! defined( 'PS_VERSION' ) ) {
|
92 |
+
define( 'PS_VERSION', '3.1.4' );
|
93 |
+
}
|
94 |
+
if ( ! defined( 'PS_MAIN_FILE_PATH' ) ) {
|
95 |
+
define( 'PS_MAIN_FILE_PATH', __FILE__ );
|
96 |
+
}
|
97 |
+
if ( ! defined( 'PS_DIRECTORY' ) ) {
|
98 |
+
define( 'PS_DIRECTORY', plugin_basename( dirname( __FILE__ ) ) );
|
99 |
+
}
|
100 |
+
if ( ! defined( 'PS_PATH' ) ) {
|
101 |
+
define( 'PS_PATH', plugin_dir_path( __FILE__ ) );
|
102 |
+
}
|
103 |
+
if ( ! defined( 'PS_URL' ) ) {
|
104 |
+
define( 'PS_URL', plugins_url( '', __FILE__ ) . '/' );
|
105 |
+
}
|
106 |
+
if ( ! defined( 'PS_MAIN_PAGE_URL' ) ) {
|
107 |
+
define( 'PS_MAIN_PAGE_URL', esc_url( admin_url( 'admin.php?page=post-snippets' ) ) );
|
108 |
+
}
|
109 |
+
class PostSnippets {
|
110 |
+
|
111 |
+
/**
|
112 |
+
* Holds the plugin instance
|
113 |
+
*/
|
114 |
+
private static $instance = false;
|
115 |
+
/**
|
116 |
+
* Define plugin constants
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
*/
|
118 |
+
const MIN_PHP_VERSION = '5.3.0';
|
119 |
+
const MIN_WP_VERSION = '3.3';
|
120 |
+
const SETTINGS = 'post_snippets';
|
121 |
+
const OPTION_KEY = 'post_snippets_options';
|
122 |
+
const USER_META_KEY = 'post_snippets';
|
123 |
+
const FILE = __FILE__;
|
124 |
+
/**
|
125 |
+
* Singleton class
|
126 |
+
*/
|
127 |
+
public static function getInstance() {
|
128 |
+
if ( ! self::$instance ) {
|
129 |
+
self::$instance = new self();
|
130 |
+
}
|
131 |
+
return self::$instance;
|
132 |
+
}
|
133 |
+
|
134 |
+
/**
|
135 |
+
* Initializes the plugin.
|
136 |
+
*/
|
137 |
+
private function __construct() {
|
138 |
+
if ( ! $this->testHost() ) {
|
139 |
+
return;
|
140 |
+
}
|
141 |
+
load_plugin_textdomain( 'post-snippets', false, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
|
142 |
+
add_action( 'after_setup_theme', array( &$this, 'phpExecState' ) );
|
143 |
+
new \PostSnippets\Admin();
|
144 |
+
new \PostSnippets\WPEditor();
|
145 |
+
new \PostSnippets\Shortcode();
|
146 |
+
}
|
147 |
+
|
148 |
+
/**
|
149 |
+
* PSR-0 compliant autoloader to load classes as needed.
|
150 |
+
*
|
151 |
+
* @param string $classname
|
152 |
+
*
|
153 |
+
* @return void
|
154 |
+
*/
|
155 |
+
public static function autoload( $className ) {
|
156 |
+
if ( __CLASS__ !== mb_substr( $className, 0, strlen( __CLASS__ ) ) ) {
|
157 |
+
return;
|
158 |
+
}
|
159 |
+
$className = ltrim( $className, '\\' );
|
160 |
+
$fileName = '';
|
161 |
+
$namespace = '';
|
162 |
+
|
163 |
+
if ( $lastNsPos = strrpos( $className, '\\' ) ) {
|
164 |
+
$namespace = substr( $className, 0, $lastNsPos );
|
165 |
+
$className = substr( $className, $lastNsPos + 1 );
|
166 |
+
$fileName = str_replace( '\\', DIRECTORY_SEPARATOR, $namespace );
|
167 |
+
$fileName .= DIRECTORY_SEPARATOR;
|
168 |
+
}
|
169 |
+
|
170 |
+
$fileName .= str_replace( '_', DIRECTORY_SEPARATOR, $className );
|
171 |
+
include 'src' . DIRECTORY_SEPARATOR . $fileName . '.php';
|
172 |
+
}
|
173 |
+
|
174 |
+
// -------------------------------------------------------------------------
|
175 |
+
// Helpers
|
176 |
+
// -------------------------------------------------------------------------
|
177 |
+
/**
|
178 |
+
* Allow snippets to be retrieved directly from PHP.
|
179 |
+
*
|
180 |
+
* @since Post Snippets 1.8.9.1
|
181 |
+
*
|
182 |
+
* @param string $name The name of the snippet to retrieve
|
183 |
+
* @param string|array $variables The variables to pass to the snippet,
|
184 |
+
* formatted as a query string or an associative array.
|
185 |
+
*
|
186 |
+
* @return string The Snippet
|
187 |
+
*/
|
188 |
+
public static function getSnippet( $name, $variables = '' ) {
|
189 |
+
$snippets = get_option( self::OPTION_KEY, array() );
|
190 |
+
$snippet_count = count( $snippets );
|
191 |
+
for ( $i = 0; $i < $snippet_count; $i++ ) {
|
192 |
+
|
193 |
+
if ( $snippets[ $i ]['title'] == $name ) {
|
194 |
+
if ( ! is_array( $variables ) ) {
|
195 |
+
parse_str( htmlspecialchars_decode( $variables ), $variables );
|
196 |
+
}
|
197 |
+
$snippet = $snippets[ $i ]['snippet'];
|
198 |
+
$var_arr = explode( ',', $snippets[ $i ]['vars'] );
|
199 |
+
if ( ! empty( $var_arr[0] ) ) {
|
200 |
+
$var_arr_count = count( $var_arr );
|
201 |
+
for ( $j = 0; $j < $var_arr_count; $j++ ) {
|
202 |
+
$snippet = str_replace( '{' . $var_arr[ $j ] . '}', $variables[ $var_arr[ $j ] ], $snippet );
|
203 |
+
}
|
204 |
+
}
|
205 |
+
break;
|
206 |
+
}
|
207 |
+
}
|
208 |
+
return do_shortcode( $snippet );
|
209 |
+
}
|
210 |
+
|
211 |
+
// -------------------------------------------------------------------------
|
212 |
+
// Environment Checks
|
213 |
+
// -------------------------------------------------------------------------
|
214 |
+
/**
|
215 |
+
* Checks PHP and WordPress versions.
|
216 |
+
*/
|
217 |
+
private function testHost() {
|
218 |
+
// Check if PHP is too old
|
219 |
+
|
220 |
+
if ( version_compare( PHP_VERSION, self::MIN_PHP_VERSION, '<' ) ) {
|
221 |
+
// Display notice
|
222 |
+
add_action( 'admin_notices', array( &$this, 'phpVersionError' ) );
|
223 |
+
return false;
|
224 |
+
}
|
225 |
+
|
226 |
+
// Check if WordPress is too old
|
227 |
+
global $wp_version;
|
228 |
+
|
229 |
+
if ( version_compare( $wp_version, self::MIN_WP_VERSION, '<' ) ) {
|
230 |
+
add_action( 'admin_notices', array( &$this, 'wpVersionError' ) );
|
231 |
+
return false;
|
232 |
+
}
|
233 |
+
|
234 |
+
return true;
|
235 |
+
}
|
236 |
+
|
237 |
+
/**
|
238 |
+
* Displays a warning when installed on an old PHP version.
|
239 |
+
*/
|
240 |
+
public function phpVersionError() {
|
241 |
+
echo '<div class="error"><p><strong>';
|
242 |
+
printf(
|
243 |
+
'Error: %3$s requires PHP version %1$s or greater.<br/>' . 'Your installed PHP version: %2$s',
|
244 |
+
esc_html( self::MIN_PHP_VERSION ),
|
245 |
+
esc_html( PHP_VERSION ),
|
246 |
+
esc_html( $this->getPluginName() )
|
247 |
+
);
|
248 |
+
echo '</strong></p></div>';
|
249 |
+
}
|
250 |
+
|
251 |
+
/**
|
252 |
+
* Displays a warning when installed in an old WordPress version.
|
253 |
+
*/
|
254 |
+
public function wpVersionError() {
|
255 |
+
echo '<div class="error"><p><strong>';
|
256 |
+
printf( 'Error: %2$s requires WordPress version %1$s or greater.', esc_html( self::MIN_WP_VERSION ), esc_html( $this->getPluginName() ) );
|
257 |
+
echo '</strong></p></div>';
|
258 |
+
}
|
259 |
+
|
260 |
+
/**
|
261 |
+
* Get the name of this plugin.
|
262 |
+
*
|
263 |
+
* @return string The plugin name.
|
264 |
+
*/
|
265 |
+
private function getPluginName() {
|
266 |
+
$data = get_plugin_data( self::FILE );
|
267 |
+
return $data['Name'];
|
268 |
+
}
|
269 |
+
|
270 |
+
// -------------------------------------------------------------------------
|
271 |
+
// Deprecated methods
|
272 |
+
// -------------------------------------------------------------------------
|
273 |
+
/**
|
274 |
+
* Allow plugins to disable the PHP Code execution feature with a filter.
|
275 |
+
* Deprecated: Use the POST_SNIPPETS_DISABLE_PHP global constant to disable
|
276 |
+
* PHP instead.
|
277 |
+
*
|
278 |
+
* @see http://wordpress.org/extend/plugins/post-snippets/faq/
|
279 |
+
* @since 2.1
|
280 |
+
* @deprecated 2.3
|
281 |
+
*/
|
282 |
+
public function phpExecState() {
|
283 |
+
$filter = apply_filters( 'post_snippets_php_execution_enabled', true );
|
284 |
+
|
285 |
+
if ( $filter == false && ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
286 |
+
_deprecated_function( 'post_snippets_php_execution_enabled', '2.3', 'define(\'POST_SNIPPETS_DISABLE_PHP\', true);' );
|
287 |
+
define( 'POST_SNIPPETS_DISABLE_PHP', true );
|
288 |
+
}
|
289 |
+
|
290 |
+
}
|
291 |
+
|
292 |
+
}
|
293 |
+
add_action( 'plugins_loaded', array( 'PostSnippets', 'getInstance' ) );
|
294 |
+
/**
|
295 |
+
* Load all of the necessary class files for the plugin
|
296 |
+
*/
|
297 |
+
spl_autoload_register( 'PostSnippets::autoload' );
|
298 |
}
|
readme.txt
CHANGED
@@ -2,9 +2,9 @@
|
|
2 |
Contributors: wpexpertsio
|
3 |
Tags: custom snippet, custom shortcode, snippet, snippets, shortcode, shortcodes, block, blocks, html
|
4 |
Requires at least: 3.3
|
5 |
-
Tested up to: 5.
|
6 |
Requires PHP: 5.3
|
7 |
-
Stable tag: 3.1.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -107,6 +107,10 @@ your clients to be able to use PHP code in a post snippet.
|
|
107 |
|
108 |
== Changelog ==
|
109 |
|
|
|
|
|
|
|
|
|
110 |
= Version 3.1.3 - 10 Aug 2021 =
|
111 |
|
112 |
* Updated Freemius SDK Version 2.4.2
|
2 |
Contributors: wpexpertsio
|
3 |
Tags: custom snippet, custom shortcode, snippet, snippets, shortcode, shortcodes, block, blocks, html
|
4 |
Requires at least: 3.3
|
5 |
+
Tested up to: 5.9
|
6 |
Requires PHP: 5.3
|
7 |
+
Stable tag: 3.1.4
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
107 |
|
108 |
== Changelog ==
|
109 |
|
110 |
+
= Version 3.1.4 - 28 Jan 2022 =
|
111 |
+
|
112 |
+
* Improvement - Code Optimization
|
113 |
+
|
114 |
= Version 3.1.3 - 10 Aug 2021 =
|
115 |
|
116 |
* Updated Freemius SDK Version 2.4.2
|
src/PostSnippets/Admin.php
CHANGED
@@ -7,1084 +7,1098 @@ namespace PostSnippets;
|
|
7 |
*
|
8 |
* Class that renders out the HTML for the settings screen and contains helpful
|
9 |
* methods to simply the maintainance of the admin screen.
|
10 |
-
*
|
11 |
*/
|
12 |
-
class Admin
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
|
|
|
|
276 |
wp_send_json_error();
|
277 |
return;
|
278 |
}
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
387 |
return;
|
388 |
}
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
|
557 |
-
|
558 |
-
|
559 |
-
|
560 |
-
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
-
|
601 |
-
|
602 |
-
|
603 |
-
|
604 |
-
|
605 |
-
|
606 |
-
|
607 |
-
|
608 |
-
|
609 |
-
|
610 |
-
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
|
623 |
-
|
624 |
-
|
625 |
-
|
|
|
|
|
|
|
|
|
|
|
626 |
<!-- Create a header in the default WordPress \'wrap\' container -->
|
627 |
<div class="wrap">
|
628 |
<div id="icon-plugins" class="icon32"></div>
|
629 |
-
<h2>'
|
630 |
-
|
631 |
-
|
632 |
-
|
633 |
-
|
634 |
-
|
635 |
-
|
636 |
-
|
637 |
-
|
638 |
-
|
639 |
-
|
640 |
-
|
641 |
-
|
642 |
-
|
643 |
-
|
644 |
-
|
645 |
-
|
646 |
-
|
647 |
-
|
648 |
-
|
649 |
-
|
650 |
-
|
651 |
-
|
652 |
-
|
653 |
-
|
654 |
-
|
655 |
-
|
656 |
-
|
657 |
-
|
658 |
-
|
659 |
-
|
660 |
-
|
661 |
-
|
662 |
-
|
663 |
-
|
664 |
-
|
665 |
-
|
666 |
-
|
667 |
-
|
668 |
-
|
669 |
-
|
670 |
-
|
671 |
-
|
672 |
-
|
673 |
-
|
674 |
-
|
675 |
-
|
676 |
-
|
677 |
-
|
678 |
-
|
679 |
-
|
680 |
-
|
681 |
-
|
682 |
-
|
683 |
-
|
684 |
-
|
685 |
-
|
686 |
-
|
687 |
-
|
688 |
-
|
689 |
-
|
690 |
-
|
691 |
-
|
692 |
-
|
693 |
-
|
694 |
-
|
695 |
-
|
696 |
-
|
697 |
-
|
698 |
-
|
699 |
-
|
700 |
-
|
701 |
-
|
702 |
-
|
703 |
-
|
704 |
-
|
705 |
-
|
706 |
-
|
707 |
-
|
708 |
-
|
709 |
-
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
716 |
-
|
717 |
-
|
718 |
-
|
719 |
-
|
720 |
-
|
721 |
-
|
722 |
-
|
723 |
-
|
724 |
-
|
725 |
-
|
726 |
-
|
727 |
-
|
728 |
-
|
729 |
-
|
730 |
-
|
731 |
-
|
732 |
-
|
733 |
-
|
734 |
-
|
735 |
-
|
736 |
-
|
737 |
-
|
738 |
-
|
739 |
-
|
740 |
-
|
741 |
-
|
742 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
746 |
-
|
747 |
-
|
748 |
-
|
749 |
-
|
750 |
-
|
751 |
-
|
752 |
-
|
753 |
-
|
754 |
-
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
759 |
-
|
760 |
-
|
761 |
-
|
762 |
-
|
763 |
-
|
764 |
-
|
765 |
-
|
766 |
-
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
774 |
-
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
789 |
-
|
790 |
-
|
791 |
-
|
792 |
-
|
793 |
-
|
794 |
-
|
795 |
-
|
796 |
-
|
797 |
-
|
798 |
-
|
799 |
-
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
807 |
-
|
808 |
-
|
809 |
-
|
810 |
-
|
811 |
-
|
812 |
-
|
813 |
-
|
814 |
-
|
815 |
-
|
816 |
-
|
817 |
-
|
818 |
-
|
819 |
-
|
820 |
-
|
821 |
-
|
822 |
-
|
823 |
-
|
824 |
-
|
825 |
-
|
826 |
-
|
827 |
-
|
828 |
-
|
829 |
-
|
830 |
-
|
831 |
-
|
832 |
-
|
833 |
-
|
834 |
-
|
835 |
-
|
836 |
-
|
837 |
-
|
838 |
-
|
839 |
-
|
840 |
-
|
841 |
-
|
842 |
-
|
843 |
-
|
844 |
-
|
845 |
-
|
846 |
-
|
847 |
-
|
848 |
-
|
849 |
-
|
850 |
-
|
851 |
-
|
852 |
-
|
853 |
-
|
854 |
-
|
855 |
-
|
856 |
-
|
857 |
-
|
858 |
-
|
859 |
-
|
860 |
-
|
861 |
-
|
862 |
-
|
863 |
-
|
864 |
-
|
865 |
-
|
866 |
-
|
867 |
-
|
868 |
-
|
869 |
-
|
870 |
-
|
871 |
-
|
872 |
-
|
873 |
-
|
874 |
-
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
-
|
880 |
-
|
881 |
-
|
882 |
-
|
883 |
-
|
884 |
-
|
885 |
-
|
886 |
-
|
887 |
-
|
888 |
-
|
889 |
-
|
890 |
-
|
891 |
-
|
892 |
-
|
893 |
-
|
894 |
-
|
895 |
-
|
896 |
-
|
897 |
-
|
898 |
-
|
899 |
-
|
900 |
-
|
901 |
-
|
902 |
-
|
903 |
-
|
904 |
-
|
905 |
-
|
906 |
-
|
907 |
-
|
908 |
-
|
909 |
-
|
910 |
-
|
911 |
-
|
912 |
-
|
913 |
-
|
914 |
-
|
915 |
-
|
916 |
-
|
917 |
-
|
918 |
-
|
919 |
-
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
-
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
|
928 |
-
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
|
933 |
-
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
|
939 |
-
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
944 |
-
|
945 |
-
|
946 |
-
|
947 |
-
|
948 |
-
|
949 |
-
|
950 |
-
|
951 |
-
|
952 |
-
|
953 |
-
|
954 |
-
|
955 |
-
|
956 |
-
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
-
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
-
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
971 |
-
|
972 |
-
|
973 |
-
|
974 |
-
|
975 |
-
|
976 |
-
|
977 |
-
|
978 |
-
|
979 |
-
|
980 |
-
|
981 |
-
|
982 |
-
|
983 |
-
|
984 |
-
|
985 |
-
|
986 |
-
|
987 |
-
|
988 |
-
|
989 |
-
|
990 |
-
|
991 |
-
|
992 |
-
|
993 |
-
|
994 |
-
|
995 |
-
|
996 |
-
|
997 |
-
|
998 |
-
|
999 |
-
|
1000 |
-
|
1001 |
-
|
1002 |
-
|
1003 |
-
|
1004 |
-
|
1005 |
-
|
1006 |
-
|
1007 |
-
|
1008 |
-
|
1009 |
-
|
1010 |
-
|
1011 |
-
|
1012 |
-
|
1013 |
-
|
1014 |
-
|
1015 |
-
|
1016 |
-
|
1017 |
-
|
1018 |
-
|
1019 |
-
|
1020 |
-
|
1021 |
-
|
1022 |
-
|
1023 |
-
|
1024 |
-
|
1025 |
-
|
1026 |
-
|
1027 |
-
|
1028 |
-
|
1029 |
-
|
1030 |
-
|
1031 |
-
|
1032 |
-
|
1033 |
-
|
1034 |
-
|
1035 |
-
|
1036 |
-
|
1037 |
-
|
1038 |
-
|
1039 |
-
|
1040 |
-
|
1041 |
-
|
1042 |
-
|
1043 |
-
|
1044 |
-
|
1045 |
-
|
1046 |
-
|
1047 |
-
|
1048 |
-
|
1049 |
-
|
1050 |
-
|
1051 |
-
|
1052 |
-
|
1053 |
-
|
1054 |
-
|
1055 |
-
|
1056 |
-
|
1057 |
-
|
1058 |
-
|
1059 |
-
|
1060 |
-
|
1061 |
-
|
1062 |
-
|
1063 |
-
|
1064 |
-
|
1065 |
-
|
1066 |
-
|
1067 |
-
|
1068 |
-
|
1069 |
-
|
1070 |
-
|
1071 |
-
|
1072 |
-
|
1073 |
-
|
1074 |
-
|
1075 |
-
|
1076 |
-
|
1077 |
-
|
1078 |
-
|
1079 |
-
|
1080 |
-
public function get_allowed_capability(){
|
1081 |
-
$capability = 'manage_options';
|
1082 |
-
|
1083 |
-
if ( defined( 'POST_SNIPPETS_ALLOW_EDIT_POSTS' ) and current_user_can( 'edit_posts' ) ) {
|
1084 |
-
$capability = 'edit_posts';
|
1085 |
-
}
|
1086 |
-
|
1087 |
-
return $capability;
|
1088 |
-
}
|
1089 |
-
|
1090 |
-
}
|
7 |
*
|
8 |
* Class that renders out the HTML for the settings screen and contains helpful
|
9 |
* methods to simply the maintainance of the admin screen.
|
|
|
10 |
*/
|
11 |
+
class Admin {
|
12 |
+
|
13 |
+
/**
|
14 |
+
* Plugin settings.
|
15 |
+
*
|
16 |
+
* @var array
|
17 |
+
*/
|
18 |
+
protected $settings;
|
19 |
+
/**
|
20 |
+
* Defines hooks and filters for admin page.
|
21 |
+
*/
|
22 |
+
public function __construct() {
|
23 |
+
add_action( 'admin_menu', array( &$this, 'menu' ) );
|
24 |
+
add_action( 'admin_init', array( &$this, 'init' ) );
|
25 |
+
add_action( 'current_screen', array( &$this, 'addHeaderXss' ) );
|
26 |
+
add_filter( 'plugin_action_links_' . plugin_basename( PS_MAIN_FILE_PATH ), array( $this, 'actionLinks' ) );
|
27 |
+
// Newsletter sign-up admin notice
|
28 |
+
add_action( 'admin_notices', array( $this, 'admin_notice_newsletter' ) );
|
29 |
+
// Get started admin notice
|
30 |
+
add_action( 'admin_notices', array( $this, 'admin_notice_get_started' ) );
|
31 |
+
// add_action( 'wp_ajax_update_post_snippets_order', array( $this, 'update_snippets_order' ) );
|
32 |
+
add_action( 'wp_ajax_update_post_snippet_title', array( $this, 'update_post_snippet_title' ) );
|
33 |
+
add_action( 'wp_ajax_update_post_snippet', array( $this, 'update_post_snippet' ) );
|
34 |
+
add_action( 'wp_ajax_delete_post_snippet', array( $this, 'delete_post_snippet' ) );
|
35 |
+
add_action( 'wp_ajax_sync_up', array( $this, 'sync_up' ) );
|
36 |
+
add_action( 'wp_ajax_sync_list', array( $this, 'sync_list' ) );
|
37 |
+
add_action( 'wp_ajax_sync', array( $this, 'sync' ) );
|
38 |
+
add_action( 'enqueue_block_editor_assets', array( $this, 'load_block' ) );
|
39 |
+
}
|
40 |
+
|
41 |
+
public function load_block() {
|
42 |
+
wp_enqueue_script(
|
43 |
+
'post-snippets-block',
|
44 |
+
PS_URL . 'dist/blocks.build.js',
|
45 |
+
array( 'wp-blocks', 'wp-editor' ),
|
46 |
+
true
|
47 |
+
);
|
48 |
+
|
49 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
50 |
+
if ( isset( $snippets ) && ! empty( $snippets ) && is_array( $snippets ) ) {
|
51 |
+
usort(
|
52 |
+
$snippets,
|
53 |
+
function ( $a, $b ) {
|
54 |
+
return strcasecmp( $a['title'], $b['title'] );
|
55 |
+
}
|
56 |
+
);
|
57 |
+
}
|
58 |
+
wp_localize_script( 'post-snippets-block', 'post_snippets_s', $snippets );
|
59 |
+
}
|
60 |
+
|
61 |
+
// -------------------------------------------------------------------------
|
62 |
+
// Setup
|
63 |
+
// -------------------------------------------------------------------------
|
64 |
+
/**
|
65 |
+
* Register the administration page.
|
66 |
+
*
|
67 |
+
* @return void
|
68 |
+
*/
|
69 |
+
public function menu() {
|
70 |
+
$capability = $this->get_allowed_capability();
|
71 |
+
|
72 |
+
if ( $capability == 'edit_posts' ) {
|
73 |
+
$allowed = true;
|
74 |
+
}
|
75 |
+
|
76 |
+
if ( current_user_can( 'manage_options' ) || isset( $allowed ) ) {
|
77 |
+
$optionPage = add_menu_page(
|
78 |
+
__( 'Post Snippets', 'post-snippets' ),
|
79 |
+
__( 'Post Snippets', 'post-snippets' ),
|
80 |
+
$capability,
|
81 |
+
'post-snippets',
|
82 |
+
array( $this, 'optionsPage' ),
|
83 |
+
PS_URL . 'assets/icon.svg'
|
84 |
+
);
|
85 |
+
$newsPage = add_submenu_page(
|
86 |
+
'post-snippets',
|
87 |
+
__( 'News', 'post-snippets' ),
|
88 |
+
__( 'News', 'post-snippets' ),
|
89 |
+
$capability,
|
90 |
+
'post-snippets-news',
|
91 |
+
array( $this, 'newsPage' )
|
92 |
+
// array( $this, 'overviewPage' )
|
93 |
+
);
|
94 |
+
/*
|
95 |
+
$optionPage = add_submenu_page(
|
96 |
+
__( 'Post Snippets', 'post-snippets'),
|
97 |
+
__( 'Post Snippets', 'post-snippets'),
|
98 |
+
$capability,
|
99 |
+
'post-snippets',
|
100 |
+
array ( &$this, 'optionsPage' )
|
101 |
+
);*/
|
102 |
+
new Help( $optionPage );
|
103 |
+
} else {
|
104 |
+
add_menu_page(
|
105 |
+
__( 'Post Snippets', 'post-snippets' ),
|
106 |
+
__( 'Post Snippets', 'post-snippets' ),
|
107 |
+
'manage_options',
|
108 |
+
'post-snippets',
|
109 |
+
array( $this, 'overviewPage' ),
|
110 |
+
PS_URL . 'assets/icon.svg'
|
111 |
+
);
|
112 |
+
}
|
113 |
+
|
114 |
+
}
|
115 |
+
|
116 |
+
/**
|
117 |
+
* Initialize assets for the administration page.
|
118 |
+
*
|
119 |
+
* @return void
|
120 |
+
*/
|
121 |
+
public function init() {
|
122 |
+
wp_register_script(
|
123 |
+
'post-snippets',
|
124 |
+
plugins_url( '/assets/post-snippets.js', \PostSnippets::FILE ),
|
125 |
+
array( 'jquery' ),
|
126 |
+
PS_VERSION,
|
127 |
+
true
|
128 |
+
);
|
129 |
+
$this->scripts();
|
130 |
+
$this->registerSettings();
|
131 |
+
}
|
132 |
+
|
133 |
+
/**
|
134 |
+
* Enqueue scripts to be loaded.
|
135 |
+
*
|
136 |
+
* @return void
|
137 |
+
*/
|
138 |
+
public function scripts() {
|
139 |
+
// Localize the strings in the script
|
140 |
+
$translation_array = array(
|
141 |
+
'invalid_shortcode' => __( 'Invalid shortcode name', 'post-snippets' ),
|
142 |
+
'save_title_nonce' => wp_create_nonce( 'ps-save-title-nonce' ),
|
143 |
+
'update_snippet_nonce' => wp_create_nonce( 'ps-update-snippet-nonce' ),
|
144 |
+
);
|
145 |
+
wp_localize_script( 'post-snippets', 'post_snippets', $translation_array );
|
146 |
+
// Add CSS for Pro features page
|
147 |
+
$features_style_url = plugins_url( '/assets/features.css', \PostSnippets::FILE );
|
148 |
+
wp_register_style(
|
149 |
+
'post-snippets-icons',
|
150 |
+
$features_style_url,
|
151 |
+
array(),
|
152 |
+
PS_VERSION
|
153 |
+
);
|
154 |
+
wp_enqueue_style( 'post-snippets-icons' );
|
155 |
+
// Add CSS for icons
|
156 |
+
$features_style_url = plugins_url( '/assets/icons.css', \PostSnippets::FILE );
|
157 |
+
wp_register_style(
|
158 |
+
'post-snippets-features',
|
159 |
+
$features_style_url,
|
160 |
+
array(),
|
161 |
+
PS_VERSION
|
162 |
+
);
|
163 |
+
wp_enqueue_style( 'post-snippets-features' );
|
164 |
+
// Add CSS for newsletter opt-in
|
165 |
+
$features_style_url = plugins_url( '/assets/newsletter.css', \PostSnippets::FILE );
|
166 |
+
wp_register_style(
|
167 |
+
'post-snippets-newsletter',
|
168 |
+
$features_style_url,
|
169 |
+
array(),
|
170 |
+
PS_VERSION
|
171 |
+
);
|
172 |
+
wp_enqueue_style( 'post-snippets-newsletter' );
|
173 |
+
wp_enqueue_script( 'jquery-ui-sortable' );
|
174 |
+
wp_enqueue_script( 'jquery-ui-dialog' );
|
175 |
+
wp_enqueue_script( 'underscore' );
|
176 |
+
wp_enqueue_script( 'post-snippets' );
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Add X-XSS-Protection header.
|
181 |
+
*
|
182 |
+
* Newer versions of Chrome does not allow form tags to be submitted in the
|
183 |
+
* forms. This header disables that functionlity on the Post Snippets admin
|
184 |
+
* screen only.
|
185 |
+
*/
|
186 |
+
public function addHeaderXss( $current_screen ) {
|
187 |
+
if ( $current_screen->base == 'settings_page_post-snippets/post-snippets' ) {
|
188 |
+
header( 'X-XSS-Protection: 0' );
|
189 |
+
}
|
190 |
+
}
|
191 |
+
|
192 |
+
/**
|
193 |
+
* Quick link to the Post Snippets Settings page from the Plugins page.
|
194 |
+
*
|
195 |
+
* @param array $links Array of all plugin links
|
196 |
+
*
|
197 |
+
* @return array $links Array with all the plugin's action links
|
198 |
+
*/
|
199 |
+
public function actionLinks( $links ) {
|
200 |
+
$links[] = '<a href="' . PS_MAIN_PAGE_URL . '">' . __( 'Settings', 'post-snippets' ) . '</a>';
|
201 |
+
return $links;
|
202 |
+
}
|
203 |
+
|
204 |
+
// -------------------------------------------------------------------------
|
205 |
+
// Handle form submissions
|
206 |
+
// -------------------------------------------------------------------------
|
207 |
+
/**
|
208 |
+
* Add New Snippet.
|
209 |
+
*/
|
210 |
+
private function add() {
|
211 |
+
|
212 |
+
if ( isset( $_POST['add-snippet'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
|
213 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
214 |
+
if ( empty( $snippets ) ) {
|
215 |
+
$snippets = array();
|
216 |
+
}
|
217 |
+
array_push(
|
218 |
+
$snippets,
|
219 |
+
array(
|
220 |
+
'title' => 'Untitled',
|
221 |
+
'vars' => '',
|
222 |
+
'description' => '',
|
223 |
+
'shortcode' => false,
|
224 |
+
'php' => false,
|
225 |
+
'wptexturize' => false,
|
226 |
+
'snippet' => '',
|
227 |
+
)
|
228 |
+
);
|
229 |
+
update_option( \PostSnippets::OPTION_KEY, $snippets );
|
230 |
+
$this->message( __( 'A snippet named Untitled has been added.', 'post-snippets' ) );
|
231 |
+
}
|
232 |
+
|
233 |
+
}
|
234 |
+
|
235 |
+
public function sync_list() {
|
236 |
+
|
237 |
+
if ( isset( $_POST['sync_down'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_down'] ), 'sync_down' ) && current_user_can( 'manage_options' ) ) {
|
238 |
+
|
239 |
+
if ( postsnippets_fs()->can_use_premium_code() ) {
|
240 |
+
$license = postsnippets_fs()->_get_license();
|
241 |
+
|
242 |
+
if ( $license != null ) {
|
243 |
+
$id = $license->id;
|
244 |
+
$secret = $license->secret_key;
|
245 |
+
$query = array();
|
246 |
+
$query['lid'] = $id;
|
247 |
+
$query['s'] = $secret;
|
248 |
+
$arg = array(
|
249 |
+
'method' => 'POST',
|
250 |
+
'body' => ( $query ),
|
251 |
+
'data_format' => 'body',
|
252 |
+
);
|
253 |
+
$response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
|
254 |
+
$body = wp_remote_retrieve_body( $response );
|
255 |
+
// $http_code = wp_remote_retrieve_response_code( $response );
|
256 |
+
|
257 |
+
$response = json_decode( $body );
|
258 |
+
// $ch = curl_init();
|
259 |
+
// curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
|
260 |
+
// curl_setopt( $ch, CURLOPT_POST, 1 );
|
261 |
+
// curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
|
262 |
+
// curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
263 |
+
// $server_output = curl_exec( $ch );
|
264 |
+
// $response = json_decode( $server_output );
|
265 |
+
wp_send_json_success( $response );
|
266 |
+
}
|
267 |
+
}
|
268 |
+
} else {
|
269 |
+
wp_send_json_error();
|
270 |
+
}
|
271 |
+
|
272 |
+
}
|
273 |
+
|
274 |
+
public function sync() {
|
275 |
+
if ( isset( $_POST['sync_up'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_up'] ), 'sync_up' ) && current_user_can( 'manage_options' ) ) {
|
276 |
+
if ( ! isset( $_POST['ids'] ) ) {
|
277 |
wp_send_json_error();
|
278 |
return;
|
279 |
}
|
280 |
+
$ids = explode( ',', sanitize_text_field( wp_unslash( $_POST['ids'] ) ) );
|
281 |
+
|
282 |
+
foreach ( $ids as $id ) {
|
283 |
+
if ( ! is_numeric( $id ) ) {
|
284 |
+
wp_send_json_error();
|
285 |
+
return;
|
286 |
+
}
|
287 |
+
}
|
288 |
+
|
289 |
+
if ( count( $ids ) == 0 ) {
|
290 |
+
wp_send_json_error();
|
291 |
+
return;
|
292 |
+
}
|
293 |
+
|
294 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
295 |
+
|
296 |
+
if ( postsnippets_fs()->can_use_premium_code() ) {
|
297 |
+
$license = postsnippets_fs()->_get_license();
|
298 |
+
|
299 |
+
if ( $license != null ) {
|
300 |
+
$id = $license->id;
|
301 |
+
$secret = $license->secret_key;
|
302 |
+
$query = array();
|
303 |
+
$query['lid'] = $id;
|
304 |
+
$query['s'] = $secret;
|
305 |
+
$arg = array(
|
306 |
+
'method' => 'POST',
|
307 |
+
'body' => ( $query ),
|
308 |
+
'data_format' => 'body',
|
309 |
+
);
|
310 |
+
$response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
|
311 |
+
$body = wp_remote_retrieve_body( $response );
|
312 |
+
|
313 |
+
// $ch = curl_init();
|
314 |
+
// curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/list" );
|
315 |
+
// curl_setopt( $ch, CURLOPT_POST, 1 );
|
316 |
+
// curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
|
317 |
+
// curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
318 |
+
// $server_output = curl_exec( $ch );
|
319 |
+
|
320 |
+
$response = json_decode( $body, true );
|
321 |
+
$saved_snippets = $response['data'];
|
322 |
+
$i = 0;
|
323 |
+
$updated = array();
|
324 |
+
foreach ( $snippets as &$snippet ) {
|
325 |
+
foreach ( $saved_snippets as $saved ) {
|
326 |
+
|
327 |
+
if ( $snippet['title'] == $saved['title'] && in_array( $saved['id'], $ids ) ) {
|
328 |
+
$snippet = $saved;
|
329 |
+
$options = json_decode( $saved['options'], true );
|
330 |
+
$snippet['php'] = ( $options['php'] ? '1' : '0' );
|
331 |
+
$snippet['shortcode'] = ( $options['shortcode'] ? '1' : '0' );
|
332 |
+
$snippet['wptexturize'] = ( $options['wptexturize'] ? '1' : '0' );
|
333 |
+
if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
334 |
+
$snippet['php'] = '0';
|
335 |
+
}
|
336 |
+
$updated[] = $snippet['title'];
|
337 |
+
}
|
338 |
+
}
|
339 |
+
}
|
340 |
+
foreach ( $saved_snippets as $saved ) {
|
341 |
+
if ( ! in_array( $saved['id'], $ids ) ) {
|
342 |
+
continue;
|
343 |
+
}
|
344 |
+
|
345 |
+
if ( ! in_array( $saved['title'], $updated ) ) {
|
346 |
+
$snippet = $saved;
|
347 |
+
$options = json_decode( $saved['options'], true );
|
348 |
+
$snippet['php'] = ( $options['php'] ? '1' : '0' );
|
349 |
+
$snippet['shortcode'] = ( $options['shortcode'] ? '1' : '0' );
|
350 |
+
$snippet['wptexturize'] = ( $options['wptexturize'] ? '1' : '0' );
|
351 |
+
if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
352 |
+
$snippet['php'] = '0';
|
353 |
+
}
|
354 |
+
$snippets[] = $snippet;
|
355 |
+
}
|
356 |
+
}
|
357 |
+
update_option( \PostSnippets::OPTION_KEY, $snippets );
|
358 |
+
wp_send_json_success();
|
359 |
+
}
|
360 |
+
}
|
361 |
+
} else {
|
362 |
+
wp_send_json_error();
|
363 |
+
}
|
364 |
+
|
365 |
+
}
|
366 |
+
|
367 |
+
public function sync_up() {
|
368 |
+
|
369 |
+
if ( isset( $_POST['sync_up'] ) && wp_verify_nonce( sanitize_key( $_POST['sync_up'] ), 'sync_up' ) && current_user_can( 'manage_options' ) ) {
|
370 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
371 |
+
|
372 |
+
if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
|
373 |
+
wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
|
374 |
+
return;
|
375 |
+
}
|
376 |
+
|
377 |
+
if ( postsnippets_fs()->can_use_premium_code() ) {
|
378 |
+
$license = postsnippets_fs()->_get_license();
|
379 |
+
|
380 |
+
if ( $license != null ) {
|
381 |
+
$id = $license->id;
|
382 |
+
$secret = $license->secret_key;
|
383 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
384 |
+
|
385 |
+
if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
|
386 |
+
wp_send_json_error( __( 'Nothing selected to save.', 'post-snippets' ) );
|
387 |
+
return;
|
388 |
+
}
|
389 |
+
|
390 |
+
$toSave = sanitize_key( $_POST['key'] );
|
391 |
+
$newsnippets = array();
|
392 |
+
$data = null;
|
393 |
+
foreach ( $snippets as $key => $snippet ) {
|
394 |
+
|
395 |
+
if ( $key == $toSave ) {
|
396 |
+
$data = $snippet;
|
397 |
+
break;
|
398 |
+
}
|
399 |
+
}
|
400 |
+
|
401 |
+
if ( $data == null ) {
|
402 |
+
wp_send_json_error( __( "Snippet {$key} not found", 'post-snippets' ) );
|
403 |
+
return;
|
404 |
+
}
|
405 |
+
|
406 |
+
if ( ! isset( $_POST['update'] ) ) {
|
407 |
+
wp_send_json_error( __( 'Update not defined.', 'post-snippets' ) );
|
408 |
return;
|
409 |
}
|
410 |
+
|
411 |
+
$query = array();
|
412 |
+
$query['update'] = sanitize_text_field( wp_unslash( $_POST['update'] ) );
|
413 |
+
$query['lid'] = $id;
|
414 |
+
$query['s'] = $secret;
|
415 |
+
$query['title'] = $snippet['title'];
|
416 |
+
$query['description'] = $snippet['description'];
|
417 |
+
$query['vars'] = $snippet['vars'];
|
418 |
+
$query['snippet'] = $snippet['snippet'];
|
419 |
+
$query['options'] = wp_json_encode(
|
420 |
+
array(
|
421 |
+
'shortcode' => isset( $snippet['shortcode'] ) && $snippet['shortcode'] == '1',
|
422 |
+
'php' => isset( $snippet['php'] ) && $snippet['php'] == '1',
|
423 |
+
'wptexturize' => isset( $snippet['wptexturize'] ) && $snippet['wptexturize'] == '1',
|
424 |
+
)
|
425 |
+
);
|
426 |
+
|
427 |
+
$arg = array(
|
428 |
+
'method' => 'POST',
|
429 |
+
'body' => ( $query ),
|
430 |
+
'data_format' => 'body',
|
431 |
+
);
|
432 |
+
$response = wp_remote_post( 'https://cloud.postsnippets.com/wp-content/themes/twentytwenty/ps-cloud/list.php', $arg );
|
433 |
+
$body = wp_remote_retrieve_body( $response );
|
434 |
+
|
435 |
+
// $ch = curl_init();
|
436 |
+
// curl_setopt( $ch, CURLOPT_URL, "https://api.greentreelabs.net/postsnippets/save" );
|
437 |
+
// curl_setopt( $ch, CURLOPT_POST, 1 );
|
438 |
+
// curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $query ) );
|
439 |
+
// curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
|
440 |
+
// $server_output = curl_exec( $ch );
|
441 |
+
// curl_close( $ch );
|
442 |
+
|
443 |
+
$response = json_decode( $body );
|
444 |
+
|
445 |
+
if ( isset( $response->code ) && $response->code != '1' ) {
|
446 |
+
$msg = '?';
|
447 |
+
if ( isset( $response->code ) ) {
|
448 |
+
$msg = $response->data;
|
449 |
+
}
|
450 |
+
wp_send_json_error( $response );
|
451 |
+
} else {
|
452 |
+
wp_send_json_success();
|
453 |
+
}
|
454 |
+
} else {
|
455 |
+
wp_send_json_error( 'enter-license' );
|
456 |
+
return;
|
457 |
+
}
|
458 |
+
} else {
|
459 |
+
wp_send_json_error( 'license' );
|
460 |
+
return;
|
461 |
+
}
|
462 |
+
}
|
463 |
+
|
464 |
+
}
|
465 |
+
|
466 |
+
/**
|
467 |
+
* Delete snippet via ajax
|
468 |
+
*/
|
469 |
+
public function delete_post_snippet() {
|
470 |
+
|
471 |
+
if ( isset( $_POST['delete_snippet'] ) && wp_verify_nonce( sanitize_key( $_POST['delete_snippet'] ), 'delete_snippet' ) && current_user_can( 'manage_options' ) ) {
|
472 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
473 |
+
|
474 |
+
if ( empty( $snippets ) || ! isset( $_POST['key'] ) ) {
|
475 |
+
wp_send_json_error( __( 'Nothing selected to delete.', 'post-snippets' ) );
|
476 |
+
return;
|
477 |
+
}
|
478 |
+
|
479 |
+
$delete = sanitize_key( $_POST['key'] );
|
480 |
+
$newsnippets = array();
|
481 |
+
foreach ( $snippets as $key => $snippet ) {
|
482 |
+
if ( $key != $delete ) {
|
483 |
+
array_push( $newsnippets, $snippet );
|
484 |
+
}
|
485 |
+
}
|
486 |
+
update_option( \PostSnippets::OPTION_KEY, $newsnippets );
|
487 |
+
wp_send_json_success();
|
488 |
+
} else {
|
489 |
+
wp_send_json_error( __( 'Security check failed.', 'post-snippets' ) );
|
490 |
+
}
|
491 |
+
|
492 |
+
wp_die();
|
493 |
+
}
|
494 |
+
|
495 |
+
/**
|
496 |
+
* Delete Snippet/s.
|
497 |
+
*/
|
498 |
+
private function delete() {
|
499 |
+
|
500 |
+
if ( isset( $_POST['delete-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
|
501 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
502 |
+
|
503 |
+
if ( empty( $snippets ) || ! isset( $_POST['checked'] ) ) {
|
504 |
+
$this->message( __( 'Nothing selected to delete.', 'post-snippets' ) );
|
505 |
+
return;
|
506 |
+
}
|
507 |
+
|
508 |
+
$delete = array_map( 'sanitize_text_field', wp_unslash( $_POST['checked'] ) );
|
509 |
+
$newsnippets = array();
|
510 |
+
foreach ( $snippets as $key => $snippet ) {
|
511 |
+
if ( in_array( $key, $delete ) == false ) {
|
512 |
+
array_push( $newsnippets, $snippet );
|
513 |
+
}
|
514 |
+
}
|
515 |
+
update_option( \PostSnippets::OPTION_KEY, $newsnippets );
|
516 |
+
$this->message( __( 'Selected snippets have been deleted.', 'post-snippets' ) );
|
517 |
+
}
|
518 |
+
|
519 |
+
}
|
520 |
+
|
521 |
+
/**
|
522 |
+
* Update Snippet/s.
|
523 |
+
*/
|
524 |
+
private function update() {
|
525 |
+
if ( isset( $_POST['update-snippets'] ) && isset( $_POST['update_snippets_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['update_snippets_nonce'] ), 'update_snippets' ) && current_user_can( 'manage_options' ) ) {
|
526 |
+
$default = array(
|
527 |
+
'title' => '',
|
528 |
+
'rtf' => '0',
|
529 |
+
'snippet' => '',
|
530 |
+
'description' => '',
|
531 |
+
'vars' => '',
|
532 |
+
'shortcode' => '0',
|
533 |
+
'php' => '0',
|
534 |
+
'wptexturize' => '0',
|
535 |
+
);
|
536 |
+
$formatted_snippets = array();
|
537 |
+
|
538 |
+
if ( ! empty( $_POST['snippets'] ) ) {
|
539 |
+
$snippets = array_map( 'sanitize_text_field', wp_unslash( $_POST['snippets'] ) );
|
540 |
+
$i = 0;
|
541 |
+
foreach ( $snippets as $snippet ) {
|
542 |
+
if ( empty( $snippets ) ) {
|
543 |
+
continue;
|
544 |
+
}
|
545 |
+
$snippet = wp_parse_args( $snippet, $default );
|
546 |
+
$snippet['title'] = str_replace( ' ', '', $snippet['title'] );
|
547 |
+
if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
548 |
+
$snippet['php'] = '0';
|
549 |
+
}
|
550 |
+
$snippet['snippet'] = wp_specialchars_decode( trim( stripslashes( $snippet['snippet'] ) ), ENT_NOQUOTES );
|
551 |
+
$snippet['description'] = wp_specialchars_decode( trim( stripslashes( $snippet['description'] ) ), ENT_NOQUOTES );
|
552 |
+
$formatted_snippets[ $i ] = $snippet;
|
553 |
+
$i++;
|
554 |
+
}
|
555 |
+
}
|
556 |
+
|
557 |
+
update_option( \PostSnippets::OPTION_KEY, $formatted_snippets );
|
558 |
+
$this->message( __( 'Snippets have been updated.', 'post-snippets' ) );
|
559 |
+
}
|
560 |
+
|
561 |
+
}
|
562 |
+
|
563 |
+
/**
|
564 |
+
* Update User Option.
|
565 |
+
*
|
566 |
+
* Sets the per user option for the read-only overview page.
|
567 |
+
*
|
568 |
+
* @since Post Snippets 1.9.7
|
569 |
+
*/
|
570 |
+
private function setUserOptions() {
|
571 |
+
|
572 |
+
if ( isset( $_POST['post_snippets_user_nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['post_snippets_user_nonce'] ), 'post_snippets_user_options' ) && current_user_can( 'manage_options' ) ) {
|
573 |
+
$id = get_current_user_id();
|
574 |
+
$render = ( isset( $_POST['render'] ) ? true : false );
|
575 |
+
update_user_meta( $id, \PostSnippets::USER_META_KEY, $render );
|
576 |
+
}
|
577 |
+
|
578 |
+
}
|
579 |
+
|
580 |
+
/**
|
581 |
+
* Get User Option.
|
582 |
+
*
|
583 |
+
* Gets the per user option for the read-only overview page.
|
584 |
+
*
|
585 |
+
* @since Post Snippets 1.9.7
|
586 |
+
* @return boolean If overview should be rendered on output or not
|
587 |
+
*/
|
588 |
+
private function getUserOptions() {
|
589 |
+
$id = get_current_user_id();
|
590 |
+
$options = get_user_meta( $id, \PostSnippets::USER_META_KEY, true );
|
591 |
+
return $options;
|
592 |
+
}
|
593 |
+
|
594 |
+
// -------------------------------------------------------------------------
|
595 |
+
// HTML generation for option pages
|
596 |
+
// -------------------------------------------------------------------------
|
597 |
+
/**
|
598 |
+
* Display Flashing Message.
|
599 |
+
*
|
600 |
+
* @param string $message Message to display to the user.
|
601 |
+
*/
|
602 |
+
private function message( $message ) {
|
603 |
+
if ( $message ) {
|
604 |
+
echo "<div class='updated'><p><strong>" .esc_html( $message ). "</strong></p></div>";
|
605 |
+
}
|
606 |
+
}
|
607 |
+
|
608 |
+
public function newsPage() {
|
609 |
+
$plugins = array(
|
610 |
+
array(
|
611 |
+
'name' => 'myCred',
|
612 |
+
'description' => 'myCred makes it simple to create a loyalty program or gamify your website so that you can increase the average customer value with less marketing effort.',
|
613 |
+
'image' => 'myCred.png',
|
614 |
+
'url' => 'https://wordpress.org/plugins/mycred',
|
615 |
+
),
|
616 |
+
array(
|
617 |
+
'name' => 'WP Contact Slider',
|
618 |
+
'description' => 'WP contact slider is simple contact slider to display contactform7, Gravity forms, Wp Forms, Caldera forms, Constant Contact Forms or display random text or HTML.',
|
619 |
+
'image' => 'ContactSlider.png',
|
620 |
+
'url' => 'https://wordpress.org/plugins/wp-contact-slider/',
|
621 |
+
),
|
622 |
+
array(
|
623 |
+
'name' => 'Wholesale For WooCommerce',
|
624 |
+
'description' => 'Sign up wholesale customers and display wholesale prices based on multiple wholesale user roles on your existing WooCommerce store',
|
625 |
+
'image' => 'WholesaleForWoocommerce.png',
|
626 |
+
'url' => 'https://woocommerce.com/products/wholesale-for-woocommerce/',
|
627 |
+
),
|
628 |
+
array(
|
629 |
+
'name' => 'WooCommerce Product Disclaimer',
|
630 |
+
'description' => 'Woocommerce extension where you can set some products to accept terms and conditions before adding product to cart. ',
|
631 |
+
'image' => 'ProductDisclaimer.png',
|
632 |
+
'url' => 'https://wordpress.org/plugins/woo-product-disclaimer/',
|
633 |
+
),
|
634 |
+
);
|
635 |
+
include PS_PATH . '/views/admin_news.php';
|
636 |
+
}
|
637 |
+
|
638 |
+
/**
|
639 |
+
* Creates the snippets administration page.
|
640 |
+
*
|
641 |
+
* For users with manage_options capability (admin, super admin).
|
642 |
+
*
|
643 |
+
* @since Post Snippets 1.8.8
|
644 |
+
*/
|
645 |
+
public function optionsPage() {
|
646 |
+
// Handle Form Submits
|
647 |
+
$this->add();
|
648 |
+
$this->delete();
|
649 |
+
$this->update();
|
650 |
+
// Header
|
651 |
+
echo '
|
652 |
<!-- Create a header in the default WordPress \'wrap\' container -->
|
653 |
<div class="wrap">
|
654 |
<div id="icon-plugins" class="icon32"></div>
|
655 |
+
<h2>';
|
656 |
+
echo esc_html__( 'Post Snippets', 'post-snippets' );
|
657 |
+
echo '</h2>';
|
658 |
+
// Tabs
|
659 |
+
$active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore
|
660 |
+
$base_url = '?page=post-snippets&tab=';
|
661 |
+
$tabs = array(
|
662 |
+
'snippets' => __( 'Manage Snippets', 'post-snippets' ),
|
663 |
+
'options' => __( 'Options', 'post-snippets' ),
|
664 |
+
'tools' => __( 'Import/Export', 'post-snippets' ),
|
665 |
+
);
|
666 |
+
if ( postsnippets_fs()->is_not_paying() ) {
|
667 |
+
$tabs['upgrade'] = __( 'Upgrade', 'post-snippets' );
|
668 |
+
}
|
669 |
+
echo '<h2 class="nav-tab-wrapper">';
|
670 |
+
foreach ( $tabs as $tab => $title ) {
|
671 |
+
$active = ( $active_tab == $tab ? ' nav-tab-active' : '' );
|
672 |
+
$link = $base_url . $tab;
|
673 |
+
if ( $tab == 'upgrade' ) {
|
674 |
+
$link = postsnippets_fs()->get_upgrade_url();
|
675 |
+
}
|
676 |
+
echo "<a href='" . esc_url( $link ) . "' class='nav-tab " . esc_attr( $active ) . ' tab-' . esc_attr( $tab ) . "'>" . esc_html( $title ) . '</a>';
|
677 |
+
}
|
678 |
+
echo '</h2>';
|
679 |
+
// Tab content
|
680 |
+
|
681 |
+
if ( $active_tab == 'snippets' ) {
|
682 |
+
$this->tabSnippets();
|
683 |
+
} elseif ( $active_tab == 'options' ) {
|
684 |
+
$this->tabOptions();
|
685 |
+
} elseif ( $active_tab == 'tools' ) {
|
686 |
+
$this->tabTools();
|
687 |
+
} else {
|
688 |
+
$this->tabFeatures();
|
689 |
+
}
|
690 |
+
|
691 |
+
// Close it
|
692 |
+
echo '</div>';
|
693 |
+
}
|
694 |
+
|
695 |
+
/**
|
696 |
+
* Tab to Manage Snippets.
|
697 |
+
*
|
698 |
+
* @since Post Snippets 2.0
|
699 |
+
*/
|
700 |
+
private function tabSnippets() {
|
701 |
+
echo '<p class="description post-snippets-documentation-note">';
|
702 |
+
esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
|
703 |
+
echo '</p>';
|
704 |
+
$data = array();
|
705 |
+
echo View::render( 'admin_snippets', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
706 |
+
}
|
707 |
+
|
708 |
+
/**
|
709 |
+
* Tab to set options for the plugin.
|
710 |
+
*
|
711 |
+
* @return void
|
712 |
+
*/
|
713 |
+
private function tabOptions() {
|
714 |
+
echo '<p class="description post-snippets-documentation-note">';
|
715 |
+
esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
|
716 |
+
echo '</p>';
|
717 |
+
$data = array();
|
718 |
+
echo View::render( 'admin_options', $data ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
719 |
+
}
|
720 |
+
|
721 |
+
/**
|
722 |
+
* Tab for Import/Export
|
723 |
+
*
|
724 |
+
* @since Post Snippets 2.0
|
725 |
+
*/
|
726 |
+
private function tabTools() {
|
727 |
+
echo '<p class="description post-snippets-documentation-note">';
|
728 |
+
esc_html_e( 'Click \'Help\' in the top right for the documentation!', 'post-snippets' );
|
729 |
+
echo '</p>';
|
730 |
+
$ie = new ImportExport();
|
731 |
+
// Create header and export html form
|
732 |
+
printf( '<h3>%s</h3>', esc_html__( 'Import/Export', 'post-snippets' ) );
|
733 |
+
printf( '<h4>%s</h4>', esc_html__( 'Export', 'post-snippets' ) );
|
734 |
+
echo '<form method="post">';
|
735 |
+
echo '<p>';
|
736 |
+
esc_html_e( 'Export your snippets for backup or to import them on another site.', 'post-snippets' );
|
737 |
+
echo '</p>';
|
738 |
+
printf( "<input type='submit' class='button' name='postsnippets_export' value='%s' />", esc_html__( 'Export Snippets', 'post-snippets' ) );
|
739 |
+
wp_nonce_field( 'pspro_export_snippets', 'pspro_export_snippets_nonce', false );
|
740 |
+
echo '</form>';
|
741 |
+
// Export logic, and import html form and logic
|
742 |
+
$ie->exportSnippets();
|
743 |
+
echo $ie->importSnippets(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
744 |
+
}
|
745 |
+
|
746 |
+
/**
|
747 |
+
* Tab for Pro features
|
748 |
+
*
|
749 |
+
* @since Post Snippets 2.5.4
|
750 |
+
*/
|
751 |
+
private function tabFeatures() {
|
752 |
+
$features = new Features();
|
753 |
+
echo $features->showFeatures(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
|
754 |
+
}
|
755 |
+
|
756 |
+
/**
|
757 |
+
* Creates a read-only overview page.
|
758 |
+
*
|
759 |
+
* For users with edit_posts capability but without manage_options
|
760 |
+
* capability.
|
761 |
+
*
|
762 |
+
* @since Post Snippets 1.9.7
|
763 |
+
*/
|
764 |
+
public function overviewPage() {
|
765 |
+
// Header
|
766 |
+
echo '<div class="wrap">';
|
767 |
+
echo '<h2>Post Snippets</h2>';
|
768 |
+
echo '<p>';
|
769 |
+
esc_html_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' );
|
770 |
+
echo '</p>';
|
771 |
+
// Form
|
772 |
+
$this->setUserOptions();
|
773 |
+
$render = $this->getUserOptions();
|
774 |
+
echo '<form method="post" action="">';
|
775 |
+
wp_nonce_field( 'post_snippets_user_options', 'post_snippets_user_nonce' );
|
776 |
+
$this->checkbox( __( 'Display rendered snippets', 'post-snippets' ), 'render', $render );
|
777 |
+
$this->submit( 'update-post-snippets-user', __( 'Update', 'post-snippets' ) );
|
778 |
+
echo '</form>';
|
779 |
+
// Snippet List
|
780 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
781 |
+
if ( ! empty( $snippets ) ) {
|
782 |
+
foreach ( $snippets as $key => $snippet ) {
|
783 |
+
echo "<hr style='border: none;border-top:1px dashed #aaa; margin:24px 0;' />";
|
784 |
+
echo '<h3>' . esc_html( $snippet['title'] );
|
785 |
+
if ( $snippet['description'] ) {
|
786 |
+
echo "<span class='description'> " . esc_html( $snippet['description'] ) . '</span>';
|
787 |
+
}
|
788 |
+
echo '</h3>';
|
789 |
+
if ( $snippet['vars'] ) {
|
790 |
+
printf( '<strong>%s:</strong> ' . esc_html( $snippet['vars'] ) . '<br/>', esc_html__( 'Variables', 'post-snippets' ) );
|
791 |
+
}
|
792 |
+
// echo "<strong>Variables:</strong> {$snippet['vars']}<br/>";
|
793 |
+
$options = array();
|
794 |
+
if ( $snippet['shortcode'] ) {
|
795 |
+
array_push( $options, 'Shortcode' );
|
796 |
+
}
|
797 |
+
if ( $snippet['php'] ) {
|
798 |
+
array_push( $options, 'PHP' );
|
799 |
+
}
|
800 |
+
if ( $snippet['wptexturize'] ) {
|
801 |
+
array_push( $options, 'wptexturize' );
|
802 |
+
}
|
803 |
+
if ( $options ) {
|
804 |
+
printf( '<strong>%s:</strong> %s<br/>', esc_html__( 'Options', 'post-snippets' ), esc_html( implode( ', ', $options ) ) );
|
805 |
+
}
|
806 |
+
printf( '<br/><strong>%s:</strong><br/>', esc_html__( 'Snippet', 'post-snippets' ) );
|
807 |
+
|
808 |
+
if ( $render ) {
|
809 |
+
echo do_shortcode( $snippet['snippet'] );
|
810 |
+
} else {
|
811 |
+
echo '<code>';
|
812 |
+
echo esc_html( $snippet['snippet'] );
|
813 |
+
echo '</code>';
|
814 |
+
}
|
815 |
+
}
|
816 |
+
}
|
817 |
+
// Close
|
818 |
+
echo '</div>';
|
819 |
+
}
|
820 |
+
|
821 |
+
// -------------------------------------------------------------------------
|
822 |
+
// Register and callbacks for the options tab
|
823 |
+
// -------------------------------------------------------------------------
|
824 |
+
/**
|
825 |
+
* Register settings for the options tab.
|
826 |
+
*
|
827 |
+
* @return void
|
828 |
+
*/
|
829 |
+
protected function registerSettings() {
|
830 |
+
$this->settings = get_option( \PostSnippets::SETTINGS );
|
831 |
+
register_setting( \PostSnippets::SETTINGS, \PostSnippets::SETTINGS );
|
832 |
+
add_settings_section(
|
833 |
+
'general_section',
|
834 |
+
__( 'General', 'post-snippets' ),
|
835 |
+
null,
|
836 |
+
'post-snippets'
|
837 |
+
);
|
838 |
+
add_settings_field(
|
839 |
+
'exclude_from_custom_editors',
|
840 |
+
__( 'Exclude from Custom Editors', 'post-snippets' ),
|
841 |
+
array( $this, 'cbExcludeFromCustomEditors' ),
|
842 |
+
'post-snippets',
|
843 |
+
'general_section',
|
844 |
+
array(
|
845 |
+
'id' => 'exclude_from_custom_editors',
|
846 |
+
'label_for' => 'exclude_from_custom_editors',
|
847 |
+
'description' => __( 'Checking this only includes Post Snippets on standard WordPress post editing screens.', 'post-snippets' ),
|
848 |
+
)
|
849 |
+
);
|
850 |
+
}
|
851 |
+
|
852 |
+
/**
|
853 |
+
* Callback for HTML generator for exlusion of custom editors.
|
854 |
+
*
|
855 |
+
* @param array $args
|
856 |
+
*
|
857 |
+
* @return void
|
858 |
+
*/
|
859 |
+
public function cbExcludeFromCustomEditors( $args ) {
|
860 |
+
$checked = ( isset( $this->settings[ $args['id'] ] ) ? $this->settings[ $args['id'] ] : false );
|
861 |
+
echo "<input type='checkbox' id='" . esc_attr( $args['id'] ) . "' ";
|
862 |
+
echo "name='" . esc_attr( \PostSnippets::SETTINGS . '[' . $args['id'] . ']' ) . "'" . "value='1' ";
|
863 |
+
if ( $checked ) {
|
864 |
+
echo 'checked ';
|
865 |
+
}
|
866 |
+
echo ' />';
|
867 |
+
echo "<span class='description'>" . esc_html( $args['description'] ) . '</span>';
|
868 |
+
}
|
869 |
+
|
870 |
+
// -------------------------------------------------------------------------
|
871 |
+
// HTML and Form element methods for Snippets form
|
872 |
+
// -------------------------------------------------------------------------
|
873 |
+
/**
|
874 |
+
* Checkbox.
|
875 |
+
*
|
876 |
+
* Renders the HTML for an input checkbox.
|
877 |
+
*
|
878 |
+
* @param string $label The label rendered to screen
|
879 |
+
* @param string $name The unique name and id to identify the input
|
880 |
+
* @param boolean $checked If the input is checked or not
|
881 |
+
*
|
882 |
+
* @return void
|
883 |
+
*/
|
884 |
+
public static function checkbox( $label, $name, $checked ) {
|
885 |
+
echo '<label for="' . esc_attr( $name ) . '">';
|
886 |
+
printf( '<input type="checkbox" name="%1$s" id="%1$s" value="true"', esc_attr( $name ) );
|
887 |
+
if ( $checked ) {
|
888 |
+
echo ' checked';
|
889 |
+
}
|
890 |
+
echo ' />';
|
891 |
+
echo esc_html( $label ) . '</label><br/>';
|
892 |
+
}
|
893 |
+
|
894 |
+
/**
|
895 |
+
* Submit.
|
896 |
+
*
|
897 |
+
* Renders the HTML for a submit button.
|
898 |
+
*
|
899 |
+
* @since Post Snippets 1.9.7
|
900 |
+
*
|
901 |
+
* @param string $name The name that identifies the button on submit
|
902 |
+
* @param string $label The label rendered on the button
|
903 |
+
* @param string $class Optional. Button class. Default: button-primary
|
904 |
+
* @param boolean $wrap Optional. Wrap in a submit div. Default: true
|
905 |
+
*
|
906 |
+
* @return void
|
907 |
+
*/
|
908 |
+
public static function submit(
|
909 |
+
$name,
|
910 |
+
$label,
|
911 |
+
$class = 'button-primary',
|
912 |
+
$wrap = true
|
913 |
+
) {
|
914 |
+
|
915 |
+
if ( $wrap ) {
|
916 |
+
|
917 |
+
echo "<div class=\"submit\"><input type=submit name='" . esc_attr( $name ) . "' value='" . esc_attr( $label ) . "' class='" . esc_attr( $class ) . "' /> </div>";
|
918 |
+
return;
|
919 |
+
|
920 |
+
}
|
921 |
+
|
922 |
+
echo "<input type=submit name='" . esc_attr( $name ) . "' value='" . esc_attr( $label ) . "' class='" . esc_attr( $class ) . "' /> ";
|
923 |
+
|
924 |
+
}
|
925 |
+
|
926 |
+
/**
|
927 |
+
*
|
928 |
+
* Show newsletter opt-in, only in Post Snippets.
|
929 |
+
* Not on Pro features tab/page.
|
930 |
+
* Not when user selected to Hide opt-in.
|
931 |
+
*
|
932 |
+
* @since 2.5.4
|
933 |
+
*/
|
934 |
+
public function admin_notice_newsletter() {
|
935 |
+
// Hide newsletter opt-in if option is true
|
936 |
+
if ( get_option( 'ps_hide_admin_notice_newsletter' ) == true ) {
|
937 |
+
return;
|
938 |
+
}
|
939 |
+
// Set option if "hide" button click detected (custom querystring value set to 1).
|
940 |
+
|
941 |
+
if ( ! empty( $_REQUEST['ps-dismiss-newsletter-nag'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
942 |
+
update_option( 'ps_hide_admin_notice_newsletter', true );
|
943 |
+
return;
|
944 |
+
}
|
945 |
+
|
946 |
+
// Show newsletter notice.
|
947 |
+
|
948 |
+
if ( get_current_screen()->id == 'settings_page_post-snippets/post-snippets' ) {
|
949 |
+
$active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
950 |
+
if ( $active_tab != 'features' ) {
|
951 |
+
include_once PS_PATH . '/views/admin_notice_newsletter.php';
|
952 |
+
}
|
953 |
+
}
|
954 |
+
|
955 |
+
}
|
956 |
+
|
957 |
+
/**
|
958 |
+
*
|
959 |
+
* Show 'Get started' admin notice', everywhere.
|
960 |
+
* Not when user already clicked or dismissed.
|
961 |
+
*
|
962 |
+
* @since 2.5.4
|
963 |
+
*/
|
964 |
+
public function admin_notice_get_started() {
|
965 |
+
// Hide newsletter opt-in if option is true
|
966 |
+
if ( get_option( 'ps_hide_admin_notice_get_started' ) == true ) {
|
967 |
+
return;
|
968 |
+
}
|
969 |
+
// Set option if "hide" button click detected (custom query string value set to 1).
|
970 |
+
|
971 |
+
if ( ! empty( $_REQUEST['ps-dismiss-get-started-nag'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
972 |
+
update_option( 'ps_hide_admin_notice_get_started', true );
|
973 |
+
return;
|
974 |
+
}
|
975 |
+
|
976 |
+
// Show newsletter notice.
|
977 |
+
|
978 |
+
if ( strpos( get_current_screen()->id, '/post-snippets' ) == false ) {
|
979 |
+
$active_tab = ( isset( $_GET['tab'] ) ? sanitize_key( $_GET['tab'] ) : 'snippets' ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
|
980 |
+
if ( $active_tab != 'features' ) {
|
981 |
+
include_once PS_PATH . '/views/admin_notice_get_started.php';
|
982 |
+
}
|
983 |
+
}
|
984 |
+
|
985 |
+
}
|
986 |
+
|
987 |
+
/**
|
988 |
+
* Save Updated sorting
|
989 |
+
*/
|
990 |
+
/*
|
991 |
+
public function update_snippets_order() {
|
992 |
+
if ( empty( $_POST['order'] ) || ! is_array( $_POST['order'] ) ) {
|
993 |
+
wp_send_json_error( 'order data not received' );
|
994 |
+
}
|
995 |
+
$capability = $this->get_allowed_capability();
|
996 |
+
if ( ! current_user_can( $capability ) ) {
|
997 |
+
wp_send_json_error( 'permission denied' );
|
998 |
+
}
|
999 |
+
$orders = array_map( 'sanitize_key', array_map( 'intval', $_POST['order'] ) );
|
1000 |
+
$snippets = get_option( 'post_snippets_options', array() );
|
1001 |
+
if ( empty( $snippets ) ) {
|
1002 |
+
wp_send_json_error( 'snippets empty' );
|
1003 |
+
}
|
1004 |
+
$updated_order = array();
|
1005 |
+
foreach ( $orders as $order ) {
|
1006 |
+
if ( isset( $snippets[ $order ] ) ) {
|
1007 |
+
$updated_order[] = $snippets[ $order ];
|
1008 |
+
}
|
1009 |
+
}
|
1010 |
+
update_option( 'post_snippets_options', $updated_order );
|
1011 |
+
wp_send_json_success( 'success' );
|
1012 |
+
}
|
1013 |
+
*/
|
1014 |
+
|
1015 |
+
/**
|
1016 |
+
* Save Updated title
|
1017 |
+
*/
|
1018 |
+
public function update_post_snippet_title() {
|
1019 |
+
if ( ! isset( $_POST['key'] ) || empty( $_POST['title'] ) ) {
|
1020 |
+
wp_send_json_error();
|
1021 |
+
}
|
1022 |
+
if ( ! isset( $_POST['save_title_nonce'] ) || !wp_verify_nonce( sanitize_key( $_POST['save_title_nonce'] ), 'ps-save-title-nonce' ) || !current_user_can( 'manage_options' ) ) {
|
1023 |
+
wp_send_json_error();
|
1024 |
+
}
|
1025 |
+
|
1026 |
+
$capability = $this->get_allowed_capability();
|
1027 |
+
if ( ! current_user_can( $capability ) ) {
|
1028 |
+
wp_send_json_error( 'permission denied' );
|
1029 |
+
}
|
1030 |
+
$pkey = intval( sanitize_text_field( wp_unslash( $_POST['key'] ) ) );
|
1031 |
+
$title = sanitize_text_field( wp_unslash( $_POST['title'] ) );
|
1032 |
+
$snippets = get_option( 'post_snippets_options', array() );
|
1033 |
+
if ( empty( $snippets ) ) {
|
1034 |
+
wp_send_json_error();
|
1035 |
+
}
|
1036 |
+
|
1037 |
+
if ( isset( $snippets[ $pkey ] ) && $snippets[ $pkey ]['title'] == $title ) {
|
1038 |
+
|
1039 |
+
wp_send_json_error( __( 'You have not made any changes to the snippet title.', 'post-snippets' ) );
|
1040 |
+
}
|
1041 |
+
|
1042 |
+
foreach ( $snippets as $key => $snippet ) {
|
1043 |
+
if ( $snippet['title'] == $title ) {
|
1044 |
+
wp_send_json_error( __( 'Duplicate title is not allowed. Please use different title for each snippets.', 'post-snippets' ) );
|
1045 |
+
}
|
1046 |
+
}
|
1047 |
+
|
1048 |
+
if ( isset( $snippets[ $pkey ] ) ) {
|
1049 |
+
$snippets[ $pkey ]['title'] = $title;
|
1050 |
+
update_option( 'post_snippets_options', $snippets );
|
1051 |
+
}
|
1052 |
+
|
1053 |
+
wp_send_json_success( $title );
|
1054 |
+
}
|
1055 |
+
|
1056 |
+
public function update_post_snippet() {
|
1057 |
+
if ( ! isset( $_POST['key'] ) ) {
|
1058 |
+
wp_send_json_error();
|
1059 |
+
}
|
1060 |
+
if ( ! isset( $_POST['update_snippet_nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['update_snippet_nonce'] ), 'ps-update-snippet-nonce' ) || !current_user_can( 'manage_options' ) ) {
|
1061 |
+
wp_send_json_error();
|
1062 |
+
}
|
1063 |
+
|
1064 |
+
$capability = $this->get_allowed_capability();
|
1065 |
+
if ( ! current_user_can( $capability ) ) {
|
1066 |
+
wp_send_json_error( 'permission denied' );
|
1067 |
+
}
|
1068 |
+
$key = intval( sanitize_text_field( wp_unslash ( $_POST['key'] ) ) );
|
1069 |
+
$snippets = get_option( 'post_snippets_options', array() );
|
1070 |
+
if ( empty( $snippets ) ) {
|
1071 |
+
wp_send_json_error();
|
1072 |
+
}
|
1073 |
+
$title = '';
|
1074 |
+
if ( isset( $_POST['title'] ) ) {
|
1075 |
+
$title = sanitize_text_field( wp_unslash( $_POST['title'] ) );
|
1076 |
+
}
|
1077 |
+
|
1078 |
+
if ( isset( $snippets[ $key ] ) ) {
|
1079 |
+
$snippets[ $key ]['description'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['description'] ?? '' ) ) );
|
1080 |
+
$snippets[ $key ]['snippet'] = stripslashes( wp_kses_post( wp_unslash( $_POST['snippet'] ?? '' ) ) );
|
1081 |
+
$snippets[ $key ]['vars'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['vars'] ?? '' ) ) );
|
1082 |
+
$snippets[ $key ]['shortcode'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['shortcode'] ?? '' ) ) );
|
1083 |
+
$snippets[ $key ]['php'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['php'] ?? '' ) ) );
|
1084 |
+
$snippets[ $key ]['wptexturize'] = stripslashes( sanitize_text_field( wp_unslash( $_POST['wptexturize'] ?? '' ) ) );
|
1085 |
+
if ( ! empty( $title ) ) {
|
1086 |
+
$snippets[ $key ]['title'] = $title;
|
1087 |
+
}
|
1088 |
+
update_option( 'post_snippets_options', $snippets );
|
1089 |
+
}
|
1090 |
+
|
1091 |
+
wp_send_json_success( $title );
|
1092 |
+
}
|
1093 |
+
|
1094 |
+
public function get_allowed_capability() {
|
1095 |
+
$capability = 'manage_options';
|
1096 |
+
|
1097 |
+
if ( defined( 'POST_SNIPPETS_ALLOW_EDIT_POSTS' ) && current_user_can( 'edit_posts' ) ) {
|
1098 |
+
$capability = 'edit_posts';
|
1099 |
+
}
|
1100 |
+
|
1101 |
+
return $capability;
|
1102 |
+
}
|
1103 |
+
|
1104 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/PostSnippets/Features.php
CHANGED
@@ -5,7 +5,6 @@ namespace PostSnippets;
|
|
5 |
/**
|
6 |
* Post Snippets Features.
|
7 |
*
|
8 |
-
*
|
9 |
* @author GreenTreeLabs <info at postsnippets dot com>
|
10 |
* @link https://www.postsnippets.com
|
11 |
*/
|
@@ -15,7 +14,7 @@ class Features {
|
|
15 |
public function showFeatures() {
|
16 |
$html = '';
|
17 |
ob_start();
|
18 |
-
?>
|
19 |
<div class="wrap">
|
20 |
<div id="pt-features">
|
21 |
<div id="pt-features-content">
|
@@ -31,11 +30,11 @@ class Features {
|
|
31 |
</div>
|
32 |
<!-- .pt-features -->
|
33 |
</div><!-- .wrap -->
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
|
39 |
-
|
40 |
}
|
41 |
}
|
5 |
/**
|
6 |
* Post Snippets Features.
|
7 |
*
|
|
|
8 |
* @author GreenTreeLabs <info at postsnippets dot com>
|
9 |
* @link https://www.postsnippets.com
|
10 |
*/
|
14 |
public function showFeatures() {
|
15 |
$html = '';
|
16 |
ob_start();
|
17 |
+
?>
|
18 |
<div class="wrap">
|
19 |
<div id="pt-features">
|
20 |
<div id="pt-features-content">
|
30 |
</div>
|
31 |
<!-- .pt-features -->
|
32 |
</div><!-- .wrap -->
|
33 |
+
<?php
|
34 |
|
35 |
+
$html .= ob_get_contents();
|
36 |
+
ob_end_clean();
|
37 |
|
38 |
+
return $html;
|
39 |
}
|
40 |
}
|
src/PostSnippets/Help.php
CHANGED
@@ -1,114 +1,109 @@
|
|
1 |
<?php
|
|
|
2 |
namespace PostSnippets;
|
3 |
|
4 |
/**
|
5 |
* Handles the plugin help screen.
|
6 |
-
*
|
7 |
*/
|
8 |
-
class Help
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
add_action('load-'.$optionPage, array(&$this, 'tabs'));
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
}
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
}
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
$screen = get_current_screen();
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
}
|
114 |
}
|
1 |
<?php
|
2 |
+
|
3 |
namespace PostSnippets;
|
4 |
|
5 |
/**
|
6 |
* Handles the plugin help screen.
|
|
|
7 |
*/
|
8 |
+
class Help {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Define actions.
|
12 |
+
*
|
13 |
+
* @param string
|
14 |
+
* @return void
|
15 |
+
*/
|
16 |
+
public function __construct( $optionPage ) {
|
17 |
+
add_action( 'load-' . $optionPage, array( &$this, 'tabs' ) );
|
|
|
18 |
|
19 |
+
add_action( 'load-post.php', array( &$this, 'postEditor' ) );
|
20 |
+
add_action( 'load-post-new.php', array( &$this, 'postEditor' ) );
|
21 |
+
}
|
22 |
|
23 |
+
/**
|
24 |
+
* Load the post editor tab in the admin_head filter.
|
25 |
+
*
|
26 |
+
* We load the tab that will integrate in the post editor help menu via the
|
27 |
+
* admin_head hook, as we are not otherwise able to make it get ordered
|
28 |
+
* below the native help tabs.
|
29 |
+
*
|
30 |
+
* @return void.
|
31 |
+
*/
|
32 |
+
public function postEditor() {
|
33 |
+
add_action( 'admin_head', array( &$this, 'postEditorTabs' ) );
|
34 |
+
}
|
|
|
35 |
|
36 |
+
/**
|
37 |
+
* Setup the help tabs and sidebar.
|
38 |
+
*
|
39 |
+
* @return void
|
40 |
+
*/
|
41 |
+
public function tabs() {
|
42 |
+
$screen = get_current_screen();
|
43 |
+
$screen->set_help_sidebar( $this->content( 'help/sidebar' ) );
|
44 |
+
$screen->add_help_tab(
|
45 |
+
array(
|
46 |
+
'id' => 'usage-plugin-help',
|
47 |
+
'title' => __( 'Usage', 'post-snippets' ),
|
48 |
+
'content' => $this->content( 'help/usage' ),
|
49 |
+
)
|
50 |
+
);
|
51 |
+
$screen->add_help_tab(
|
52 |
+
array(
|
53 |
+
'id' => 'post-plugin-help',
|
54 |
+
'title' => __( 'Post Editor', 'post-snippets' ),
|
55 |
+
'content' => $this->content( 'help/post' ),
|
56 |
+
)
|
57 |
+
);
|
58 |
+
if ( ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
59 |
+
$screen->add_help_tab(
|
60 |
+
array(
|
61 |
+
'id' => 'php-plugin-help',
|
62 |
+
'title' => __( 'PHP', 'post-snippets' ),
|
63 |
+
'content' => $this->content( 'help/php' ),
|
64 |
+
)
|
65 |
+
);
|
66 |
+
}
|
67 |
+
$screen->add_help_tab(
|
68 |
+
array(
|
69 |
+
'id' => 'advanced-plugin-help',
|
70 |
+
'title' => __( 'Advanced', 'post-snippets' ),
|
71 |
+
'content' => $this->content( 'help/advanced' ),
|
72 |
+
)
|
73 |
+
);
|
74 |
+
$screen->add_help_tab(
|
75 |
+
array(
|
76 |
+
'id' => 'filters-plugin-help',
|
77 |
+
'title' => __( 'Filters', 'post-snippets' ),
|
78 |
+
'content' => $this->content( 'help/filters' ),
|
79 |
+
)
|
80 |
+
);
|
81 |
+
}
|
|
|
82 |
|
83 |
+
/**
|
84 |
+
* Setup the help tab for the post editor.
|
85 |
+
*
|
86 |
+
* @return void
|
87 |
+
*/
|
88 |
+
public function postEditorTabs() {
|
89 |
+
$screen = get_current_screen();
|
|
|
90 |
|
91 |
+
$screen->add_help_tab(
|
92 |
+
array(
|
93 |
+
'id' => 'postsnippets-plugin-help',
|
94 |
+
'title' => 'Post Snippets',
|
95 |
+
'content' => $this->content( 'help/post' ),
|
96 |
+
)
|
97 |
+
);
|
98 |
+
}
|
99 |
|
100 |
+
/**
|
101 |
+
* Get the content for a help tab
|
102 |
+
*
|
103 |
+
* @param string $tab
|
104 |
+
* @return string
|
105 |
+
*/
|
106 |
+
private function content( $tab ) {
|
107 |
+
return View::render( $tab );
|
108 |
+
}
|
|
|
109 |
}
|
src/PostSnippets/ImportExport.php
CHANGED
@@ -5,225 +5,253 @@ namespace PostSnippets;
|
|
5 |
* Post Snippets I/O.
|
6 |
*
|
7 |
* Class to handle import and export of Snippets.
|
8 |
-
*
|
9 |
*/
|
10 |
-
class ImportExport
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
229 |
}
|
5 |
* Post Snippets I/O.
|
6 |
*
|
7 |
* Class to handle import and export of Snippets.
|
|
|
8 |
*/
|
9 |
+
class ImportExport {
|
10 |
+
|
11 |
+
protected static $FILE_ZIP;
|
12 |
+
const FILE_CFG = 'post-snippets-export.cfg';
|
13 |
+
|
14 |
+
private $downloadUrl;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Export Snippets.
|
18 |
+
*
|
19 |
+
* Check if an export file shall be created, or if a download url should be
|
20 |
+
* pushed to the footer. Also checks for old export files laying around and
|
21 |
+
* deletes them (for security).
|
22 |
+
*
|
23 |
+
* @return void
|
24 |
+
*/
|
25 |
+
public function exportSnippets() {
|
26 |
+
self::set_export_name();
|
27 |
+
if ( isset( $_POST['postsnippets_export'] ) ) {
|
28 |
+
check_admin_referer( 'pspro_export_snippets', 'pspro_export_snippets_nonce' );
|
29 |
+
if( !current_user_can( 'manage_options' ) ){
|
30 |
+
return;
|
31 |
+
}
|
32 |
+
$url = $this->createExportFile();
|
33 |
+
if ( $url ) {
|
34 |
+
$this->downloadUrl = $url;
|
35 |
+
add_action(
|
36 |
+
'admin_footer',
|
37 |
+
array( &$this, 'psnippetsFooter' ),
|
38 |
+
10000
|
39 |
+
);
|
40 |
+
} else {
|
41 |
+
echo esc_html__( 'Error: ', 'post-snippets' ) . esc_url( $url );
|
42 |
+
}
|
43 |
+
} else {
|
44 |
+
// Check if there is any old export files to delete
|
45 |
+
$dir = wp_upload_dir();
|
46 |
+
$upload_dir = $dir['basedir'] . '/';
|
47 |
+
chdir( $upload_dir );
|
48 |
+
if ( file_exists( './' . self::$FILE_ZIP ) ) {
|
49 |
+
unlink( './' . self::$FILE_ZIP );
|
50 |
+
}
|
51 |
+
}
|
52 |
+
}
|
53 |
+
|
54 |
+
/**
|
55 |
+
* Handles uploading of post snippets archive and import the snippets.
|
56 |
+
*
|
57 |
+
* @uses wp_handle_upload() in wp-admin/includes/file.php
|
58 |
+
* @return string HTML to handle the import
|
59 |
+
*/
|
60 |
+
public function importSnippets() {
|
61 |
+
$import =
|
62 |
+
'<br/><br/><strong>' .
|
63 |
+
esc_html__( 'Import', 'post-snippets' ) .
|
64 |
+
'</strong><br/>';
|
65 |
+
if ( ! isset( $_FILES['postsnippets_import_file'] )
|
66 |
+
|| empty( $_FILES['postsnippets_import_file'] )
|
67 |
+
) {
|
68 |
+
$import .=
|
69 |
+
'<p>' . esc_html__( 'Import snippets from a post-snippets-export.zip file. Imported sinppets will get added at the bottom.', 'post-snippets' ) .
|
70 |
+
'</p>';
|
71 |
+
$import .=
|
72 |
+
'<p>' . esc_html__( 'Please make sure no snippets have duplicate titles.', 'post-snippets' ) .
|
73 |
+
'</p>';
|
74 |
+
$import .= '<form method="post" enctype="multipart/form-data">';
|
75 |
+
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
76 |
+
$import .= '<input type="hidden" name="action" value="wp_handle_upload"/>';
|
77 |
+
$import .=
|
78 |
+
'<input type="submit" class="button" value="' .
|
79 |
+
__( 'Import Snippets', 'post-snippets' ) . '"/>';
|
80 |
+
$import .= wp_nonce_field( 'pspro_import_snippets', 'pspro_import_snippets_nonce', false, false );
|
81 |
+
$import .= '</form>';
|
82 |
+
} else {
|
83 |
+
check_admin_referer( 'pspro_import_snippets', 'pspro_import_snippets_nonce' );
|
84 |
+
|
85 |
+
if( !current_user_can( 'manage_options' ) ){
|
86 |
+
|
87 |
+
$import .=
|
88 |
+
'<p><strong>' .
|
89 |
+
esc_html__( 'Only Admins can import snippets', 'post-snippets' ) .
|
90 |
+
'</strong></p>';
|
91 |
+
|
92 |
+
return $import;
|
93 |
+
}
|
94 |
+
|
95 |
+
$file = wp_handle_upload( $_FILES['postsnippets_import_file'] );
|
96 |
+
|
97 |
+
if ( isset( $file['file'] ) && ! is_wp_error( $file ) ) {
|
98 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
99 |
+
$zip = new \PclZip( $file['file'] );
|
100 |
+
$dir = wp_upload_dir();
|
101 |
+
$upload_dir = $dir['basedir'] . '/';
|
102 |
+
chdir( $upload_dir );
|
103 |
+
$unzipped = $zip->extract();
|
104 |
+
|
105 |
+
if ( $unzipped[0]['stored_filename'] == self::FILE_CFG
|
106 |
+
&& $unzipped[0]['status'] == 'ok'
|
107 |
+
) {
|
108 |
+
// Delete the uploaded archive
|
109 |
+
unlink( $file['file'] );
|
110 |
+
|
111 |
+
$snippets = file_get_contents(
|
112 |
+
$upload_dir . self::FILE_CFG
|
113 |
+
);
|
114 |
+
|
115 |
+
if ( $snippets ) {
|
116 |
+
$snippets = apply_filters(
|
117 |
+
'post_snippets_import',
|
118 |
+
$snippets
|
119 |
+
);
|
120 |
+
|
121 |
+
$imported_snippets = maybe_unserialize( $snippets );
|
122 |
+
$current_snippets = get_option( \PostSnippets::OPTION_KEY );
|
123 |
+
|
124 |
+
if ( empty( $current_snippets ) ) {
|
125 |
+
$current_snippets = array();
|
126 |
+
}
|
127 |
+
|
128 |
+
$all_snippets = $current_snippets;
|
129 |
+
$duplicate_title_exist = false;
|
130 |
+
$empty_title = false;
|
131 |
+
$duplicate_title = '';
|
132 |
+
foreach ( $imported_snippets as $snippet ) {
|
133 |
+
foreach ( $snippet as $key => $value ) {
|
134 |
+
$snippet[ $key ] = sanitize_text_field( $snippet[ $key ] );
|
135 |
+
}
|
136 |
+
if ( empty( $snippet['title'] ) ) {
|
137 |
+
$empty_title = true;
|
138 |
+
break;
|
139 |
+
}
|
140 |
+
// $snippet['title'] = sanitize_text_field( $snippet['title'] );
|
141 |
+
$all_snippets[] = $snippet;
|
142 |
+
foreach ( $current_snippets as $current ) {
|
143 |
+
if ( $current['title'] == $snippet['title'] ) {
|
144 |
+
$duplicate_title = $snippet['title'];
|
145 |
+
$duplicate_title_exist = true;
|
146 |
+
break;
|
147 |
+
}
|
148 |
+
}
|
149 |
+
}
|
150 |
+
|
151 |
+
if ( $empty_title ) {
|
152 |
+
$import .=
|
153 |
+
'<p><strong>' .
|
154 |
+
esc_html__( 'Snippets cannot have empty Titles', 'post-snippets' ) .
|
155 |
+
'</strong></p>';
|
156 |
+
} elseif ( $duplicate_title_exist == false ) {
|
157 |
+
update_option( \PostSnippets::OPTION_KEY, $all_snippets );
|
158 |
+
$import .=
|
159 |
+
'<p><strong>' .
|
160 |
+
esc_html__( 'Snippets successfully imported.', 'post-snippets' ) .
|
161 |
+
'</strong></p>';
|
162 |
+
} else {
|
163 |
+
$import .=
|
164 |
+
'<p><strong>' .
|
165 |
+
esc_html__( 'All the snippets should have unique titles. The snippet in your import file with title "' . $duplicate_title . '" already exists in your site.', 'post-snippets' ) .
|
166 |
+
'</strong></p>';
|
167 |
+
}
|
168 |
+
}
|
169 |
+
|
170 |
+
// Delete the snippet file
|
171 |
+
unlink( './' . self::FILE_CFG );
|
172 |
+
|
173 |
+
} else {
|
174 |
+
$import .=
|
175 |
+
'<p><strong>' .
|
176 |
+
esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
|
177 |
+
' ' .
|
178 |
+
esc_html__( 'Unzipping failed.', 'post-snippets' ) .
|
179 |
+
'</strong></p>';
|
180 |
+
}
|
181 |
+
} else {
|
182 |
+
if ( $file['error'] || is_wp_error( $file ) ) {
|
183 |
+
$import .=
|
184 |
+
'<p><strong>' .
|
185 |
+
esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
|
186 |
+
' ' .
|
187 |
+
$file['error'] . '</strong></p>';
|
188 |
+
} else {
|
189 |
+
$import .=
|
190 |
+
'<p><strong>' .
|
191 |
+
esc_html__( 'Snippets could not be imported:', 'post-snippets' ) .
|
192 |
+
' ' .
|
193 |
+
esc_html__( 'Upload failed.', 'post-snippets' ) .
|
194 |
+
'</strong></p>';
|
195 |
+
}
|
196 |
+
}
|
197 |
+
}
|
198 |
+
return $import;
|
199 |
+
}
|
200 |
+
|
201 |
+
/**
|
202 |
+
* Create a zipped filed containing all Post Snippets, for export.
|
203 |
+
*
|
204 |
+
* @return string URL to the exported snippets
|
205 |
+
*/
|
206 |
+
private function createExportFile() {
|
207 |
+
$snippets = maybe_serialize( get_option( \PostSnippets::OPTION_KEY ) );
|
208 |
+
$snippets = apply_filters( 'post_snippets_export', $snippets );
|
209 |
+
$dir = wp_upload_dir();
|
210 |
+
$upload_dir = $dir['basedir'] . '/';
|
211 |
+
$upload_url = $dir['baseurl'] . '/';
|
212 |
+
|
213 |
+
// Open a file stream and write the serialized options to it.
|
214 |
+
if ( ! $handle = fopen( $upload_dir . './' . self::FILE_CFG, 'w' ) ) {
|
215 |
+
die();
|
216 |
+
}
|
217 |
+
if ( ! fwrite( $handle, $snippets ) ) {
|
218 |
+
die();
|
219 |
+
}
|
220 |
+
fclose( $handle );
|
221 |
+
|
222 |
+
// Create a zip archive
|
223 |
+
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
|
224 |
+
chdir( $upload_dir );
|
225 |
+
$zip = new \PclZip( './' . self::$FILE_ZIP );
|
226 |
+
$zipped = $zip->create( './' . self::FILE_CFG );
|
227 |
+
|
228 |
+
// Delete the snippet file
|
229 |
+
unlink( './' . self::FILE_CFG );
|
230 |
+
|
231 |
+
if ( ! $zipped ) {
|
232 |
+
return false;
|
233 |
+
}
|
234 |
+
|
235 |
+
return $upload_url . './' . self::$FILE_ZIP;
|
236 |
+
}
|
237 |
+
|
238 |
+
/**
|
239 |
+
* Set export file name
|
240 |
+
*/
|
241 |
+
public static function set_export_name() {
|
242 |
+
$date_part = date( 'Y-m-d' );
|
243 |
+
self::$FILE_ZIP = "post-snippets-export-{$date_part}.zip";
|
244 |
+
}
|
245 |
+
|
246 |
+
/**
|
247 |
+
* Generates the javascript to trigger the download of the file.
|
248 |
+
*
|
249 |
+
* @return void
|
250 |
+
*/
|
251 |
+
public function psnippetsFooter() {
|
252 |
+
echo '<script type="text/javascript">
|
253 |
+
document.location = \'' . esc_js( $this->downloadUrl ) . '\';
|
254 |
+
</script>';
|
255 |
+
// echo $export;
|
256 |
+
}
|
257 |
}
|
src/PostSnippets/Shortcode.php
CHANGED
@@ -3,107 +3,103 @@ namespace PostSnippets;
|
|
3 |
|
4 |
/**
|
5 |
* Shortcode Handling.
|
6 |
-
*
|
7 |
*/
|
8 |
-
class Shortcode
|
9 |
-
{
|
10 |
-
public function __construct()
|
11 |
-
{
|
12 |
-
$this->create();
|
13 |
-
}
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
public function create()
|
19 |
-
{
|
20 |
-
$snippets = get_option(\PostSnippets::OPTION_KEY);
|
21 |
-
if (!empty($snippets)) {
|
22 |
-
foreach ($snippets as $snippet) {
|
23 |
-
// If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
|
24 |
-
if (isset($snippet['shortcode']) && $snippet['shortcode'] && !empty($snippet['snippet'])) {
|
25 |
-
$vars = explode(",", $snippet['vars']);
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
}
|
33 |
|
34 |
-
|
35 |
-
$texturize = isset($snippet[
|
36 |
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
$short_atts = shortcode_atts( $default_atts, $atts );
|
42 |
extract( $short_atts );
|
43 |
-
foreach(array_keys( $default_atts ) as $key) {
|
44 |
-
$attributes[$key] =
|
45 |
-
isset(${"$key"}) ? ${"$key"} :
|
46 |
-
(isset($short_atts[$key]) ? $short_atts[$key] : null);
|
47 |
}
|
48 |
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
$generated_content = $snippet[
|
55 |
-
|
56 |
// $snippet = str_replace("&", "&", $snippet);
|
57 |
-
|
58 |
-
|
59 |
}
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
}
|
100 |
|
101 |
-
|
102 |
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
|
107 |
-
|
108 |
-
|
109 |
}
|
3 |
|
4 |
/**
|
5 |
* Shortcode Handling.
|
|
|
6 |
*/
|
7 |
+
class Shortcode {
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
public function __construct() {
|
10 |
+
$this->create();
|
11 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
+
/**
|
14 |
+
* Create the functions for shortcodes dynamically and register them
|
15 |
+
*/
|
16 |
+
public function create() {
|
17 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
18 |
+
if ( ! empty( $snippets ) ) {
|
19 |
+
foreach ( $snippets as $snippet ) {
|
20 |
+
// If shortcode is enabled for the snippet, and a snippet has been entered, register it as a shortcode.
|
21 |
+
if ( isset( $snippet['shortcode'] ) && $snippet['shortcode'] && ! empty( $snippet['snippet'] ) ) {
|
22 |
+
$vars = explode( ',', $snippet['vars'] );
|
23 |
+
|
24 |
+
$default_atts = array();
|
25 |
+
foreach ( $vars as $var ) {
|
26 |
+
$attribute = explode( '=', $var );
|
27 |
+
$default_value = ( count( $attribute ) > 1 ) ? $attribute[1] : '';
|
28 |
+
$default_atts[ $attribute[0] ] = $default_value;
|
29 |
}
|
30 |
|
31 |
+
// Get the wptexturize setting
|
32 |
+
$texturize = isset( $snippet['wptexturize'] ) ? $snippet['wptexturize'] : false;
|
33 |
|
34 |
+
add_shortcode(
|
35 |
+
$snippet['title'],
|
36 |
+
function ( $atts, $content = null ) use ( $snippet, $texturize, $default_atts ) {
|
37 |
|
38 |
$short_atts = shortcode_atts( $default_atts, $atts );
|
39 |
extract( $short_atts );
|
40 |
+
foreach ( array_keys( $default_atts ) as $key ) {
|
41 |
+
$attributes[ $key ] =
|
42 |
+
isset( ${"$key"} ) ? ${"$key"} :
|
43 |
+
( isset( $short_atts[ $key ] ) ? $short_atts[ $key ] : null );
|
44 |
}
|
45 |
|
46 |
+
// $attributes = compact( array_keys( $default_atts ) );
|
47 |
+
// Add enclosed content if available to the attributes array
|
48 |
+
if ( $content != null ) {
|
49 |
+
$attributes['content'] = $content;
|
50 |
+
}
|
51 |
+
$generated_content = $snippet['snippet'];
|
52 |
+
// Disables auto conversion from & to & as that should be done in snippet, not code (destroys php etc).
|
53 |
// $snippet = str_replace("&", "&", $snippet);
|
54 |
+
foreach ( $attributes as $key => $val ) {
|
55 |
+
$generated_content = str_replace( '{' . $key . '}', $val, $generated_content );
|
56 |
}
|
57 |
|
58 |
+
// There might be the case that a snippet contains
|
59 |
+
// the post snippets reserved variable {content} to
|
60 |
+
// capture the content in enclosed shortcodes, but
|
61 |
+
// the shortcode is used without enclosing it. To
|
62 |
+
// avoid outputting {content} as part of the string
|
63 |
+
// lets remove possible occurences.
|
64 |
+
$generated_content = str_replace( '{content}', '', $generated_content );
|
65 |
|
66 |
+
// Handle PHP shortcodes
|
67 |
+
$php = $snippet['php'];
|
68 |
+
if ( $php == true ) {
|
69 |
+
$generated_content = \PostSnippets\Shortcode::phpEval( $generated_content );
|
70 |
+
}
|
71 |
+
// Strip escaping and execute nested shortcodes
|
72 |
+
$generated_content = do_shortcode( stripslashes( $generated_content ) );
|
73 |
+
// WPTexturize the Snippet
|
74 |
+
if ( ! empty( $snippet['wptexturize'] ) && ( $snippet['wptexturize'] == true ) ) {
|
75 |
+
$generated_content = wptexturize( $generated_content );
|
76 |
+
}
|
77 |
+
return $generated_content;
|
78 |
+
}
|
79 |
+
);
|
80 |
+
}
|
81 |
+
}
|
82 |
+
}
|
83 |
+
}
|
84 |
|
85 |
+
/**
|
86 |
+
* Evaluate a snippet as PHP code.
|
87 |
+
*
|
88 |
+
* @since Post Snippets 1.9
|
89 |
+
* @param string $content The snippet to evaluate
|
90 |
+
* @return string The result of the evaluation
|
91 |
+
*/
|
92 |
+
public static function phpEval( $content ) {
|
93 |
+
if ( defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
94 |
+
return $content;
|
95 |
+
}
|
|
|
96 |
|
97 |
+
$content = stripslashes( $content );
|
98 |
|
99 |
+
ob_start();
|
100 |
+
eval( $content );
|
101 |
+
$content = ob_get_clean();
|
102 |
|
103 |
+
return addslashes( $content );
|
104 |
+
}
|
105 |
}
|
src/PostSnippets/View.php
CHANGED
@@ -3,27 +3,25 @@ namespace PostSnippets;
|
|
3 |
|
4 |
/**
|
5 |
* View Handling.
|
6 |
-
*
|
7 |
*/
|
8 |
-
class View
|
9 |
-
{
|
10 |
-
/**
|
11 |
-
* Render a View.
|
12 |
-
*
|
13 |
-
* @param string $view
|
14 |
-
* @param array $data
|
15 |
-
* @return string
|
16 |
-
*/
|
17 |
-
public static function render($view, $data = null)
|
18 |
-
{
|
19 |
-
// Handle data
|
20 |
-
($data) ? extract($data) : null;
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
29 |
}
|
3 |
|
4 |
/**
|
5 |
* View Handling.
|
|
|
6 |
*/
|
7 |
+
class View {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
/**
|
10 |
+
* Render a View.
|
11 |
+
*
|
12 |
+
* @param string $view
|
13 |
+
* @param array $data
|
14 |
+
* @return string
|
15 |
+
*/
|
16 |
+
public static function render( $view, $data = null ) {
|
17 |
+
// Handle data
|
18 |
+
( $data ) ? extract( $data ) : null;
|
19 |
|
20 |
+
ob_start();
|
21 |
+
include plugin_dir_path( __FILE__ ) . '../../views/' . $view . '.php';
|
22 |
+
$view = ob_get_contents();
|
23 |
+
ob_end_clean();
|
24 |
+
|
25 |
+
return $view;
|
26 |
+
}
|
27 |
}
|
src/PostSnippets/WPEditor.php
CHANGED
@@ -3,301 +3,290 @@ namespace PostSnippets;
|
|
3 |
|
4 |
/**
|
5 |
* Post Snippets WP Editor.
|
6 |
-
*
|
7 |
*/
|
8 |
-
class WPEditor
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
{
|
294 |
-
// Check if variable contains a default defintion
|
295 |
-
$def_pos = strpos($variable, '=');
|
296 |
-
|
297 |
-
if ($def_pos !== false) {
|
298 |
-
$split = str_split($variable, $def_pos);
|
299 |
-
$variable = $split[0];
|
300 |
-
}
|
301 |
-
return $variable;
|
302 |
-
}
|
303 |
}
|
3 |
|
4 |
/**
|
5 |
* Post Snippets WP Editor.
|
|
|
6 |
*/
|
7 |
+
class WPEditor {
|
8 |
+
|
9 |
+
const TINYMCE_PLUGIN_NAME = 'post_snippets';
|
10 |
+
|
11 |
+
public function __construct() {
|
12 |
+
// Add TinyMCE button
|
13 |
+
add_action( 'init', array( &$this, 'addTinymceButton' ) );
|
14 |
+
|
15 |
+
// Add Editor QuickTag button:
|
16 |
+
add_action(
|
17 |
+
'admin_print_footer_scripts',
|
18 |
+
array( &$this, 'addQuicktagButton' ),
|
19 |
+
100
|
20 |
+
);
|
21 |
+
|
22 |
+
add_action( 'admin_head', array( &$this, 'jqueryUiDialog' ) );
|
23 |
+
add_action( 'admin_footer', array( &$this, 'addJqueryUiDialog' ) );
|
24 |
+
|
25 |
+
// Adds the JS and HTML code in the header and footer for the jQuery
|
26 |
+
// insert UI dialog in the editor
|
27 |
+
add_action( 'admin_init', array( &$this, 'enqueueAssets' ) );
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
// -------------------------------------------------------------------------
|
32 |
+
// WordPress Editor Buttons
|
33 |
+
// -------------------------------------------------------------------------
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Add TinyMCE button.
|
37 |
+
*
|
38 |
+
* Adds filters to add custom buttons to the TinyMCE editor (Visual Editor)
|
39 |
+
* in WordPress.
|
40 |
+
*
|
41 |
+
* @since Post Snippets 1.8.7
|
42 |
+
*/
|
43 |
+
public function addTinymceButton() {
|
44 |
+
// Don't bother doing this stuff if the current user lacks permissions
|
45 |
+
if ( ! current_user_can( 'edit_posts' ) && ! current_user_can( 'edit_pages' ) ) {
|
46 |
+
return;
|
47 |
+
}
|
48 |
+
|
49 |
+
// Add only in Rich Editor mode
|
50 |
+
if ( get_user_option( 'rich_editing' ) == 'true' ) {
|
51 |
+
add_filter(
|
52 |
+
'mce_external_plugins',
|
53 |
+
array( &$this, 'registerTinymcePlugin' )
|
54 |
+
);
|
55 |
+
add_filter(
|
56 |
+
'mce_buttons',
|
57 |
+
array( &$this, 'registerTinymceButton' )
|
58 |
+
);
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
/**
|
63 |
+
* Register TinyMCE button.
|
64 |
+
*
|
65 |
+
* Pushes the custom TinyMCE button into the array of with button names.
|
66 |
+
* 'separator' or '|' can be pushed to the array as well. See the link
|
67 |
+
* for all available TinyMCE controls.
|
68 |
+
*
|
69 |
+
* @see wp-includes/class-wp-editor.php
|
70 |
+
* @link http://www.tinymce.com/wiki.php/Buttons/controls
|
71 |
+
* @since Post Snippets 1.8.7
|
72 |
+
*
|
73 |
+
* @param array $buttons Filter supplied array of buttons to modify
|
74 |
+
* @return array The modified array with buttons
|
75 |
+
*/
|
76 |
+
public function registerTinymceButton( $buttons ) {
|
77 |
+
if ( ! $this->isEditingPost() ) {
|
78 |
+
return $buttons;
|
79 |
+
}
|
80 |
+
|
81 |
+
array_push( $buttons, 'separator', self::TINYMCE_PLUGIN_NAME );
|
82 |
+
return $buttons;
|
83 |
+
}
|
84 |
+
|
85 |
+
/**
|
86 |
+
* Register TinyMCE plugin.
|
87 |
+
*
|
88 |
+
* Adds the absolute URL for the TinyMCE plugin to the associative array of
|
89 |
+
* plugins. Array structure: 'plugin_name' => 'plugin_url'
|
90 |
+
*
|
91 |
+
* @see wp-includes/class-wp-editor.php
|
92 |
+
* @since Post Snippets 1.8.7
|
93 |
+
*
|
94 |
+
* @param array $plugins Filter supplied array of plugins to modify
|
95 |
+
* @return array The modified array with plugins
|
96 |
+
*/
|
97 |
+
public function registerTinymcePlugin( $plugins ) {
|
98 |
+
if ( ! $this->isEditingPost() ) {
|
99 |
+
return $plugins;
|
100 |
+
}
|
101 |
+
|
102 |
+
// Load the TinyMCE plugin, editor_plugin.js, into the array
|
103 |
+
$plugins[ self::TINYMCE_PLUGIN_NAME ] =
|
104 |
+
plugins_url( '/tinymce/editor_plugin.js?ver=1.9', \PostSnippets::FILE );
|
105 |
+
|
106 |
+
return $plugins;
|
107 |
+
}
|
108 |
+
|
109 |
+
|
110 |
+
/**
|
111 |
+
* Adds a QuickTag button to the HTML editor.
|
112 |
+
*
|
113 |
+
* Compatible with WordPress 3.3 and newer.
|
114 |
+
*
|
115 |
+
* @see wp-includes/js/quicktags.dev.js -> qt.addButton()
|
116 |
+
* @since Post Snippets 1.8.6
|
117 |
+
*/
|
118 |
+
public function addQuicktagButton() {
|
119 |
+
if ( ! $this->isEditingPost() ) {
|
120 |
+
return;
|
121 |
+
}
|
122 |
+
|
123 |
+
echo "\n<!-- START: Add QuickTag button for Post Snippets -->\n";
|
124 |
+
?>
|
125 |
+
<script type="text/javascript" charset="utf-8">
|
126 |
+
if (typeof QTags != 'undefined') {
|
127 |
+
function qt_post_snippets() {
|
128 |
+
post_snippets_caller = 'html';
|
129 |
+
jQuery("#post-snippets-dialog").dialog("open");
|
130 |
+
}
|
131 |
+
QTags.addButton('post_snippets_id', 'Post Snippets', qt_post_snippets);
|
132 |
+
}
|
133 |
+
</script>
|
134 |
+
<?php
|
135 |
+
echo "\n<!-- END: Add QuickTag button for Post Snippets -->\n";
|
136 |
+
}
|
137 |
+
|
138 |
+
|
139 |
+
// -------------------------------------------------------------------------
|
140 |
+
// JavaScript / jQuery handling for the post editor
|
141 |
+
// -------------------------------------------------------------------------
|
142 |
+
|
143 |
+
/**
|
144 |
+
* Enqueues the necessary scripts and styles for the plugins
|
145 |
+
*
|
146 |
+
* @since Post Snippets 1.7
|
147 |
+
*/
|
148 |
+
public function enqueueAssets() {
|
149 |
+
wp_enqueue_script( 'jquery-ui-dialog' );
|
150 |
+
wp_enqueue_script( 'jquery-ui-tabs' );
|
151 |
+
wp_enqueue_style( 'wp-jquery-ui-dialog' );
|
152 |
+
|
153 |
+
// Adds the CSS stylesheet for the jQuery UI dialog
|
154 |
+
$style_url = plugins_url( '/assets/post-snippets.css', \PostSnippets::FILE );
|
155 |
+
wp_register_style( 'post-snippets', $style_url, false, PS_VERSION );
|
156 |
+
wp_enqueue_style( 'post-snippets' );
|
157 |
+
}
|
158 |
+
|
159 |
+
/**
|
160 |
+
* jQuery control for the dialog and Javascript needed to insert snippets into the editor
|
161 |
+
*
|
162 |
+
* @since Post Snippets 1.7
|
163 |
+
*/
|
164 |
+
public function jqueryUiDialog() {
|
165 |
+
if ( ! $this->isEditingPost() ) {
|
166 |
+
return;
|
167 |
+
}
|
168 |
+
|
169 |
+
// Prepare the snippets and shortcodes into javascript variables
|
170 |
+
// so they can be inserted into the editor, and get the variables replaced
|
171 |
+
// with user defined strings.
|
172 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY, array() );
|
173 |
+
|
174 |
+
// Let other plugins change the snippets array
|
175 |
+
$snippets = apply_filters( 'post_snippets_snippets_list', $snippets );
|
176 |
+
|
177 |
+
$snippetStack = array();
|
178 |
+
|
179 |
+
if ( is_array( $snippets ) || is_object( $snippets ) ) {
|
180 |
+
foreach ( $snippets as $key => $snippet ) {
|
181 |
+
if ( isset( $snippet['shortcode'] ) && ! empty( $snippet['shortcode'] ) ) {
|
182 |
+
// Build a long string of the variables, ie: varname1={varname1} varname2={varname2}
|
183 |
+
// so {varnameX} can be replaced at runtime.
|
184 |
+
$var_arr = explode( ',', $snippet['vars'] );
|
185 |
+
$variables = '';
|
186 |
+
if ( ! empty( $var_arr[0] ) ) {
|
187 |
+
foreach ( $var_arr as $var ) {
|
188 |
+
$var = $this->stripDefaultVal( $var );
|
189 |
+
|
190 |
+
$variables .= ' ' . $var . '="{' . $var . '}"';
|
191 |
+
}
|
192 |
+
}
|
193 |
+
$shortcode = $snippet['title'] . $variables;
|
194 |
+
array_push( $snippetStack, "var postsnippet_{$key} = '[" . $shortcode . "]';\n" );
|
195 |
+
} elseif ( isset( $snippet['snippet'] ) ) {
|
196 |
+
// To use $snippet is probably not a good naming convention here.
|
197 |
+
// rename to js_snippet or something?
|
198 |
+
$snippet = $snippet['snippet'];
|
199 |
+
// Fixes for potential collisions:
|
200 |
+
/* Replace <> with char codes, otherwise </script> in a snippet will break it */
|
201 |
+
$snippet = str_replace( '<', '\x3C', str_replace( '>', '\x3E', $snippet ) );
|
202 |
+
/* Escape " with \" */
|
203 |
+
$snippet = str_replace( '"', '\"', $snippet );
|
204 |
+
/* Remove CR and replace LF with \n to keep formatting */
|
205 |
+
$snippet = str_replace( chr( 13 ), '', str_replace( chr( 10 ), '\n', $snippet ) );
|
206 |
+
// Print out the variable containing the snippet
|
207 |
+
array_push( $snippetStack, "var postsnippet_{$key} = \"" . $snippet . "\";\n" );
|
208 |
+
}
|
209 |
+
}
|
210 |
+
}
|
211 |
+
?>
|
212 |
+
|
213 |
+
<?php
|
214 |
+
$data = array(
|
215 |
+
'methods' => $this,
|
216 |
+
'snippets' => $snippets,
|
217 |
+
'snippetStack' => $snippetStack,
|
218 |
+
);
|
219 |
+
echo View::render( 'jquery_ui_dialog_head', $data );
|
220 |
+
}
|
221 |
+
|
222 |
+
/**
|
223 |
+
* Build jQuery UI Window.
|
224 |
+
*
|
225 |
+
* Creates the jQuery for Post Editor popup window, its snippet tabs and the
|
226 |
+
* form fields to enter variables.
|
227 |
+
*
|
228 |
+
* @since Post Snippets 1.7
|
229 |
+
*/
|
230 |
+
public function addJqueryUiDialog() {
|
231 |
+
if ( ! $this->isEditingPost() ) {
|
232 |
+
return;
|
233 |
+
}
|
234 |
+
|
235 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY, array() );
|
236 |
+
|
237 |
+
// Let other plugins change the snippets array
|
238 |
+
$snippets = apply_filters( 'post_snippets_snippets_list', $snippets );
|
239 |
+
$data = array( 'snippets' => $snippets );
|
240 |
+
|
241 |
+
echo View::render( 'jquery_ui_dialog_footer', $data );
|
242 |
+
}
|
243 |
+
|
244 |
+
/**
|
245 |
+
* Determine if current screen is a post editing screen.
|
246 |
+
*
|
247 |
+
* @return boolean
|
248 |
+
*/
|
249 |
+
protected function isEditingPost() {
|
250 |
+
$settings = get_option( \PostSnippets::SETTINGS );
|
251 |
+
$exclude = isset( $settings['exclude_from_custom_editors'] ) ?
|
252 |
+
$settings['exclude_from_custom_editors'] :
|
253 |
+
false;
|
254 |
+
|
255 |
+
// If we are not excluding from custom editors, always return true.
|
256 |
+
if ( ! $exclude ) {
|
257 |
+
return true;
|
258 |
+
}
|
259 |
+
|
260 |
+
// If get_current_screen doesn't exist, we're on the frontend,
|
261 |
+
// so return false, as it's then definately a custom editor
|
262 |
+
if ( function_exists( 'get_current_screen' ) ) {
|
263 |
+
$screen = get_current_screen();
|
264 |
+
} else {
|
265 |
+
$screen = false;
|
266 |
+
}
|
267 |
+
|
268 |
+
return is_object( $screen ) ? $screen->base == 'post' : false;
|
269 |
+
}
|
270 |
+
|
271 |
+
/**
|
272 |
+
* Strip Default Value.
|
273 |
+
*
|
274 |
+
* Checks if a variable string contains a default value, and if it does it
|
275 |
+
* will strip it away and return the string with only the variable name
|
276 |
+
* kept.
|
277 |
+
*
|
278 |
+
* @since Post Snippets 1.9.3
|
279 |
+
* @param string $variable The variable to check for default value
|
280 |
+
* @return string The variable without any default value
|
281 |
+
*/
|
282 |
+
public function stripDefaultVal( $variable ) {
|
283 |
+
// Check if variable contains a default defintion
|
284 |
+
$def_pos = strpos( $variable, '=' );
|
285 |
+
|
286 |
+
if ( $def_pos !== false ) {
|
287 |
+
$split = str_split( $variable, $def_pos );
|
288 |
+
$variable = $split[0];
|
289 |
+
}
|
290 |
+
return $variable;
|
291 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
}
|
src/init.php
CHANGED
@@ -24,8 +24,8 @@ function guten_post_list_cgb_block_assets() { // phpcs:ignore
|
|
24 |
wp_enqueue_style(
|
25 |
'guten_post_list-cgb-style-css', // Handle.
|
26 |
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
|
27 |
-
array( 'wp-editor' ) // Dependency to include the CSS after it.
|
28 |
-
|
29 |
);
|
30 |
}
|
31 |
|
@@ -47,7 +47,7 @@ function guten_post_list_cgb_editor_assets() { // phpcs:ignore
|
|
47 |
'guten_post_list-cgb-block-js', // Handle.
|
48 |
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
|
49 |
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
|
50 |
-
|
51 |
true // Enqueue the script in the footer.
|
52 |
);
|
53 |
|
@@ -55,8 +55,8 @@ function guten_post_list_cgb_editor_assets() { // phpcs:ignore
|
|
55 |
wp_enqueue_style(
|
56 |
'guten_post_list-cgb-block-editor-css', // Handle.
|
57 |
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
|
58 |
-
array( 'wp-edit-blocks' ) // Dependency to include the CSS after it.
|
59 |
-
|
60 |
);
|
61 |
}
|
62 |
|
24 |
wp_enqueue_style(
|
25 |
'guten_post_list-cgb-style-css', // Handle.
|
26 |
plugins_url( 'dist/blocks.style.build.css', dirname( __FILE__ ) ), // Block style CSS.
|
27 |
+
array( 'wp-editor' ), // Dependency to include the CSS after it.
|
28 |
+
filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.style.build.css' ) // Version: File modification time.
|
29 |
);
|
30 |
}
|
31 |
|
47 |
'guten_post_list-cgb-block-js', // Handle.
|
48 |
plugins_url( '/dist/blocks.build.js', dirname( __FILE__ ) ), // Block.build.js: We register the block here. Built with Webpack.
|
49 |
array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-editor' ), // Dependencies, defined above.
|
50 |
+
filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.build.js' ), // Version: File modification time.
|
51 |
true // Enqueue the script in the footer.
|
52 |
);
|
53 |
|
55 |
wp_enqueue_style(
|
56 |
'guten_post_list-cgb-block-editor-css', // Handle.
|
57 |
plugins_url( 'dist/blocks.editor.build.css', dirname( __FILE__ ) ), // Block editor CSS.
|
58 |
+
array( 'wp-edit-blocks' ), // Dependency to include the CSS after it.
|
59 |
+
filemtime( plugin_dir_path( __DIR__ ) . 'dist/blocks.editor.build.css' ) // Version: File modification time.
|
60 |
);
|
61 |
}
|
62 |
|
views/admin_news.php
CHANGED
@@ -4,40 +4,40 @@
|
|
4 |
|
5 |
<style>
|
6 |
.sab-plugin {
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
}
|
14 |
.sab-plugin img {
|
15 |
-
|
16 |
-
|
17 |
}
|
18 |
.sab-plugin p {
|
19 |
-
|
20 |
-
|
21 |
}
|
22 |
.sab-center {
|
23 |
-
|
24 |
}
|
25 |
.sab-plugin .sab-button {
|
26 |
-
|
27 |
}
|
28 |
</style>
|
29 |
|
30 |
<div class="sab-plugins">
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
</div>
|
43 |
</div>
|
4 |
|
5 |
<style>
|
6 |
.sab-plugin {
|
7 |
+
width: 300px;
|
8 |
+
display: inline-block;
|
9 |
+
background: #fff;
|
10 |
+
border: 1px solid #ccc;
|
11 |
+
padding: 4px 4px 20px 4px;
|
12 |
+
margin:0 10px 10px 0;
|
13 |
}
|
14 |
.sab-plugin img {
|
15 |
+
width: 100%;
|
16 |
+
height: 200px;
|
17 |
}
|
18 |
.sab-plugin p {
|
19 |
+
padding: 15px;
|
20 |
+
height: 106px;
|
21 |
}
|
22 |
.sab-center {
|
23 |
+
text-align: center;
|
24 |
}
|
25 |
.sab-plugin .sab-button {
|
26 |
+
display:inline-block;
|
27 |
}
|
28 |
</style>
|
29 |
|
30 |
<div class="sab-plugins">
|
31 |
+
<?php foreach ( $plugins as $plugin ) : ?>
|
32 |
+
<div class="sab-plugin">
|
33 |
+
<a target="_blank" href="<?php echo esc_url( $plugin['url'] ); ?>">
|
34 |
+
<img src="<?php echo esc_url( PS_URL ) . 'assets/img/' , esc_attr( $plugin['image'] ); ?>" alt="Go to <?php echo esc_attr( $plugin['name'] ); ?>" />
|
35 |
+
</a>
|
36 |
+
<p><?php echo esc_html( $plugin['description'] ); ?></p>
|
37 |
+
<div class="sab-center">
|
38 |
+
<a target="_blank" class="button button-primary button-hero" href="<?php echo esc_url( $plugin['url'] ); ?>"><?php esc_html_e( 'Read more' ); ?></a>
|
39 |
+
</div>
|
40 |
+
</div>
|
41 |
+
<?php endforeach ?>
|
42 |
</div>
|
43 |
</div>
|
views/admin_notice_get_started.php
CHANGED
@@ -19,21 +19,21 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
|
|
19 |
?>
|
20 |
|
21 |
<style>
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
</style>
|
27 |
|
28 |
<div id="ps-admin-notice" class="updated">
|
29 |
-
|
30 |
-
<?php
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
</div>
|
38 |
|
39 |
|
19 |
?>
|
20 |
|
21 |
<style>
|
22 |
+
#pt-admin-notice .button-primary,
|
23 |
+
#pt-admin-notice .button-secondary {
|
24 |
+
margin-left: 15px;
|
25 |
+
}
|
26 |
</style>
|
27 |
|
28 |
<div id="ps-admin-notice" class="updated">
|
29 |
+
<p>
|
30 |
+
<?php esc_html_e( 'You\'ve just installed Post Snippets, find it under \'Settings\'.', 'post-snippets' ); ?>
|
31 |
+
|
32 |
+
<a href="<?php echo esc_attr( PS_MAIN_PAGE_URL ) . '&ps-dismiss-get-started-nag=1'; ?>" class="button-primary"
|
33 |
+
style="vertical-align: baseline;"><?php esc_html_e( 'Go to Post Snippets', 'post-snippets' ); ?></a>
|
34 |
+
<a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-get-started-nag', 1 ) ); ?>"
|
35 |
+
class="button-secondary"><?php esc_html_e( 'Hide this', 'post-snippets' ); ?></a>
|
36 |
+
</p>
|
37 |
</div>
|
38 |
|
39 |
|
views/admin_notice_newsletter.php
CHANGED
@@ -25,42 +25,42 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
|
|
25 |
<div class="subscribe-form ml-block-success" style="display:none">
|
26 |
<div class="form-section mb0">
|
27 |
<p>
|
28 |
-
<?php
|
29 |
</p>
|
30 |
</div>
|
31 |
</div>
|
32 |
|
33 |
-
|
34 |
<form class="ml-block-form" action="//app.mailerlite.com/webforms/submit/a3m1f7" data-id="177069"
|
35 |
-
|
36 |
<div class="subscribe-form horizontal">
|
37 |
<div class="form-section horizontal" style="display: inline">
|
38 |
<div class="form-group ml-field-email ml-validate-required ml-validate-email"
|
39 |
-
|
40 |
<span
|
41 |
-
class="subscribe-message"><?php
|
42 |
<input style="display: inline" type="text" name="fields[email]" class="form-control"
|
43 |
-
|
|
|
|
|
|
|
44 |
</div>
|
45 |
-
<div class="form-group ml-field-ps_count ml-validate-required" style="display: none">
|
46 |
-
<input style="display: none" type="text" name="fields[ps_count]" class="form-control" placeholder="PS Count*" value="<?php echo $snippet_count ?>" spellcheck="false" autocapitalize="off" autocorrect="off">
|
47 |
-
</div>
|
48 |
|
49 |
</div>
|
50 |
<div class="form-section horizontal" style="display: inline">
|
51 |
<button type="submit" class="primary">
|
52 |
-
<?php
|
53 |
</button>
|
54 |
|
55 |
<button disabled="disabled" style="display: none;" type="button" class="loading primary">
|
56 |
<img src="//static.mailerlite.com/images/rolling.gif" width="20" height="20"
|
57 |
-
|
58 |
</button>
|
59 |
|
60 |
</div>
|
61 |
|
62 |
<a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-newsletter-nag', 1 ) ); ?>"
|
63 |
-
class="button-secondary"><?php
|
64 |
|
65 |
<div class="clearfix" style="clear: both;"></div>
|
66 |
<input type="hidden" name="ml-submit" value="1"/>
|
@@ -71,14 +71,14 @@ $snippet_count = count( get_option( 'post_snippets_options', array() ) );
|
|
71 |
function ml_webform_success_6493346() {
|
72 |
jQuery('.ml-subscribe-form-6493346 .ml-block-success').show();
|
73 |
jQuery('.ml-subscribe-form-6493346 .ml-block-form, .subscribe-message').hide();
|
74 |
-
|
75 |
}
|
76 |
</script>
|
77 |
|
78 |
</div>
|
79 |
</div>
|
80 |
<script type="text/javascript"
|
81 |
-
|
82 |
|
83 |
|
84 |
|
25 |
<div class="subscribe-form ml-block-success" style="display:none">
|
26 |
<div class="form-section mb0">
|
27 |
<p>
|
28 |
+
<?php esc_html_e( 'Thank you for subscribing to the Post Snippets newsletter!', 'post-snippets' ); ?>
|
29 |
</p>
|
30 |
</div>
|
31 |
</div>
|
32 |
|
33 |
+
<!-- FOR NEW PLUGIN - UPDATE BELOW ID IN ACTION URL -->
|
34 |
<form class="ml-block-form" action="//app.mailerlite.com/webforms/submit/a3m1f7" data-id="177069"
|
35 |
+
data-code="c7d6k5" method="POST" target="_blank">
|
36 |
<div class="subscribe-form horizontal">
|
37 |
<div class="form-section horizontal" style="display: inline">
|
38 |
<div class="form-group ml-field-email ml-validate-required ml-validate-email"
|
39 |
+
style="display: inline">
|
40 |
<span
|
41 |
+
class="subscribe-message"><?php esc_html_e( 'Subscribe for Post Snippets updates:', 'post-snippets' ); ?></span>
|
42 |
<input style="display: inline" type="text" name="fields[email]" class="form-control"
|
43 |
+
placeholder="Email*" value="<?php echo esc_attr( wp_get_current_user()->user_email ); ?>">
|
44 |
+
</div>
|
45 |
+
<div class="form-group ml-field-ps_count ml-validate-required" style="display: none">
|
46 |
+
<input style="display: none" type="text" name="fields[ps_count]" class="form-control" placeholder="PS Count*" value="<?php echo esc_attr( $snippet_count ); ?>" spellcheck="false" autocapitalize="off" autocorrect="off">
|
47 |
</div>
|
|
|
|
|
|
|
48 |
|
49 |
</div>
|
50 |
<div class="form-section horizontal" style="display: inline">
|
51 |
<button type="submit" class="primary">
|
52 |
+
<?php esc_html_e( 'Subscribe now!', 'post-snippets' ); ?>
|
53 |
</button>
|
54 |
|
55 |
<button disabled="disabled" style="display: none;" type="button" class="loading primary">
|
56 |
<img src="//static.mailerlite.com/images/rolling.gif" width="20" height="20"
|
57 |
+
style="padding-top: 3px;">
|
58 |
</button>
|
59 |
|
60 |
</div>
|
61 |
|
62 |
<a href="<?php echo esc_url( add_query_arg( 'ps-dismiss-newsletter-nag', 1 ) ); ?>"
|
63 |
+
class="button-secondary"><?php esc_html_e( 'Hide this', 'post-snippets' ); ?></a>
|
64 |
|
65 |
<div class="clearfix" style="clear: both;"></div>
|
66 |
<input type="hidden" name="ml-submit" value="1"/>
|
71 |
function ml_webform_success_6493346() {
|
72 |
jQuery('.ml-subscribe-form-6493346 .ml-block-success').show();
|
73 |
jQuery('.ml-subscribe-form-6493346 .ml-block-form, .subscribe-message').hide();
|
74 |
+
window.location.search += '&ps-dismiss-newsletter-nag=1';
|
75 |
}
|
76 |
</script>
|
77 |
|
78 |
</div>
|
79 |
</div>
|
80 |
<script type="text/javascript"
|
81 |
+
src="//static.mailerlite.com/js/w/webforms.min.js?v3772b61f1ec61c541c401d4eadfdd02f"></script>
|
82 |
|
83 |
|
84 |
|
views/admin_options.php
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<form method="post" action="options.php">
|
2 |
<?php
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
?>
|
7 |
</form>
|
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>
|
views/admin_snippets.php
CHANGED
@@ -1,339 +1,330 @@
|
|
1 |
<form method="post" action="" class="post-snippets-wrap">
|
2 |
-
|
3 |
-
wp_nonce_field( 'update_snippets', 'update_snippets_nonce' );
|
4 |
-
?>
|
5 |
-
|
6 |
-
|
7 |
-
\PostSnippets\Admin::submit(
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
);
|
13 |
-
\PostSnippets\Admin::submit(
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
);
|
19 |
-
?>
|
20 |
<a href="#" class="button" data-ps-download><i class="wp-ps-cloud-download"></i> Download snippets</a>
|
21 |
-
|
22 |
|
23 |
<div>
|
24 |
|
25 |
</div>
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
?>
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
?>
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
<div class="post-snippets post-snippets-list post-snippets-list-empty" style="display: none;">
|
48 |
-
<p>
|
49 |
-
<?php
|
50 |
-
echo __( 'You\'ve just installed Post Snippets, awesome!', 'post-snippets' ) ;
|
51 |
-
?><br />
|
52 |
-
<?php
|
53 |
-
echo __( 'Click "Add New Snippet" to create your first snippet or read the documentation at the top right under "Help".', 'post-snippets' ) ;
|
54 |
-
?>
|
55 |
-
</p>
|
56 |
-
</div>
|
57 |
-
<?php
|
58 |
-
wp_nonce_field( 'delete_snippet', 'delete_snippet' );
|
59 |
-
?>
|
60 |
-
<?php
|
61 |
-
wp_nonce_field( 'sync_up', 'sync_up' );
|
62 |
-
?>
|
63 |
-
<?php
|
64 |
-
wp_nonce_field( 'sync_down', 'sync_down' );
|
65 |
-
?>
|
66 |
-
<?php
|
67 |
-
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
68 |
-
|
69 |
-
if ( !empty($snippets) ) {
|
70 |
-
?>
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
echo $snippet['title'] ;
|
95 |
-
?></span>
|
96 |
-
<span class='ps-description'><?php
|
97 |
-
if ( !empty($snippet['description']) ) {
|
98 |
-
echo " (" . esc_html( $snippet['description'] ) . ")" ;
|
99 |
-
}
|
100 |
-
?></span>
|
101 |
-
<a href="#" class="edit-title">
|
102 |
-
<i class="dashicons dashicons-edit"></i>
|
103 |
-
</a>
|
104 |
-
<a href="#" class="save-title">
|
105 |
-
<i class="dashicons dashicons-yes"></i>
|
106 |
-
</a>
|
107 |
-
</div>
|
108 |
-
<div class="text-right post-snippets-toolbar-right">
|
109 |
|
110 |
-
|
111 |
-
|
112 |
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
?>" name="<?php
|
139 |
-
echo "snippets[{$key}][description]" ;
|
140 |
-
?>" value='<?php
|
141 |
-
if ( isset( $snippet['description'] ) ) {
|
142 |
-
echo esc_html( $snippet['description'] ) ;
|
143 |
-
}
|
144 |
-
?>'/>
|
145 |
-
<a style="margin-top:6px" href="#" data-save-snippet="<?php
|
146 |
-
echo $key ;
|
147 |
-
?>" class="button-primary"><?php
|
148 |
-
_e( 'Save', 'post-snippets' );
|
149 |
-
?></a>
|
150 |
-
<span id="saved-success-<?php
|
151 |
-
echo $key ;
|
152 |
-
?>" style="display: none;">Snippet saved</span>
|
153 |
-
</div>
|
154 |
-
</div>
|
155 |
-
<div class="post-snippets-data-cell">
|
156 |
-
<strong>Variables:</strong><br/>
|
157 |
-
<input type='text' id="vars-<?php
|
158 |
-
echo $key ;
|
159 |
-
?>" name="<?php
|
160 |
-
echo "snippets[{$key}][vars]" ;
|
161 |
-
?>" value='<?php
|
162 |
-
echo $snippet['vars'] ;
|
163 |
-
?>'/>
|
164 |
-
<br/>
|
165 |
-
<br/>
|
166 |
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
?>" value="1" <?php
|
175 |
-
checked( $snippet['shortcode'], '1', true );
|
176 |
-
?>>
|
177 |
-
Shortcode
|
178 |
-
</label>
|
179 |
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
echo "snippets[{$key}][php]" ;
|
189 |
-
?>">
|
190 |
-
<input type="checkbox" name="<?php
|
191 |
-
echo "snippets[{$key}][php]" ;
|
192 |
-
?>" id="php-<?php
|
193 |
-
echo $key ;
|
194 |
-
?>" value="1" <?php
|
195 |
-
checked( $snippet['php'], '1', true );
|
196 |
-
?>>
|
197 |
-
PHP Code
|
198 |
-
</label>
|
199 |
-
<br/>
|
200 |
-
<?php
|
201 |
-
}
|
202 |
-
|
203 |
-
?>
|
204 |
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
}
|
|
|
226 |
|
227 |
-
?>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
|
230 |
-
<div id="delete-confirm"
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
?>: <strong></strong>?
|
237 |
-
</
|
|
|
238 |
|
239 |
-
<div id="sync-up-confirm"
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
?>: <strong></strong>
|
246 |
-
|
247 |
-
|
248 |
-
|
|
|
|
|
249 |
|
250 |
-
<div id="sync-up-success"
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
?>
|
257 |
-
</
|
|
|
258 |
|
259 |
-
<div id="sync-success"
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
?>
|
266 |
-
</
|
|
|
267 |
|
268 |
-
<div id="sync-up-error"
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
</div>
|
274 |
|
275 |
-
<div id="sync-update-confirm"
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
?>
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
</div>
|
|
|
290 |
|
291 |
-
<div id="sync-down-list"
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
314 |
|
315 |
-
|
316 |
-
|
317 |
-
</div>
|
318 |
|
319 |
-
<div id="sp-loading" style="display:none;">
|
320 |
-
|
321 |
-
</div>
|
322 |
|
323 |
<div class="post-snippets-buttons-bottom">
|
324 |
-
|
325 |
-
\PostSnippets\Admin::submit(
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
);
|
331 |
-
\PostSnippets\Admin::submit(
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
);
|
337 |
-
?>
|
338 |
</div>
|
339 |
</form>
|
1 |
<form method="post" action="" class="post-snippets-wrap">
|
2 |
+
<?php
|
3 |
+
wp_nonce_field( 'update_snippets', 'update_snippets_nonce' );
|
4 |
+
?>
|
5 |
+
<div class="post-snippets-buttons-top">
|
6 |
+
<?php
|
7 |
+
\PostSnippets\Admin::submit(
|
8 |
+
'add-snippet',
|
9 |
+
__( 'Add New Snippet', 'post-snippets' ),
|
10 |
+
'button-secondary',
|
11 |
+
false
|
12 |
+
);
|
13 |
+
\PostSnippets\Admin::submit(
|
14 |
+
'delete-snippets',
|
15 |
+
__( 'Delete Selected', 'post-snippets' ),
|
16 |
+
'button-secondary',
|
17 |
+
false
|
18 |
+
);
|
19 |
+
?>
|
20 |
<a href="#" class="button" data-ps-download><i class="wp-ps-cloud-download"></i> Download snippets</a>
|
21 |
+
</div>
|
22 |
|
23 |
<div>
|
24 |
|
25 |
</div>
|
26 |
|
27 |
+
<table class="widefat fixed mt-20 post-snippets-table" cellspacing="0">
|
28 |
+
<thead>
|
29 |
+
<tr>
|
30 |
+
<th scope="col" class="check-column"><input type="checkbox" /></th>
|
31 |
+
<th scope="col" class="text-right expand-collapse">
|
32 |
+
<a href="#" class="expand-all">
|
33 |
+
<?php
|
34 |
+
esc_html_e( 'Expand All', 'post-snippets' );
|
35 |
+
?>
|
36 |
+
</a>
|
37 |
+
<a href="#" class="collapse-all">
|
38 |
+
<?php
|
39 |
+
esc_html_e( 'Collapse All', 'post-snippets' );
|
40 |
+
?>
|
41 |
+
</a>
|
42 |
+
</th>
|
43 |
+
</tr>
|
44 |
+
</thead>
|
45 |
+
</table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
+
<div class="post-snippets post-snippets-list post-snippets-list-empty" style="display: none;">
|
48 |
+
<p>
|
49 |
+
<?php
|
50 |
+
echo esc_html__( 'You\'ve just installed Post Snippets, awesome!', 'post-snippets' );
|
51 |
+
?>
|
52 |
+
<br />
|
53 |
+
<?php
|
54 |
+
echo esc_html__( 'Click "Add New Snippet" to create your first snippet or read the documentation at the top right under "Help".', 'post-snippets' );
|
55 |
+
?>
|
56 |
+
</p>
|
57 |
+
</div>
|
58 |
+
<?php
|
59 |
+
wp_nonce_field( 'delete_snippet', 'delete_snippet' );
|
60 |
+
?>
|
61 |
+
<?php
|
62 |
+
wp_nonce_field( 'sync_up', 'sync_up' );
|
63 |
+
?>
|
64 |
+
<?php
|
65 |
+
wp_nonce_field( 'sync_down', 'sync_down' );
|
66 |
+
?>
|
67 |
+
<?php
|
68 |
+
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
+
if ( ! empty( $snippets ) ) {
|
71 |
+
?>
|
72 |
|
73 |
+
<div class="post-snippets post-snippets-list">
|
74 |
+
<?php
|
75 |
+
foreach ( $snippets as $key => $snippet ) {
|
76 |
+
?>
|
77 |
+
<div class="post-snippets-item ui-state-highlight"
|
78 |
+
data-order="<?php echo esc_attr( $key ); ?>"
|
79 |
+
id="key-<?php echo esc_attr( $key ); ?> ">
|
80 |
+
<div class="post-snippets-toolbar">
|
81 |
+
<div class="text-left">
|
82 |
+
<input type='checkbox' name='checked[]' value='<?php echo esc_attr( $key ); ?>'/>
|
83 |
+
<input type='text' class="post-snippet-title"
|
84 |
+
name='<?php echo 'snippets[' . esc_attr( $key ) . '][title]'; ?>'
|
85 |
+
value='<?php echo esc_attr( $snippet['title'] ); ?>'
|
86 |
+
/>
|
87 |
+
<span id="snippet-<?php echo esc_attr( $key ); ?>-title"
|
88 |
+
class="post-snippet-title"><?php echo esc_attr( $snippet['title'] ); ?>
|
89 |
+
</span>
|
90 |
+
<span class='ps-description'>
|
91 |
+
<?php
|
92 |
+
if ( ! empty( $snippet['description'] ) ) {
|
93 |
+
echo ' (' . esc_html( $snippet['description'] ) . ')';
|
94 |
+
}
|
95 |
+
?>
|
96 |
+
</span>
|
97 |
+
<a href="#" class="edit-title">
|
98 |
+
<i class="dashicons dashicons-edit"></i>
|
99 |
+
</a>
|
100 |
+
<a href="#" class="save-title">
|
101 |
+
<i class="dashicons dashicons-yes"></i>
|
102 |
+
</a>
|
103 |
+
</div>
|
104 |
+
<div class="text-right post-snippets-toolbar-right">
|
105 |
+
<a href="#" class="toggle-post-snippets-data" title="Expand/Collapse">
|
106 |
+
<i class="dashicons dashicons-arrow-down"></i>
|
107 |
+
<i class="dashicons dashicons-arrow-up"></i>
|
108 |
+
</a>
|
109 |
+
</div>
|
110 |
+
</div>
|
111 |
+
<div class="post-snippets-data">
|
112 |
+
<div class="post-snippets-data-cell">
|
113 |
+
<div>
|
114 |
+
<textarea id="snippet-<?php echo esc_attr( $key ); ?>"
|
115 |
+
class="snippet"
|
116 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][snippet]'; ?>"
|
117 |
+
class="large-text" style='width: 100%;' rows="5"><?php
|
118 |
+
echo esc_html( $snippet['snippet'] );
|
119 |
+
?></textarea>
|
120 |
|
121 |
+
<?php
|
122 |
+
esc_html_e( 'Description', 'post-snippets' );
|
123 |
+
?>:
|
124 |
+
<input type='text' style='width: 100%;'
|
125 |
+
id="description-<?php echo esc_attr( $key ); ?>"
|
126 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][description]'; ?>"
|
127 |
+
value =
|
128 |
+
'<?php
|
129 |
+
if ( isset( $snippet['description'] ) ) {
|
130 |
+
echo esc_html( $snippet['description'] );
|
131 |
+
}
|
132 |
+
?>'/>
|
133 |
+
<a style="margin-top:6px" href="#"
|
134 |
+
data-save-snippet="<?php echo esc_attr( $key ); ?>"
|
135 |
+
class="button-primary"
|
136 |
+
>
|
137 |
+
<?php
|
138 |
+
esc_html_e( 'Save', 'post-snippets' );
|
139 |
+
?>
|
140 |
+
</a>
|
141 |
|
142 |
+
<span id="saved-success-<?php echo esc_attr( $key ); ?>"
|
143 |
+
style="display: none;">Snippet saved
|
144 |
+
</span>
|
145 |
+
</div>
|
146 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
147 |
|
148 |
+
<div class="post-snippets-data-cell">
|
149 |
+
<strong>Variables:</strong><br/>
|
150 |
+
<input type='text' id="vars-<?php echo esc_attr( $key ); ?>"
|
151 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][vars]'; ?>"
|
152 |
+
value='<?php echo esc_attr( $snippet['vars'] ); ?>'
|
153 |
+
/>
|
154 |
+
<br/><br/>
|
|
|
|
|
|
|
|
|
|
|
155 |
|
156 |
+
<label for="<?php echo 'snippets[' . esc_attr( $key ) . '][shortcode]'; ?> ">
|
157 |
+
<input type="checkbox"
|
158 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][shortcode]'; ?>"
|
159 |
+
id="shortcode-<?php echo esc_attr( $key ); ?>" value="1"
|
160 |
+
<?php checked( $snippet['shortcode'], '1', true );
|
161 |
+
?>
|
162 |
+
>Shortcode
|
163 |
+
</label>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
164 |
|
165 |
+
<br/>
|
166 |
+
<strong>
|
167 |
+
<?php
|
168 |
+
esc_html_e( 'Shortcode Options:', 'post-snippets' );
|
169 |
+
?>
|
170 |
+
</strong><br/>
|
171 |
+
|
172 |
+
<?php
|
173 |
+
if ( ! defined( 'POST_SNIPPETS_DISABLE_PHP' ) ) {
|
174 |
+
?>
|
175 |
+
<label for="<?php echo 'snippets[' . esc_attr( $key ) . '][php]';?>">
|
176 |
+
<input type="checkbox"
|
177 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][php]'; ?>"
|
178 |
+
id="php-<?php echo esc_attr( $key ); ?>"
|
179 |
+
value="1" <?php checked( $snippet['php'], '1', true ); ?>
|
180 |
+
>
|
181 |
+
PHP Code
|
182 |
+
</label>
|
183 |
+
<br/>
|
184 |
+
<?php
|
185 |
+
}
|
186 |
+
?>
|
187 |
|
188 |
+
<label for="<?php echo 'snippets[' . esc_attr( $key ) . '][wptexturize]'; ?>">
|
189 |
+
<input type="checkbox"
|
190 |
+
name="<?php echo 'snippets[' . esc_attr( $key ) . '][wptexturize]'; ?>"
|
191 |
+
id="wptexturize-<?php echo esc_attr( $key ); ?>"
|
192 |
+
value="1" <?php checked( $snippet['wptexturize'], '1', true ); ?>
|
193 |
+
>
|
194 |
+
wptexturize
|
195 |
+
</label>
|
196 |
+
</div>
|
197 |
+
</div>
|
198 |
+
</div>
|
199 |
+
<?php
|
200 |
+
}
|
201 |
+
?>
|
202 |
+
</div>
|
203 |
+
<?php
|
204 |
+
}
|
205 |
+
?>
|
206 |
|
207 |
|
208 |
+
<div id="delete-confirm"
|
209 |
+
title="<?php esc_attr_e( 'Confirm', 'post-snippets' );?>"
|
210 |
+
style="display:none;">
|
211 |
+
<p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
|
212 |
+
<?php
|
213 |
+
esc_html_e( 'Do you want to delete snippet', 'post-snippets' );
|
214 |
+
?>: <strong></strong>?
|
215 |
+
</p>
|
216 |
+
</div>
|
217 |
|
218 |
+
<div id="sync-up-confirm"
|
219 |
+
title="<?php esc_attr_e( 'Confirm', 'post-snippets' ); ?>"
|
220 |
+
style="display:none;">
|
221 |
+
<p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
|
222 |
+
<?php
|
223 |
+
esc_html_e( 'Do you want to upload the snippet', 'post-snippets' );
|
224 |
+
?>: <strong></strong>
|
225 |
+
<?php
|
226 |
+
esc_html_e( 'in your snippets cloud?', 'post-snippets' );
|
227 |
+
?>
|
228 |
+
</p>
|
229 |
+
</div>
|
230 |
|
231 |
+
<div id="sync-up-success"
|
232 |
+
title="<?php esc_attr_e( 'Success', 'post-snippets' ); ?>"
|
233 |
+
style="display:none;">
|
234 |
+
<p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
|
235 |
+
<?php
|
236 |
+
esc_html_e( 'Snippet successfully saved!', 'post-snippets' );
|
237 |
+
?>
|
238 |
+
</p>
|
239 |
+
</div>
|
240 |
|
241 |
+
<div id="sync-success"
|
242 |
+
title="<?php esc_attr_e( 'Success', 'post-snippets' );?>"
|
243 |
+
style="display:none;">
|
244 |
+
<p><span class="dashicons dashicons-thumbs-up" style="float:left; margin-right:12px;"></span>
|
245 |
+
<?php
|
246 |
+
esc_html_e( 'Snippet successfully downloaded!', 'post-snippets' );
|
247 |
+
?>
|
248 |
+
</p>
|
249 |
+
</div>
|
250 |
|
251 |
+
<div id="sync-up-error"
|
252 |
+
title="<?php esc_attr_e( 'Error', 'post-snippets' ); ?>" style="display:none;">
|
253 |
+
<p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
|
254 |
+
<p data-error></p>
|
255 |
+
</p>
|
256 |
+
</div>
|
257 |
|
258 |
+
<div id="sync-update-confirm"
|
259 |
+
title="<?php esc_attr_e( 'Confirm', 'post-snippets' ); ?>"
|
260 |
+
style="display:none;">
|
261 |
+
<p><span class="dashicons dashicons-warning" style="float:left; margin-right:12px;"></span>
|
262 |
+
<?php
|
263 |
+
esc_html_e( 'A snippet with title <strong data-title></strong> already exists in your online library:', 'post-snippets' );
|
264 |
+
?>
|
265 |
+
</p>
|
266 |
+
<div class='snippet'>
|
267 |
+
<p><b>Title</b>: <span data-title></span></p>
|
268 |
+
<p><b>Description</b>: <span data-description></span></p>
|
269 |
+
<p><b>Variables</b>: <span data-vars></span></p>
|
270 |
+
<p><b>Snippet</b>: <textarea readonly></textarea></p>
|
271 |
+
<p><b>Options</b>: <span data-options></span></p>
|
272 |
+
</div>
|
273 |
+
</div>
|
274 |
|
275 |
+
<div id="sync-down-list"
|
276 |
+
title="<?php esc_attr_e( 'Donwload your snippets', 'post-snippets' );?>">
|
277 |
+
<p class="message"></p>
|
278 |
+
<table class="wp-list-table widefat striped">
|
279 |
+
<thead>
|
280 |
+
<tr>
|
281 |
+
<td class="manage-column column-cb"><input type='checkbox' data-toggle-all></td>
|
282 |
+
<th class="">
|
283 |
+
<?php
|
284 |
+
esc_html_e( 'Title', 'post-snippets' );
|
285 |
+
?>
|
286 |
+
</th>
|
287 |
+
<th>
|
288 |
+
<?php
|
289 |
+
esc_html_e( 'Description', 'post-snippets' );
|
290 |
+
?>
|
291 |
+
</th>
|
292 |
+
<th>
|
293 |
+
<?php
|
294 |
+
esc_html_e( 'Variables', 'post-snippets' );
|
295 |
+
?>
|
296 |
+
</th>
|
297 |
+
<th>
|
298 |
+
<?php
|
299 |
+
esc_html_e( 'Snippet', 'post-snippets' );
|
300 |
+
?>
|
301 |
+
</th>
|
302 |
+
</tr>
|
303 |
+
</thead>
|
304 |
+
<tbody>
|
305 |
|
306 |
+
</tbody>
|
307 |
+
</table>
|
308 |
+
</div>
|
309 |
|
310 |
+
<div id="sp-loading" style="display:none;">
|
311 |
+
<span></span>
|
312 |
+
</div>
|
313 |
|
314 |
<div class="post-snippets-buttons-bottom">
|
315 |
+
<?php
|
316 |
+
\PostSnippets\Admin::submit(
|
317 |
+
'add-snippet',
|
318 |
+
__( 'Add New Snippet', 'post-snippets' ),
|
319 |
+
'button-secondary',
|
320 |
+
false
|
321 |
+
);
|
322 |
+
\PostSnippets\Admin::submit(
|
323 |
+
'delete-snippets',
|
324 |
+
__( 'Delete Selected', 'post-snippets' ),
|
325 |
+
'button-secondary',
|
326 |
+
false
|
327 |
+
);
|
328 |
+
?>
|
329 |
</div>
|
330 |
</form>
|
views/help/advanced.php
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
<h2><?php
|
2 |
|
3 |
<p>
|
4 |
You can add constants to wp-config.php or the theme’s functions.php file to control some aspects of the plugin. Available constants to set are:
|
@@ -12,31 +12,31 @@ define('POST_SNIPPETS_DISABLE_PHP', true);
|
|
12 |
</code></pre>
|
13 |
|
14 |
<p>
|
15 |
-
<?php
|
16 |
</p>
|
17 |
|
18 |
-
<h2><?php
|
19 |
<p>
|
20 |
<code>
|
21 |
<?php $my_snippet = PostSnippets::getSnippet( $snippet_name, $snippet_vars ); ?>
|
22 |
</code></p>
|
23 |
|
24 |
-
<h2><?php
|
25 |
<p>
|
26 |
<strong>$snippet_name</strong><br/>
|
27 |
-
<?php
|
28 |
<br/><br/>
|
29 |
<strong>$snippet_vars</strong><br/>
|
30 |
-
<?php
|
31 |
</p>
|
32 |
|
33 |
|
34 |
-
<h2><?php
|
35 |
|
36 |
<pre><code>// Use querystring for variables
|
37 |
$mySnippet = PostSnippets::getSnippet('internal-link', 'title=Awesome&url=2011/02/awesome/');
|
38 |
-
echo $mySnippet;
|
39 |
|
40 |
// Use array for variables
|
41 |
$mySnippet = PostSnippets::getSnippet('internal-link', array('title' => 'Awesome', 'url' => '2011/02/awesome/');
|
42 |
-
echo $mySnippet;</code></pre>
|
1 |
+
<h2><?php esc_html_e( 'Advanced', 'post-snippets' ); ?> (<em><?php esc_html_e( 'for developers', 'post-snippets' ); ?></em>)</h2>
|
2 |
|
3 |
<p>
|
4 |
You can add constants to wp-config.php or the theme’s functions.php file to control some aspects of the plugin. Available constants to set are:
|
12 |
</code></pre>
|
13 |
|
14 |
<p>
|
15 |
+
<?php esc_html_e( 'You can retrieve a Post Snippet directly from PHP, in a theme for instance, by using the PostSnippets::getSnippet() method.', 'post-snippets' ); ?>
|
16 |
</p>
|
17 |
|
18 |
+
<h2><?php esc_html_e( 'Usage', 'post-snippets' ); ?></h2>
|
19 |
<p>
|
20 |
<code>
|
21 |
<?php $my_snippet = PostSnippets::getSnippet( $snippet_name, $snippet_vars ); ?>
|
22 |
</code></p>
|
23 |
|
24 |
+
<h2><?php esc_html_e( 'Parameters', 'post-snippets' ); ?></h2>
|
25 |
<p>
|
26 |
<strong>$snippet_name</strong><br/>
|
27 |
+
<?php esc_html_e( '(string) (required) The name of the snippet to retrieve.', 'post-snippets' ); ?>
|
28 |
<br/><br/>
|
29 |
<strong>$snippet_vars</strong><br/>
|
30 |
+
<?php esc_html_e( '(string) The variables to pass to the snippet, formatted as a query string.', 'post-snippets' ); ?>
|
31 |
</p>
|
32 |
|
33 |
|
34 |
+
<h2><?php esc_html_e( 'Example', 'post-snippets' ); ?></h2>
|
35 |
|
36 |
<pre><code>// Use querystring for variables
|
37 |
$mySnippet = PostSnippets::getSnippet('internal-link', 'title=Awesome&url=2011/02/awesome/');
|
38 |
+
echo esc_html($mySnippet);
|
39 |
|
40 |
// Use array for variables
|
41 |
$mySnippet = PostSnippets::getSnippet('internal-link', array('title' => 'Awesome', 'url' => '2011/02/awesome/');
|
42 |
+
echo esc_html($mySnippet);</code></pre>
|
views/help/filters.php
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
<h2><?php
|
2 |
|
3 |
-
<p><?php
|
4 |
|
5 |
<ul>
|
6 |
-
<li><strong>post_snippets_import</strong> <em>serialized array</em> <?php
|
7 |
-
<li><strong>post_snippets_export</strong> <em>serialized array</em> <?php
|
8 |
-
<li><strong>post_snippets_snippets_list</strong> <em>array</em> <?php
|
9 |
</ul>
|
10 |
|
11 |
-
<h3><?php
|
12 |
|
13 |
<strong>post_snippets_export</strong>
|
14 |
<pre><code>// Filter Exported Snippets
|
@@ -16,8 +16,8 @@ function ps_export( $snippets )
|
|
16 |
{
|
17 |
$snippets = unserialize( $snippets );
|
18 |
foreach ( $snippets as &$snippet ) {
|
19 |
-
|
20 |
-
|
21 |
}
|
22 |
return serialize( $snippets );
|
23 |
}
|
@@ -29,8 +29,8 @@ function ps_import( $snippets )
|
|
29 |
{
|
30 |
$snippets = unserialize( $snippets );
|
31 |
foreach ( $snippets as &$snippet ) {
|
32 |
-
|
33 |
-
|
34 |
}
|
35 |
return serialize( $snippets );
|
36 |
}
|
1 |
+
<h2><?php esc_html_e( 'Filters', 'post-snippets' ); ?> (<em><?php esc_html_e( 'for developers', 'post-snippets' ); ?></em>)</h2>
|
2 |
|
3 |
+
<p><?php esc_html_e( 'The following filters are available for hooking into the plugin:', 'post-snippets' ); ?></p>
|
4 |
|
5 |
<ul>
|
6 |
+
<li><strong>post_snippets_import</strong> <em>serialized array</em> <?php esc_html_e( 'Modify snippets and related data before the imported file populates the snippets.', 'post-snippets' ); ?></li>
|
7 |
+
<li><strong>post_snippets_export</strong> <em>serialized array</em> <?php esc_html_e( 'Modify snippets and related data before the export file is created.', 'post-snippets' ); ?></li>
|
8 |
+
<li><strong>post_snippets_snippets_list</strong> <em>array</em> <?php esc_html_e( 'Modify the array of snippets that are used as the snippet list for the jQuery UI dialog in the edit post screen.', 'post-snippets' ); ?></li>
|
9 |
</ul>
|
10 |
|
11 |
+
<h3><?php esc_html_e( 'Examples', 'post-snippets' ); ?></h3>
|
12 |
|
13 |
<strong>post_snippets_export</strong>
|
14 |
<pre><code>// Filter Exported Snippets
|
16 |
{
|
17 |
$snippets = unserialize( $snippets );
|
18 |
foreach ( $snippets as &$snippet ) {
|
19 |
+
// Do something here. Example below search and replaces in snippets
|
20 |
+
$snippet['snippet'] = str_replace('search','replace', $snippet['snippet']);
|
21 |
}
|
22 |
return serialize( $snippets );
|
23 |
}
|
29 |
{
|
30 |
$snippets = unserialize( $snippets );
|
31 |
foreach ( $snippets as &$snippet ) {
|
32 |
+
// Do something here. Example below search and replaces in variables
|
33 |
+
$snippet['vars'] = str_replace('search', 'replace', $snippet['vars']);
|
34 |
}
|
35 |
return serialize( $snippets );
|
36 |
}
|
views/help/php.php
CHANGED
@@ -1,25 +1,25 @@
|
|
1 |
<h2>PHP Code</h2>
|
2 |
|
3 |
<p>
|
4 |
-
<?php
|
5 |
</p>
|
6 |
|
7 |
<p>
|
8 |
-
<?php
|
9 |
</p>
|
10 |
|
11 |
-
<img src="<?php echo plugins_url('assets/img/help/php-snippet.jpg', \PostSnippets::FILE); ?>" />
|
12 |
|
13 |
<p>
|
14 |
-
<?php
|
15 |
</p>
|
16 |
|
17 |
<code>[phpcode loop_me="post snippet with PHP!"]</code>
|
18 |
|
19 |
<p>
|
20 |
-
<?php
|
21 |
</p>
|
22 |
|
23 |
<p>
|
24 |
-
<?php
|
25 |
</p>
|
1 |
<h2>PHP Code</h2>
|
2 |
|
3 |
<p>
|
4 |
+
<?php esc_html_e( 'Snippets defined as shortcodes can optionally also be evaluated as PHP Code by enabling the PHP checkbox. PHP snippets is only available when treating the snippet as a shortcode.', 'post-snippets' ); ?>
|
5 |
</p>
|
6 |
|
7 |
<p>
|
8 |
+
<?php esc_html_e( 'Check this image for an example PHP snippet:', 'post-snippets' ); ?>
|
9 |
</p>
|
10 |
|
11 |
+
<img src="<?php echo esc_url( plugins_url( 'assets/img/help/php-snippet.jpg', \PostSnippets::FILE ) ); ?>" />
|
12 |
|
13 |
<p>
|
14 |
+
<?php esc_html_e( 'With a snippet defined like the one above, you can call it with its shortcode definition in a post. Let\'s pretend that the example snippet is named phpcode and have one variable defined loop_me, then it would be called like this from a post:', 'post-snippets' ); ?>
|
15 |
</p>
|
16 |
|
17 |
<code>[phpcode loop_me="post snippet with PHP!"]</code>
|
18 |
|
19 |
<p>
|
20 |
+
<?php esc_html_e( 'When the shortcode is executed the loop_me variable will be replaced with the string supplied in the shortcode and then the PHP code will be evaluated. (Outputting the string five times in this case. Wow!)', 'post-snippets' ); ?>
|
21 |
</p>
|
22 |
|
23 |
<p>
|
24 |
+
<?php esc_html_e( 'Note the evaluation order, any snippet variables will be replaced before the snippet is evaluated as PHP code. Also note that a PHP snippet don\'t need to be wrapped in <?php #code; ?>.', 'post-snippets' ); ?>
|
25 |
</p>
|
views/help/post.php
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
<h2><?php
|
2 |
|
3 |
-
<img src="<?php echo plugins_url('assets/img/help/post-snippets-editor.jpg', \PostSnippets::FILE); ?>" />
|
4 |
|
5 |
<p>
|
6 |
-
<?php
|
7 |
</p>
|
8 |
|
9 |
-
<img src="<?php echo plugins_url('assets/img/help/post-snippets-window.jpg', \PostSnippets::FILE); ?>" />
|
10 |
|
11 |
<p>
|
12 |
-
<?php
|
13 |
</p>
|
1 |
+
<h2><?php esc_html_e( 'The Post Editor', 'post-snippets' ); ?></h2>
|
2 |
|
3 |
+
<img src="<?php echo esc_url( plugins_url( 'assets/img/help/post-snippets-editor.jpg', \PostSnippets::FILE ) ); ?>" />
|
4 |
|
5 |
<p>
|
6 |
+
<?php esc_html_e( 'With your snippets set up, you\'ll find a new button in your post editor (circled in the image above), which you can click to open the Post Snippet window to insert one of your snippets in your post.', 'post-snippets' ); ?>
|
7 |
</p>
|
8 |
|
9 |
+
<img src="<?php echo esc_url( plugins_url( 'assets/img/help/post-snippets-window.jpg', \PostSnippets::FILE ) ); ?>" />
|
10 |
|
11 |
<p>
|
12 |
+
<?php esc_html_e( 'When you click this button, you get a window with all your available snippets. Each snippet has its own tab in the Post Snippet window, so you can select which snippet to insert. If you have set up custom variables for the snippet, you can now enter the values for these variables before clicking insert and they will be inserted in the correct places in the snippet string.', 'post-snippets' ); ?>
|
13 |
</p>
|
views/help/sidebar.php
CHANGED
@@ -1,16 +1,22 @@
|
|
1 |
<p><strong>
|
2 |
-
<?php
|
3 |
</strong></p>
|
4 |
|
5 |
-
<p><a href="//www.postsnippets.com" target="_blank"
|
6 |
-
|
7 |
-
|
|
|
|
|
8 |
|
9 |
-
<p><a href="http://wordpress.org/support/plugin/post-snippets" target="_blank"
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
|
13 |
-
<p><a href="https://github.com/GreenTreeLabs/post-snippets" target="_blank"
|
14 |
-
|
15 |
-
|
|
|
|
|
16 |
|
1 |
<p><strong>
|
2 |
+
<?php esc_html_e( 'Related:', 'post-snippets' ); ?>
|
3 |
</strong></p>
|
4 |
|
5 |
+
<p><a href="//www.postsnippets.com" target="_blank">
|
6 |
+
<?php
|
7 |
+
esc_html_e( 'Website', 'post-snippets' );
|
8 |
+
?>
|
9 |
+
</a></p>
|
10 |
|
11 |
+
<p><a href="http://wordpress.org/support/plugin/post-snippets" target="_blank">
|
12 |
+
<?php
|
13 |
+
esc_html_e( 'Support', 'post-snippets' );
|
14 |
+
?>
|
15 |
+
</a></p>
|
16 |
|
17 |
+
<p><a href="https://github.com/GreenTreeLabs/post-snippets" target="_blank">
|
18 |
+
<?php
|
19 |
+
esc_html_e( 'GitHub', 'post-snippets' );
|
20 |
+
?>
|
21 |
+
</a></p>
|
22 |
|
views/help/usage.php
CHANGED
@@ -1,62 +1,62 @@
|
|
1 |
-
<h2><?php
|
2 |
|
3 |
|
4 |
-
<h3><?php
|
5 |
<p>
|
6 |
-
<?php
|
7 |
</p>
|
8 |
|
9 |
|
10 |
-
<h3><?php
|
11 |
<p>
|
12 |
-
<?php
|
13 |
</p>
|
14 |
|
15 |
<p>
|
16 |
-
|
17 |
-
|
18 |
</p>
|
19 |
|
20 |
|
21 |
-
<h3><?php
|
22 |
<p>
|
23 |
-
<?php
|
24 |
</p>
|
25 |
|
26 |
-
<p><strong><?php
|
27 |
-
<p><?php
|
28 |
-
<p><?php
|
29 |
|
30 |
<pre><code>This is the website of <a href="{url}">{name}</a></code></pre>
|
31 |
|
32 |
-
<p><?php
|
33 |
|
34 |
|
35 |
-
<h3><?php
|
36 |
<p>
|
37 |
-
<?php
|
38 |
</p>
|
39 |
|
40 |
|
41 |
-
<h3><?php
|
42 |
<p>
|
43 |
-
<?php
|
44 |
</p>
|
45 |
|
46 |
<p>
|
47 |
-
<?php
|
48 |
</p>
|
49 |
|
50 |
<p>
|
51 |
-
<?php
|
52 |
</p>
|
53 |
|
54 |
-
<h3><?php
|
55 |
<p>
|
56 |
-
<?php
|
57 |
</p>
|
58 |
|
59 |
<h3>wptexturize</h3>
|
60 |
<p>
|
61 |
-
<?php printf(
|
62 |
</p>
|
1 |
+
<h2><?php esc_html_e( 'Usage', 'post-snippets' ); ?></h2>
|
2 |
|
3 |
|
4 |
+
<h3><?php esc_html_e( 'Title', 'post-snippets' ); ?></h3>
|
5 |
<p>
|
6 |
+
<?php esc_html_e( 'Give the snippet a title that helps you identify it in the post editor. This also becomes the name of the shortcode if you enable that option.', 'post-snippets' ); ?>
|
7 |
</p>
|
8 |
|
9 |
|
10 |
+
<h3><?php esc_html_e( 'Variables', 'post-snippets' ); ?></h3>
|
11 |
<p>
|
12 |
+
<?php esc_html_e( 'A comma separated list of custom variables you can reference in your snippet. A variable can also be assigned a default value that will be used in the insert window by using the equal sign, variable=default.', 'post-snippets' ); ?>
|
13 |
</p>
|
14 |
|
15 |
<p>
|
16 |
+
<strong><?php esc_html_e( 'Example', 'post-snippets' ); ?></strong>
|
17 |
+
<pre><code>url,name,role=user,title</code></pre>
|
18 |
</p>
|
19 |
|
20 |
|
21 |
+
<h3><?php esc_html_e( 'Snippet', 'post-snippets' ); ?></h3>
|
22 |
<p>
|
23 |
+
<?php esc_html_e( 'This is the block of text, HTML or PHP to insert in the post or as a shortcode. If you have entered predefined variables you can reference them from the snippet by enclosing them in {} brackets.', 'post-snippets' ); ?>
|
24 |
</p>
|
25 |
|
26 |
+
<p><strong><?php esc_html_e( 'Example', 'post-snippets' ); ?></strong></p>
|
27 |
+
<p><?php esc_html_e( 'To reference the variables in the example above, you would enter {url} and {name}. So if you enter this snippet:', 'post-snippets' ); ?></p>
|
28 |
+
<p><?php esc_html_e( 'So if you enter this snippet:', 'post-snippets' ); ?></p>
|
29 |
|
30 |
<pre><code>This is the website of <a href="{url}">{name}</a></code></pre>
|
31 |
|
32 |
+
<p><?php esc_html_e( 'You will get the option to replace url and name on insert if they are defined as variables.', 'post-snippets' ); ?></p>
|
33 |
|
34 |
|
35 |
+
<h3><?php esc_html_e( 'Description', 'post-snippets' ); ?></h3>
|
36 |
<p>
|
37 |
+
<?php esc_html_e( 'An optional description for the Snippet. If filled out, the description will be displayed in the snippets insert window in the post editor.', 'post-snippets' ); ?>
|
38 |
</p>
|
39 |
|
40 |
|
41 |
+
<h3><?php esc_html_e( 'Shortcode', 'post-snippets' ); ?></h3>
|
42 |
<p>
|
43 |
+
<?php esc_html_e( 'When enabling the shortcode checkbox, the snippet is no longer inserted directly but instead inserted as a shortcode. The obvious advantage of this is of course that you can insert a block of text or code in many places on the site, and update the content from one single place.', 'post-snippets' ); ?>
|
44 |
</p>
|
45 |
|
46 |
<p>
|
47 |
+
<?php esc_html_e( 'The name to use the shortcode is the same as the title of the snippet (spaces are not allowed). When inserting a shortcode snippet, the shortcode and not the content will be inserted in the post.', 'post-snippets' ); ?>
|
48 |
</p>
|
49 |
|
50 |
<p>
|
51 |
+
<?php esc_html_e( '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' ); ?>
|
52 |
</p>
|
53 |
|
54 |
+
<h3><?php esc_html_e( 'PHP Code', 'post-snippets' ); ?></h3>
|
55 |
<p>
|
56 |
+
<?php esc_html_e( 'See the dedicated help section for information about PHP shortcodes.', 'post-snippets' ); ?>
|
57 |
</p>
|
58 |
|
59 |
<h3>wptexturize</h3>
|
60 |
<p>
|
61 |
+
<?php printf( esc_html__( 'Before the shortcode is outputted, it can optionally be formatted with %s, to transform quotes to smart quotes, apostrophes, dashes, ellipses, the trademark symbol, and the multiplication symbol.', 'post-snippets' ), '<a href="http://codex.wordpress.org/Function_Reference/wptexturize">wptexturize</a>' ); ?>
|
62 |
</p>
|
views/jquery_ui_dialog_footer.php
CHANGED
@@ -1,91 +1,105 @@
|
|
1 |
<!-- START: Post Snippets UI Dialog -->
|
2 |
<?php // Setup the dialog divs ?>
|
3 |
<div class="hidden">
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
|
|
|
|
|
|
28 |
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
42 |
-
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
|
|
|
|
68 |
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
|
|
|
|
|
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
|
|
|
|
|
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
|
|
90 |
</div><!-- .hidden -->
|
91 |
<!-- END: Post Snippets UI Dialog -->
|
1 |
<!-- START: Post Snippets UI Dialog -->
|
2 |
<?php // Setup the dialog divs ?>
|
3 |
<div class="hidden">
|
4 |
+
<div id="post-snippets-dialog" title="Post Snippets">
|
5 |
+
<?php // Init the tabs div ?>
|
6 |
+
<div id="post-snippets-tabs">
|
7 |
|
8 |
+
<?php
|
9 |
|
10 |
+
if ( empty( $snippets ) ) {
|
11 |
+
echo sprintf( esc_html__( 'No snippets found, to create them go to %1$sPost Snippets →%2$s', 'post-snippets' ), '<a href="' . esc_url( admin_url( 'options-general.php?page=post-snippets' ) ) . '" class="button-primary">', '</a>' );
|
12 |
+
} else {
|
13 |
+
?>
|
14 |
+
<ul>
|
15 |
+
<?php
|
16 |
+
// Create a tab for each available snippet
|
17 |
+
foreach ( $snippets as $key => $snippet ) {
|
18 |
+
?>
|
19 |
+
<li><a href="#ps-tabs-<?php echo esc_attr( $key ); ?>">
|
20 |
+
<?php
|
21 |
+
echo esc_html( $snippet['title'] );
|
22 |
+
?>
|
23 |
+
</a>
|
24 |
+
</li>
|
25 |
+
<?php
|
26 |
+
}
|
27 |
+
?>
|
28 |
+
</ul>
|
29 |
+
<?php
|
30 |
+
}
|
31 |
|
32 |
+
// Create a panel with form fields for each available snippet
|
33 |
+
foreach ( $snippets as $key => $snippet ) {
|
34 |
+
?>
|
35 |
+
<div id="ps-tabs-<?php echo esc_attr( $key ); ?>">
|
36 |
+
<?php
|
37 |
+
// Print a snippet description is available
|
38 |
+
if ( isset( $snippet['description'] ) ) {
|
39 |
+
?>
|
40 |
+
<p class="howto">
|
41 |
+
<?php
|
42 |
+
echo esc_html( $snippet['description'] );
|
43 |
+
?>
|
44 |
+
</p>
|
45 |
+
<?php
|
46 |
|
47 |
+
}
|
48 |
|
49 |
+
// Get all variables defined for the snippet and output them as
|
50 |
+
// input fields
|
51 |
+
$var_arr = explode( ',', $snippet['vars'] );
|
52 |
+
if ( ! empty( $var_arr[0] ) ) {
|
53 |
+
foreach ( $var_arr as $key_2 => $var ) {
|
54 |
+
// Default value exists?
|
55 |
+
$def_pos = strpos( $var, '=' );
|
56 |
+
if ( $def_pos !== false ) {
|
57 |
+
$split = explode( '=', $var );
|
58 |
+
$var = $split[0];
|
59 |
+
$def = $split[1];
|
60 |
+
} else {
|
61 |
+
$def = '';
|
62 |
+
}
|
63 |
+
?>
|
64 |
+
<label for="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 );?>">
|
65 |
+
<?php
|
66 |
+
echo esc_html( $var );
|
67 |
+
?>:
|
68 |
+
</label>
|
69 |
+
<input type="text" id="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 ); ?>"
|
70 |
+
name="var_<?php echo esc_attr( $key ) . '_' . esc_attr( $key_2 );?>"
|
71 |
+
value="<?php echo esc_attr( $def ); ?>"
|
72 |
+
style="width: 190px" />
|
73 |
+
<br/>
|
74 |
+
<?php
|
75 |
|
76 |
+
}
|
77 |
+
} else {
|
78 |
+
// If no variables and no description available, output a text
|
79 |
+
// to inform the user that it's an insert snippet only.
|
80 |
+
if ( empty( $snippet['description'] ) ) {
|
81 |
+
?>
|
82 |
+
<p class="howto">
|
83 |
+
<?php
|
84 |
+
esc_html_e( 'This snippet is insert only, no variables defined.', 'post-snippets' );
|
85 |
+
?>
|
86 |
+
</p>
|
87 |
+
<?php
|
88 |
|
89 |
+
}
|
90 |
+
}
|
91 |
+
?>
|
92 |
+
</div><!-- #ps-tabs-
|
93 |
+
<?php
|
94 |
+
echo esc_html( $key );
|
95 |
+
?>
|
96 |
+
-->
|
97 |
+
<?php
|
98 |
|
99 |
+
}
|
100 |
+
// Close the tabs and dialog divs
|
101 |
+
?>
|
102 |
+
</div><!-- #post-snippets-tabs -->
|
103 |
+
</div><!-- #post-snippets-dialog -->
|
104 |
</div><!-- .hidden -->
|
105 |
<!-- END: Post Snippets UI Dialog -->
|
views/jquery_ui_dialog_head.php
CHANGED
@@ -1,110 +1,122 @@
|
|
1 |
|
2 |
<!-- START: Post Snippets jQuery UI and related functions -->
|
3 |
<script type='text/javascript'>
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
|
32 |
-
|
33 |
|
34 |
-
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
|
58 |
-
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
|
82 |
-
|
83 |
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
</script>
|
110 |
<!-- END: Post Snippets jQuery UI and related functions -->
|
1 |
|
2 |
<!-- START: Post Snippets jQuery UI and related functions -->
|
3 |
<script type='text/javascript'>
|
4 |
+
<?php
|
5 |
+
foreach ( $snippetStack as $snippetVarString ) {
|
6 |
+
echo html_entity_decode( esc_html( $snippetVarString ), ENT_QUOTES );
|
7 |
+
} ?>
|
8 |
|
9 |
+
jQuery(document).ready(function($){
|
10 |
+
<?php
|
11 |
+
// Create js variables for all form fields
|
12 |
+
foreach ( $snippets as $key => $snippet ) {
|
13 |
+
$var_arr = explode( ',', $snippet['vars'] );
|
14 |
+
if ( ! empty( $var_arr[0] ) ) {
|
15 |
+
foreach ( $var_arr as $key_2 => $var ) {
|
16 |
+
$varname = 'var_' . $key . '_' . $key_2;
|
17 |
+
echo 'var ' . esc_js( $varname ) . ' = $( "#' . esc_js( $varname ) . "\" );\n";
|
18 |
+
}
|
19 |
+
}
|
20 |
+
}
|
21 |
+
?>
|
22 |
+
// We do the check to see if post snippets dialog is in the footer.
|
23 |
+
// Some plugins, like 'download monitor' uses WordPress admin bootstrap and
|
24 |
+
// then bring in admin_head but not admin_footer. So to allow other plugins
|
25 |
+
// to do that 'hack', we bail out in thoise cases.
|
26 |
+
if ($("#post-snippets-tabs").length>0) {
|
27 |
|
28 |
+
if($.isFunction($().tabs)){ // Ensure the tabs function is available
|
29 |
+
var tabs = $("#post-snippets-tabs").tabs();
|
30 |
+
}
|
31 |
|
32 |
+
$(function() {
|
33 |
|
34 |
+
if($.isFunction($().dialog)){ // Ensure the dialog function is available
|
35 |
|
36 |
+
$("#post-snippets-dialog").dialog({
|
37 |
+
autoOpen: false,
|
38 |
+
modal: true,
|
39 |
+
dialogClass: 'wp-dialog',
|
40 |
+
buttons: {
|
41 |
+
Cancel: function() {
|
42 |
+
$(this).dialog("close");
|
43 |
+
},
|
44 |
+
"Insert": function() {
|
45 |
+
$(this).dialog("close");
|
46 |
+
<?php
|
47 |
+
global $wp_version;
|
48 |
+
if ( version_compare( $wp_version, '3.5', '<' ) ) {
|
49 |
+
?>
|
50 |
+
var selected = tabs.tabs('option', 'selected');
|
51 |
+
<?php
|
52 |
|
53 |
+
} else {
|
54 |
+
?>
|
55 |
+
var selected = tabs.tabs('option', 'active');
|
56 |
+
<?php
|
57 |
|
58 |
+
}
|
59 |
|
60 |
+
foreach ( $snippets as $key => $snippet ) {
|
61 |
+
?>
|
62 |
+
if (selected ==
|
63 |
+
<?php
|
64 |
+
echo esc_js( $key );
|
65 |
+
?>
|
66 |
+
) {
|
67 |
+
insert_snippet = postsnippet_
|
68 |
+
<?php
|
69 |
+
echo esc_js( $key );
|
70 |
+
?>
|
71 |
+
;
|
72 |
+
<?php
|
73 |
+
$var_arr = explode( ',', $snippet['vars'] );
|
74 |
+
if ( ! empty( $var_arr[0] ) ) {
|
75 |
+
foreach ( $var_arr as $key_2 => $var ) {
|
76 |
+
$varname = 'var_' . $key . '_' . $key_2;
|
77 |
+
?>
|
78 |
+
insert_snippet = insert_snippet.replace(/\{
|
79 |
+
<?php
|
80 |
+
echo esc_js( $methods->stripDefaultVal( $var ) );
|
81 |
+
?>
|
82 |
+
\}/g,
|
83 |
+
<?php
|
84 |
+
echo esc_js( $varname );
|
85 |
+
?>
|
86 |
+
.val());
|
87 |
+
<?php
|
88 |
|
89 |
+
}
|
90 |
+
}
|
91 |
+
?>
|
92 |
+
}
|
93 |
|
94 |
+
<?php
|
95 |
|
96 |
+
}
|
97 |
+
?>
|
98 |
|
99 |
+
// Decide what method to use to insert the snippet depending
|
100 |
+
// from what editor the window was opened from
|
101 |
+
if (post_snippets_caller == 'html') {
|
102 |
+
// HTML editor in WordPress 3.3 and greater
|
103 |
+
QTags.insertContent(insert_snippet);
|
104 |
+
} else {
|
105 |
+
// Visual Editor
|
106 |
+
post_snippets_canvas.execCommand('mceInsertContent', false, insert_snippet);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
},
|
110 |
+
width: 500,
|
111 |
+
});
|
112 |
+
}
|
113 |
+
});
|
114 |
+
}
|
115 |
+
});
|
116 |
|
117 |
+
// Global variables to keep track on the canvas instance and from what editor
|
118 |
+
// that opened the Post Snippets popup.
|
119 |
+
var post_snippets_canvas;
|
120 |
+
var post_snippets_caller = '';
|
121 |
</script>
|
122 |
<!-- END: Post Snippets jQuery UI and related functions -->
|