Code Snippets - Version 2.2.3

Version Description

  • Fixed broken call to export_snippet() function
  • Added support for importing and exporting snippet scope
  • Fixed duplicate primary key database error
  • Improved database table structure
Download this release

Release Info

Developer bungeshea
Plugin Icon Code Snippets
Version 2.2.3
Comparing to
See all releases

Code changes from version 2.2.2 to 2.2.3

code-snippets.php CHANGED
@@ -7,7 +7,7 @@
7
  * contribute to the localization, please see https://github.com/sheabunge/code-snippets
8
  *
9
  * @package Code_Snippets
10
- * @version 2.2.2
11
  * @author Shea Bunge <http://bungeshea.com/>
12
  * @copyright Copyright (c) 2012-2014, Shea Bunge
13
  * @link http://bungeshea.com/plugins/code-snippets/
@@ -20,7 +20,7 @@ Plugin URI: http://bungeshea.com/plugins/code-snippets/
20
  Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
21
  Author: Shea Bunge
22
  Author URI: http://bungeshea.com
23
- Version: 2.2.2
24
  License: MIT
25
  License URI: license.txt
26
  Text Domain: code-snippets
@@ -42,7 +42,7 @@ if ( ! defined( 'ABSPATH' ) ) {
42
  * @since 2.0
43
  * @var string A PHP-standardized version number string
44
  */
45
- define( 'CODE_SNIPPETS_VERSION', '2.2.2' );
46
 
47
  /**
48
  * The full path to the main file of this plugin
7
  * contribute to the localization, please see https://github.com/sheabunge/code-snippets
8
  *
9
  * @package Code_Snippets
10
+ * @version 2.2.3
11
  * @author Shea Bunge <http://bungeshea.com/>
12
  * @copyright Copyright (c) 2012-2014, Shea Bunge
13
  * @link http://bungeshea.com/plugins/code-snippets/
20
  Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
21
  Author: Shea Bunge
22
  Author URI: http://bungeshea.com
23
+ Version: 2.2.3
24
  License: MIT
25
  License URI: license.txt
26
  Text Domain: code-snippets
42
  * @since 2.0
43
  * @var string A PHP-standardized version number string
44
  */
45
+ define( 'CODE_SNIPPETS_VERSION', '2.2.3' );
46
 
47
  /**
48
  * The full path to the main file of this plugin
includes/class-export.php CHANGED
@@ -25,7 +25,7 @@ class Code_Snippets_Export {
25
  * The IDs
26
  * @var array
27
  */
28
- public $snippet_ids = array();
29
 
30
  /**
31
  * The name of the table to fetch snippets from
@@ -38,21 +38,21 @@ class Code_Snippets_Export {
38
  * Either 'xml' or 'php'
39
  * @var object
40
  */
41
- public $format;
42
 
43
  /**
44
  * The DOM document.
45
  * Only used in XML exports
46
  * @var object
47
  */
48
- public $dom;
49
 
50
  /**
51
  * The DOM document root element
52
  * Only used in XML exports
53
  * @var object
54
  */
55
- public $root;
56
 
57
  /**
58
  * Constructor function
@@ -60,7 +60,7 @@ class Code_Snippets_Export {
60
  * @param string $table The name of the table to fetch snippets from
61
  * @param string $format The format of the export file
62
  */
63
- function __construct( $ids, $table, $format = 'xml' ) {
64
  $this->snippet_ids = (array) $ids;
65
  $this->table_name = $table;
66
  $this->format = 'php' === $format ? 'php' : 'xml';
@@ -71,7 +71,7 @@ class Code_Snippets_Export {
71
  * Build the export file name
72
  * @return string
73
  */
74
- function get_filename() {
75
 
76
  if ( 1 == count( $this->snippet_ids ) ) {
77
  /* If there is only snippet to export, use its name instead of the site name */
@@ -133,8 +133,6 @@ class Code_Snippets_Export {
133
  $this->dom->appendChild( $gen );
134
  }
135
 
136
-
137
-
138
  /**
139
  * Process all snippet items
140
  */
25
  * The IDs
26
  * @var array
27
  */
28
+ protected $snippet_ids = array();
29
 
30
  /**
31
  * The name of the table to fetch snippets from
38
  * Either 'xml' or 'php'
39
  * @var object
40
  */
41
+ protected $format;
42
 
43
  /**
44
  * The DOM document.
45
  * Only used in XML exports
46
  * @var object
47
  */
48
+ protected $dom;
49
 
50
  /**
51
  * The DOM document root element
52
  * Only used in XML exports
53
  * @var object
54
  */
55
+ protected $root;
56
 
57
  /**
58
  * Constructor function
60
  * @param string $table The name of the table to fetch snippets from
61
  * @param string $format The format of the export file
62
  */
63
+ public function __construct( $ids, $table, $format = 'xml' ) {
64
  $this->snippet_ids = (array) $ids;
65
  $this->table_name = $table;
66
  $this->format = 'php' === $format ? 'php' : 'xml';
71
  * Build the export file name
72
  * @return string
73
  */
74
+ public function get_filename() {
75
 
76
  if ( 1 == count( $this->snippet_ids ) ) {
77
  /* If there is only snippet to export, use its name instead of the site name */
133
  $this->dom->appendChild( $gen );
134
  }
135
 
 
 
136
  /**
137
  * Process all snippet items
138
  */
includes/db.php CHANGED
@@ -101,7 +101,6 @@ function create_code_snippets_table( $table_name ) {
101
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
102
 
103
  /* Set the database charset */
104
-
105
  $charset_collate = '';
106
 
107
  if ( ! empty( $wpdb->charset ) ) {
@@ -113,19 +112,17 @@ function create_code_snippets_table( $table_name ) {
113
  }
114
 
115
  /* Create the database table */
116
-
117
  $sql = "CREATE TABLE $table_name (
118
- id bigint(20) unsigned not null auto_increment,
119
- name tinytext not null,
120
- description text,
121
- code longtext not null,
122
- tags longtext,
123
- scope tinyint(1) default 0,
124
- active tinyint(1) not null default 0,
125
- primary key (id)
126
- ) {$charset_collate};";
127
 
128
  dbDelta( $sql );
129
-
130
  do_action( 'code_snippets/create_table', $table_name );
131
  }
101
  require_once ABSPATH . 'wp-admin/includes/upgrade.php';
102
 
103
  /* Set the database charset */
 
104
  $charset_collate = '';
105
 
106
  if ( ! empty( $wpdb->charset ) ) {
112
  }
113
 
114
  /* Create the database table */
 
115
  $sql = "CREATE TABLE $table_name (
116
+ id bigint(20) NOT NULL AUTO_INCREMENT,
117
+ name tinytext NOT NULL default '',
118
+ description text NOT NULL default '',
119
+ code longtext NOT NULL default '',
120
+ tags longtext NOT NULL default '',
121
+ scope tinyint(1) NOT NULL default 0,
122
+ active tinyint(1) NOT NULL default 0,
123
+ PRIMARY KEY (id)
124
+ ) $charset_collate;";
125
 
126
  dbDelta( $sql );
 
127
  do_action( 'code_snippets/create_table', $table_name );
128
  }
includes/edit/edit.php CHANGED
@@ -157,7 +157,7 @@ function code_snippets_load_single_menu() {
157
 
158
  /* Export the snippet if the button was clicked */
159
  elseif ( isset( $_POST['snippet_id'], $_POST['export_snippet'] ) ) {
160
- export_snippet( $_POST['snippet_id'] );
161
  }
162
  }
163
 
157
 
158
  /* Export the snippet if the button was clicked */
159
  elseif ( isset( $_POST['snippet_id'], $_POST['export_snippet'] ) ) {
160
+ export_snippets( $_POST['snippet_id'] );
161
  }
162
  }
163
 
includes/manage/class-list-table.php CHANGED
@@ -456,7 +456,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
456
  * @uses activate_snippet() To activate snippets
457
  * @uses deactivate_snippet() To deactivate snippets
458
  * @uses delete_snippet() To delete snippets
459
- * @uses export_snippet() To export selected snippets
460
  * @uses wp_redirect() To pass the results to the current page
461
  * @uses add_query_arg() To append the results to the current URI
462
  */
456
  * @uses activate_snippet() To activate snippets
457
  * @uses deactivate_snippet() To deactivate snippets
458
  * @uses delete_snippet() To delete snippets
459
+ * @uses export_snippets() To export selected snippets
460
  * @uses wp_redirect() To pass the results to the current page
461
  * @uses add_query_arg() To append the results to the current URI
462
  */
includes/snippet-ops.php CHANGED
@@ -151,9 +151,14 @@ function escape_snippet_data( $snippet ) {
151
  /* Remove ?> from end of snippet */
152
  $snippet->code = preg_replace( '|\?>[\s]*$|', '', $snippet->code );
153
 
154
- /* Escape the data */
155
  $snippet->id = absint( $snippet->id );
156
 
 
 
 
 
 
157
  /* Store tags as a string, with tags separated by commas */
158
  $snippet->tags = code_snippets_build_tags_array( $snippet->tags );
159
  $snippet->tags = implode( ', ', $snippet->tags );
@@ -370,7 +375,7 @@ function import_snippets( $file, $multisite = null ) {
370
  $dom->load( $file );
371
 
372
  $snippets_xml = $dom->getElementsByTagName( 'snippet' );
373
- $fields = array( 'name', 'description', 'code', 'tags' );
374
  $count = 0;
375
 
376
  /* Loop through all snippets */
151
  /* Remove ?> from end of snippet */
152
  $snippet->code = preg_replace( '|\?>[\s]*$|', '', $snippet->code );
153
 
154
+ /* Ensure the ID is a positive integer */
155
  $snippet->id = absint( $snippet->id );
156
 
157
+ /* Make sure that the scope is a valid value */
158
+ if ( ! in_array( $snippet->scope, array( 0, 1, 2 ) ) ) {
159
+ $snippet->scope = 0;
160
+ }
161
+
162
  /* Store tags as a string, with tags separated by commas */
163
  $snippet->tags = code_snippets_build_tags_array( $snippet->tags );
164
  $snippet->tags = implode( ', ', $snippet->tags );
375
  $dom->load( $file );
376
 
377
  $snippets_xml = $dom->getElementsByTagName( 'snippet' );
378
+ $fields = array( 'name', 'description', 'code', 'tags', 'scope' );
379
  $count = 0;
380
 
381
  /* Loop through all snippets */
languages/code-snippets.pot CHANGED
@@ -6,9 +6,9 @@
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
- "Project-Id-Version: code-snippets 2.2.2\n"
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2015-05-11 21:14+1000\n"
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
+ "Project-Id-Version: code-snippets 2.2.3\n"
10
  "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2015-05-13 21:16+1000\n"
12
  "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
  "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
  "Language-Team: LANGUAGE <LL@li.org>\n"
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://bungeshea.com/donate/
4
  Tags: code-snippets, snippets, code, php, network, multisite
5
  Requires at least: 3.3
6
  Tested up to: 4.2.2
7
- Stable tag: 2.2.2
8
  License: MIT
9
  License URI: license.txt
10
 
@@ -116,6 +116,12 @@ That's fantastic! Fork the [repository on GitHub](http://github.com/sheabunge/co
116
 
117
  == Changelog ==
118
 
 
 
 
 
 
 
119
  = 2.2.2 =
120
  * Polyfilled array_replace_recursive() function for PHP 5.2
121
  * Updated references to old plugin site
@@ -332,6 +338,9 @@ __Fixed__
332
 
333
  == Upgrade Notice ==
334
 
 
 
 
335
  = 2.2.2 =
336
  Fix error with PHP 5.2 added statuses for scopes to manage snippets table
337
 
4
  Tags: code-snippets, snippets, code, php, network, multisite
5
  Requires at least: 3.3
6
  Tested up to: 4.2.2
7
+ Stable tag: 2.2.3
8
  License: MIT
9
  License URI: license.txt
10
 
116
 
117
  == Changelog ==
118
 
119
+ = 2.2.3 =
120
+ * Fixed broken call to `export_snippet()` function
121
+ * Added support for importing and exporting snippet scope
122
+ * Fixed duplicate primary key database error
123
+ * Improved database table structure
124
+
125
  = 2.2.2 =
126
  * Polyfilled array_replace_recursive() function for PHP 5.2
127
  * Updated references to old plugin site
338
 
339
  == Upgrade Notice ==
340
 
341
+ = 2.2.3 =
342
+ Fixed error when exporting; snippet scopes can now be imported
343
+
344
  = 2.2.2 =
345
  Fix error with PHP 5.2 added statuses for scopes to manage snippets table
346