Version Description
Download this release
Release Info
Developer | wpexpertsio |
Plugin | Post Snippets |
Version | 3.1 |
Comparing to | |
See all releases |
Code changes from version 3.0.21 to 3.1
- assets/post-snippets.js +1 -1
- post-snippets.php +9 -12
- readme.txt +9 -2
- src/PostSnippets/Admin.php +25 -25
- src/PostSnippets/ImportExport.php +36 -9
assets/post-snippets.js
CHANGED
@@ -130,7 +130,7 @@ jQuery(document).ready(function ($) {
|
|
130 |
'action': 'update_post_snippet_title',
|
131 |
'key': key,
|
132 |
'title': title,
|
133 |
-
'save_title_nonce' : post_snippets.save_title_nonce
|
134 |
};
|
135 |
$.post(ajaxurl, data, function (res) {
|
136 |
if(res.success){
|
130 |
'action': 'update_post_snippet_title',
|
131 |
'key': key,
|
132 |
'title': title,
|
133 |
+
'save_title_nonce' : post_snippets.save_title_nonce,
|
134 |
};
|
135 |
$.post(ajaxurl, data, function (res) {
|
136 |
if(res.success){
|
post-snippets.php
CHANGED
@@ -12,7 +12,7 @@
|
|
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.
|
16 |
* Author: Postsnippets
|
17 |
* Author URI: https://www.postsnippets.com
|
18 |
* License: GPL-2.0+
|
@@ -44,12 +44,9 @@ if ( !function_exists( 'postsnippets_fs' ) ) {
|
|
44 |
'is_require_payment' => true,
|
45 |
),
|
46 |
'menu' => array(
|
47 |
-
'slug' => 'post-
|
48 |
'contact' => false,
|
49 |
'support' => false,
|
50 |
-
'parent' => array(
|
51 |
-
'slug' => 'options-general.php',
|
52 |
-
),
|
53 |
),
|
54 |
'is_live' => true,
|
55 |
) );
|
@@ -64,13 +61,13 @@ if ( !function_exists( 'postsnippets_fs' ) ) {
|
|
64 |
do_action( 'postsnippets_fs_loaded' );
|
65 |
function postsnippets_fs_settings_url()
|
66 |
{
|
67 |
-
return admin_url( '
|
68 |
}
|
69 |
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
/**
|
75 |
* Only show Post Snippets submenu when PS is open, not on all Settings pages
|
76 |
*/
|
@@ -94,7 +91,7 @@ if ( !function_exists( 'postsnippets_fs' ) ) {
|
|
94 |
define( 'PS_MAIN_FILE', basename( __FILE__ ) );
|
95 |
}
|
96 |
if ( !defined( 'PS_VERSION' ) ) {
|
97 |
-
define( 'PS_VERSION', '3.
|
98 |
}
|
99 |
if ( !defined( 'PS_MAIN_FILE_PATH' ) ) {
|
100 |
define( 'PS_MAIN_FILE_PATH', __FILE__ );
|
@@ -109,7 +106,7 @@ if ( !function_exists( 'postsnippets_fs' ) ) {
|
|
109 |
define( 'PS_URL', plugins_url( '', __FILE__ ) . '/' );
|
110 |
}
|
111 |
if ( !defined( 'PS_MAIN_PAGE_URL' ) ) {
|
112 |
-
define( 'PS_MAIN_PAGE_URL', esc_url( admin_url( '
|
113 |
}
|
114 |
class PostSnippets
|
115 |
{
|
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+
|
44 |
'is_require_payment' => true,
|
45 |
),
|
46 |
'menu' => array(
|
47 |
+
'slug' => 'post-snippets',
|
48 |
'contact' => false,
|
49 |
'support' => false,
|
|
|
|
|
|
|
50 |
),
|
51 |
'is_live' => true,
|
52 |
) );
|
61 |
do_action( 'postsnippets_fs_loaded' );
|
62 |
function postsnippets_fs_settings_url()
|
63 |
{
|
64 |
+
return admin_url( 'admin.php?page=post-snippets' );
|
65 |
}
|
66 |
|
67 |
+
// postsnippets_fs()->add_filter( 'connect_url', 'postsnippets_fs_settings_url' );
|
68 |
+
// postsnippets_fs()->add_filter( 'after_skip_url', 'postsnippets_fs_settings_url' );
|
69 |
+
// postsnippets_fs()->add_filter( 'after_connect_url', 'postsnippets_fs_settings_url' );
|
70 |
+
// postsnippets_fs()->add_filter( 'after_pending_connect_url', 'postsnippets_fs_settings_url' );
|
71 |
/**
|
72 |
* Only show Post Snippets submenu when PS is open, not on all Settings pages
|
73 |
*/
|
91 |
define( 'PS_MAIN_FILE', basename( __FILE__ ) );
|
92 |
}
|
93 |
if ( !defined( 'PS_VERSION' ) ) {
|
94 |
+
define( 'PS_VERSION', '3.1' );
|
95 |
}
|
96 |
if ( !defined( 'PS_MAIN_FILE_PATH' ) ) {
|
97 |
define( 'PS_MAIN_FILE_PATH', __FILE__ );
|
106 |
define( 'PS_URL', plugins_url( '', __FILE__ ) . '/' );
|
107 |
}
|
108 |
if ( !defined( 'PS_MAIN_PAGE_URL' ) ) {
|
109 |
+
define( 'PS_MAIN_PAGE_URL', esc_url( admin_url( 'admin.php?page=post-snippets' ) ) );
|
110 |
}
|
111 |
class PostSnippets
|
112 |
{
|
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.
|
8 |
License: GPLv2 or later
|
9 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
10 |
|
@@ -107,6 +107,13 @@ your clients to be able to use PHP code in a post snippet.
|
|
107 |
|
108 |
== Changelog ==
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
= Version 3.0.21 - 2 May 2020 =
|
111 |
|
112 |
* Improvement - Code Optimized to improve security
|
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.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 |
|
108 |
== Changelog ==
|
109 |
|
110 |
+
= Version 3.1 - 20 aug 2020 =
|
111 |
+
|
112 |
+
* Fix - Post Snippets Blocks throwing error in WordPress 5.5
|
113 |
+
* Improvement - Improved import functionality
|
114 |
+
* Fix - Issues in freemius redirects
|
115 |
+
* Fix - POST_SNIPPETS_ALLOW_EDIT_POSTS not working
|
116 |
+
|
117 |
= Version 3.0.21 - 2 May 2020 =
|
118 |
|
119 |
* Improvement - Code Optimized to improve security
|
src/PostSnippets/Admin.php
CHANGED
@@ -48,25 +48,14 @@ class Admin
|
|
48 |
array( 'wp-blocks', 'wp-editor' ),
|
49 |
true
|
50 |
);
|
51 |
-
|
52 |
-
|
53 |
-
public function js_settings()
|
54 |
-
{
|
55 |
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
56 |
-
/*$data = array();
|
57 |
-
foreach($snippets as $snippet) {
|
58 |
-
$data [] = array(
|
59 |
-
"title" => $snippet["title"],
|
60 |
-
"vars" => $snippet["vars"],
|
61 |
-
"shortcode" => $snippet["shortcode"] == 1
|
62 |
-
);
|
63 |
-
}*/
|
64 |
if(isset($snippets) && !empty($snippets) && is_array($snippets)) {
|
65 |
usort( $snippets, function ( $a, $b ) {
|
66 |
return strcasecmp( $a["title"], $b["title"] );
|
67 |
} );
|
68 |
}
|
69 |
-
wp_localize_script( '
|
70 |
}
|
71 |
|
72 |
// -------------------------------------------------------------------------
|
@@ -79,11 +68,10 @@ class Admin
|
|
79 |
*/
|
80 |
public function menu()
|
81 |
{
|
82 |
-
$capability =
|
83 |
|
84 |
-
if (
|
85 |
$allowed = true;
|
86 |
-
$capability = 'edit_posts';
|
87 |
}
|
88 |
|
89 |
|
@@ -91,7 +79,7 @@ class Admin
|
|
91 |
$optionPage = add_menu_page(
|
92 |
__( 'Post Snippets', 'post-snippets' ),
|
93 |
__( 'Post Snippets', 'post-snippets' ),
|
94 |
-
|
95 |
'post-snippets',
|
96 |
array( $this, 'optionsPage' ),
|
97 |
PS_URL . 'assets/icon.svg'
|
@@ -100,7 +88,7 @@ class Admin
|
|
100 |
'post-snippets',
|
101 |
__( 'News', 'post-snippets' ),
|
102 |
__( 'News', 'post-snippets' ),
|
103 |
-
|
104 |
'post-snippets-news',
|
105 |
array( $this, 'newsPage' )
|
106 |
);
|
@@ -140,7 +128,6 @@ class Admin
|
|
140 |
true
|
141 |
);
|
142 |
$this->scripts();
|
143 |
-
$this->js_settings();
|
144 |
$this->registerSettings();
|
145 |
}
|
146 |
|
@@ -990,7 +977,8 @@ class Admin
|
|
990 |
if ( empty($_POST['order']) || !is_array( $_POST['order'] ) ) {
|
991 |
wp_send_json_error( 'order data not received' );
|
992 |
}
|
993 |
-
|
|
|
994 |
wp_send_json_error( 'permission denied' );
|
995 |
}
|
996 |
$orders = array_map( 'intval', $_POST['order'] );
|
@@ -1016,13 +1004,13 @@ class Admin
|
|
1016 |
if ( !isset( $_POST['key'] ) || empty($_POST['title']) ) {
|
1017 |
wp_send_json_error();
|
1018 |
}
|
1019 |
-
|
1020 |
if ( !wp_verify_nonce( $_POST['save_title_nonce'], 'ps-save-title-nonce' ) ) {
|
1021 |
wp_send_json_error();
|
1022 |
}
|
1023 |
|
1024 |
-
|
1025 |
-
|
|
|
1026 |
}
|
1027 |
$pkey = intval( $_POST['key'] );
|
1028 |
$title = sanitize_text_field( $_POST['title'] );
|
@@ -1058,8 +1046,10 @@ class Admin
|
|
1058 |
if ( !wp_verify_nonce( $_POST['update_snippet_nonce'], 'ps-update-snippet-nonce' ) ) {
|
1059 |
wp_send_json_error();
|
1060 |
}
|
1061 |
-
|
1062 |
-
|
|
|
|
|
1063 |
}
|
1064 |
$key = intval( $_POST['key'] );
|
1065 |
$snippets = get_option( 'post_snippets_options', array() );
|
@@ -1087,4 +1077,14 @@ class Admin
|
|
1087 |
wp_send_json_success( $title );
|
1088 |
}
|
1089 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1090 |
}
|
48 |
array( 'wp-blocks', 'wp-editor' ),
|
49 |
true
|
50 |
);
|
51 |
+
|
|
|
|
|
|
|
52 |
$snippets = get_option( \PostSnippets::OPTION_KEY );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
if(isset($snippets) && !empty($snippets) && is_array($snippets)) {
|
54 |
usort( $snippets, function ( $a, $b ) {
|
55 |
return strcasecmp( $a["title"], $b["title"] );
|
56 |
} );
|
57 |
}
|
58 |
+
wp_localize_script( 'post-snippets-block', 'post_snippets_s', $snippets );
|
59 |
}
|
60 |
|
61 |
// -------------------------------------------------------------------------
|
68 |
*/
|
69 |
public function menu()
|
70 |
{
|
71 |
+
$capability = $this->get_allowed_capability();
|
72 |
|
73 |
+
if ( $capability == 'edit_posts' ) {
|
74 |
$allowed = true;
|
|
|
75 |
}
|
76 |
|
77 |
|
79 |
$optionPage = add_menu_page(
|
80 |
__( 'Post Snippets', 'post-snippets' ),
|
81 |
__( 'Post Snippets', 'post-snippets' ),
|
82 |
+
$capability,
|
83 |
'post-snippets',
|
84 |
array( $this, 'optionsPage' ),
|
85 |
PS_URL . 'assets/icon.svg'
|
88 |
'post-snippets',
|
89 |
__( 'News', 'post-snippets' ),
|
90 |
__( 'News', 'post-snippets' ),
|
91 |
+
$capability,
|
92 |
'post-snippets-news',
|
93 |
array( $this, 'newsPage' )
|
94 |
);
|
128 |
true
|
129 |
);
|
130 |
$this->scripts();
|
|
|
131 |
$this->registerSettings();
|
132 |
}
|
133 |
|
977 |
if ( empty($_POST['order']) || !is_array( $_POST['order'] ) ) {
|
978 |
wp_send_json_error( 'order data not received' );
|
979 |
}
|
980 |
+
$capability = $this->get_allowed_capability();
|
981 |
+
if ( !current_user_can( $capability ) ) {
|
982 |
wp_send_json_error( 'permission denied' );
|
983 |
}
|
984 |
$orders = array_map( 'intval', $_POST['order'] );
|
1004 |
if ( !isset( $_POST['key'] ) || empty($_POST['title']) ) {
|
1005 |
wp_send_json_error();
|
1006 |
}
|
|
|
1007 |
if ( !wp_verify_nonce( $_POST['save_title_nonce'], 'ps-save-title-nonce' ) ) {
|
1008 |
wp_send_json_error();
|
1009 |
}
|
1010 |
|
1011 |
+
$capability = $this->get_allowed_capability();
|
1012 |
+
if ( !current_user_can( $capability ) ) {
|
1013 |
+
wp_send_json_error('permission denied');
|
1014 |
}
|
1015 |
$pkey = intval( $_POST['key'] );
|
1016 |
$title = sanitize_text_field( $_POST['title'] );
|
1046 |
if ( !wp_verify_nonce( $_POST['update_snippet_nonce'], 'ps-update-snippet-nonce' ) ) {
|
1047 |
wp_send_json_error();
|
1048 |
}
|
1049 |
+
|
1050 |
+
$capability = $this->get_allowed_capability();
|
1051 |
+
if ( !current_user_can( $capability ) ) {
|
1052 |
+
wp_send_json_error('permission denied');
|
1053 |
}
|
1054 |
$key = intval( $_POST['key'] );
|
1055 |
$snippets = get_option( 'post_snippets_options', array() );
|
1077 |
wp_send_json_success( $title );
|
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 |
}
|
src/PostSnippets/ImportExport.php
CHANGED
@@ -65,7 +65,10 @@ class ImportExport
|
|
65 |
|| empty($_FILES['postsnippets_import_file'])
|
66 |
) {
|
67 |
$import .=
|
68 |
-
'<p>'.__('Import snippets from a post-snippets-export.zip file.
|
|
|
|
|
|
|
69 |
'</p>';
|
70 |
$import .= '<form method="post" enctype="multipart/form-data">';
|
71 |
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
@@ -100,19 +103,43 @@ class ImportExport
|
|
100 |
'post_snippets_import',
|
101 |
$snippets
|
102 |
);
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
}
|
108 |
|
109 |
// Delete the snippet file
|
110 |
unlink('./'.self::FILE_CFG);
|
111 |
|
112 |
-
|
113 |
-
'<p><strong>'.
|
114 |
-
__('Snippets successfully imported.', 'post-snippets').
|
115 |
-
'</strong></p>';
|
116 |
} else {
|
117 |
$import .=
|
118 |
'<p><strong>'.
|
65 |
|| empty($_FILES['postsnippets_import_file'])
|
66 |
) {
|
67 |
$import .=
|
68 |
+
'<p>'.__('Import snippets from a post-snippets-export.zip file. Imported sinppets will get added at the bottom.', 'post-snippets').
|
69 |
+
'</p>';
|
70 |
+
$import .=
|
71 |
+
'<p>'.__('Please make sure no snippets have duplicate titles.', 'post-snippets').
|
72 |
'</p>';
|
73 |
$import .= '<form method="post" enctype="multipart/form-data">';
|
74 |
$import .= '<input type="file" name="postsnippets_import_file"/>';
|
103 |
'post_snippets_import',
|
104 |
$snippets
|
105 |
);
|
106 |
+
|
107 |
+
$imported_snippets = unserialize($snippets);
|
108 |
+
$current_snippets = get_option( \PostSnippets::OPTION_KEY );
|
109 |
+
|
110 |
+
$all_snippets = $current_snippets;
|
111 |
+
$duplicate_title_exist = false;
|
112 |
+
$duplicate_title = '';
|
113 |
+
foreach($imported_snippets as $snippet){
|
114 |
+
$all_snippets[]=$snippet;
|
115 |
+
foreach($current_snippets as $current){
|
116 |
+
if($current['title'] == $snippet['title']){
|
117 |
+
$duplicate_title = $snippet['title'];
|
118 |
+
$duplicate_title_exist = true;
|
119 |
+
break;
|
120 |
+
}
|
121 |
+
}
|
122 |
+
}
|
123 |
+
|
124 |
+
if ($duplicate_title_exist == false) {
|
125 |
+
update_option( \PostSnippets::OPTION_KEY, $all_snippets );
|
126 |
+
$import .=
|
127 |
+
'<p><strong>'.
|
128 |
+
__('Snippets successfully imported.', 'post-snippets').
|
129 |
+
'</strong></p>';
|
130 |
+
} else {
|
131 |
+
$import .=
|
132 |
+
'<p><strong>'.
|
133 |
+
__('All the snippets should have unique titles. The snippet in your import file with title "'.$duplicate_title.'" already exists in your site.', 'post-snippets').
|
134 |
+
'</strong></p>';
|
135 |
+
}
|
136 |
+
|
137 |
}
|
138 |
|
139 |
// Delete the snippet file
|
140 |
unlink('./'.self::FILE_CFG);
|
141 |
|
142 |
+
|
|
|
|
|
|
|
143 |
} else {
|
144 |
$import .=
|
145 |
'<p><strong>'.
|