Code Snippets - Version 2.4.2

Version Description

  • Added query variable to activate safe mode
  • Fixed settings not saving
  • Fixed snippet descriptions not displaying on manage menu
  • Added settings to disable description and tag editors
  • Fixed: Load CodeMirror after plugin styles to fix error with Zenburn theme
  • Fixed: Hide snippet scope icons when the scope selector is disabled
  • Fixed description heading on edt snippet menu being hidden when visual editor disabled
  • Updated editor preview updating code to use vanilla JavaScript instead of jQuery
  • Fixed: Deactivate a shared network snippet on all subsites when it looses its sharing status
Download this release

Release Info

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

Code changes from version 2.4.1 to 2.4.2

code-snippets.php CHANGED
@@ -7,20 +7,20 @@
7
  * contribute to the localization, please see https://github.com/sheabunge/code-snippets
8
  *
9
  * @package Code_Snippets
10
- * @version 2.4.1
11
  * @author Shea Bunge <http://bungeshea.com/>
12
  * @copyright Copyright (c) 2012-2015, Shea Bunge
13
- * @link http://bungeshea.com/plugins/code-snippets/
14
  * @license http://opensource.org/licenses/MIT
15
  */
16
 
17
  /*
18
  Plugin Name: Code Snippets
19
- 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.4.1
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.4.1' );
46
 
47
  /**
48
  * The full path to the main file of this plugin
@@ -87,8 +87,9 @@ foreach ( array(
87
  'admin.php',
88
 
89
  /* Settings component */
90
- 'settings/editor-preview.php',
91
  'settings/settings-fields.php',
 
 
92
  'settings/settings.php',
93
 
94
  ) as $include ) {
7
  * contribute to the localization, please see https://github.com/sheabunge/code-snippets
8
  *
9
  * @package Code_Snippets
10
+ * @version 2.4.2
11
  * @author Shea Bunge <http://bungeshea.com/>
12
  * @copyright Copyright (c) 2012-2015, Shea Bunge
13
+ * @link https://github.com/sheabunge/code-snippets
14
  * @license http://opensource.org/licenses/MIT
15
  */
16
 
17
  /*
18
  Plugin Name: Code Snippets
19
+ Plugin URI: https://github.com/sheabunge/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.4.2
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.4.2' );
46
 
47
  /**
48
  * The full path to the main file of this plugin
87
  'admin.php',
88
 
89
  /* Settings component */
 
90
  'settings/settings-fields.php',
91
+ 'settings/editor-preview.php',
92
+ 'settings/render-fields.php',
93
  'settings/settings.php',
94
 
95
  ) as $include ) {
css/min/edit.css CHANGED
@@ -1 +1 @@
1
- .form-table th{width:auto}h3{margin:1em 0}label{cursor:auto}label[for='snippet_description'] h3 div{position:absolute}ul.tagit{background-color:#fff}.submit .button{margin-right:.5em}.snippet-scope div{margin-right:30px;display:inline-block}.CodeMirror{width:100%;height:auto;min-height:300px;border:1px solid #dfdfdf;border-radius:3px;background-color:#fff}.CodeMirror-scroll{overflow-x:auto;overflow-y:hidden}.CodeMirror-sizer{min-height:300px!important}.CodeMirror-focused .cm-matchhighlight{color:#fff!important;outline:1px solid green}
1
+ .form-table th{width:auto}h3{margin:1em 0}label{cursor:auto}label[for='snippet_description'] h3 div{position:absolute}ul.tagit{background-color:#fff!important}.submit .button{margin-right:.5em}.snippet-scope div{margin-right:30px;display:inline-block}.CodeMirror{width:100%;height:auto;min-height:300px;border:1px solid #dfdfdf;border-radius:3px;background-color:#fff}.CodeMirror-scroll{overflow-x:auto;overflow-y:hidden}.CodeMirror-sizer{min-height:300px!important}.CodeMirror-focused .cm-matchhighlight{color:#fff!important;outline:1px solid green}
languages/code-snippets.pot CHANGED
@@ -6,9 +6,9 @@
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
- "Project-Id-Version: code-snippets 2.4.1\n"
10
  "Report-Msgid-Bugs-To: \n"
11
- "POT-Creation-Date: 2015-09-17 21:24+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"
@@ -35,63 +35,63 @@ msgstr ""
35
  msgid "Add New Snippet"
36
  msgstr ""
37
 
38
- #: php/admin-menus/class-edit-menu.php:180 php/class-list-table.php:324
39
  msgid "Description"
40
  msgstr ""
41
 
42
- #: php/admin-menus/class-edit-menu.php:205 php/class-list-table.php:325
43
  msgid "Tags"
44
  msgstr ""
45
 
46
- #: php/admin-menus/class-edit-menu.php:209
47
  msgid "Enter a list of tags; separated by commas"
48
  msgstr ""
49
 
50
- #: php/admin-menus/class-edit-menu.php:228
51
  msgid "Run snippet everywhere"
52
  msgstr ""
53
 
54
- #: php/admin-menus/class-edit-menu.php:229
55
- msgid "Only run in adminstration area"
56
  msgstr ""
57
 
58
- #: php/admin-menus/class-edit-menu.php:230
59
  msgid "Only run on site front-end"
60
  msgstr ""
61
 
62
- #: php/admin-menus/class-edit-menu.php:234
63
  msgid "Scope"
64
  msgstr ""
65
 
66
- #: php/admin-menus/class-edit-menu.php:254
67
  msgid "Sharing"
68
  msgstr ""
69
 
70
- #: php/admin-menus/class-edit-menu.php:258
71
  msgid "Allow this snippet to be activated on individual sites on the network"
72
  msgstr ""
73
 
74
- #: php/admin-menus/class-edit-menu.php:272
75
  msgid "An error occurred when saving the snippet."
76
  msgstr ""
77
 
78
- #: php/admin-menus/class-edit-menu.php:282
79
  msgid "Snippet <strong>added</strong>."
80
  msgstr ""
81
 
82
- #: php/admin-menus/class-edit-menu.php:283
83
  msgid "Snippet <strong>updated</strong>."
84
  msgstr ""
85
 
86
- #: php/admin-menus/class-edit-menu.php:284
87
  msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
88
  msgstr ""
89
 
90
- #: php/admin-menus/class-edit-menu.php:285
91
  msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
92
  msgstr ""
93
 
94
- #: php/admin-menus/class-edit-menu.php:286
95
  msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
96
  msgstr ""
97
 
@@ -265,21 +265,21 @@ msgstr ""
265
  msgid "Snippets per page"
266
  msgstr ""
267
 
268
- #: php/class-list-table.php:117 php/class-list-table.php:361
269
  msgid "Network Deactivate"
270
  msgstr ""
271
 
272
  #: php/class-list-table.php:117 php/class-list-table.php:180
273
- #: php/class-list-table.php:361
274
  msgid "Deactivate"
275
  msgstr ""
276
 
277
- #: php/class-list-table.php:126 php/class-list-table.php:360
278
  msgid "Network Activate"
279
  msgstr ""
280
 
281
  #: php/class-list-table.php:126 php/class-list-table.php:180
282
- #: php/class-list-table.php:360
283
  msgid "Activate"
284
  msgstr ""
285
 
@@ -288,12 +288,12 @@ msgid "Edit"
288
  msgstr ""
289
 
290
  #: php/class-list-table.php:142 php/class-list-table.php:202
291
- #: php/class-list-table.php:362 php/views/edit.php:109
292
  msgid "Export"
293
  msgstr ""
294
 
295
  #: php/class-list-table.php:151 php/class-list-table.php:214
296
- #: php/class-list-table.php:363 php/views/edit.php:121
297
  msgid "Delete"
298
  msgstr ""
299
 
@@ -320,72 +320,72 @@ msgstr ""
320
  msgid "ID"
321
  msgstr ""
322
 
323
- #: php/class-list-table.php:364
324
  msgid "Export to PHP"
325
  msgstr ""
326
 
327
- #: php/class-list-table.php:402
328
  #, php-format
329
  msgid "All <span class=\"count\">(%s)</span>"
330
  msgid_plural "All <span class=\"count\">(%s)</span>"
331
  msgstr[0] ""
332
  msgstr[1] ""
333
 
334
- #: php/class-list-table.php:403
335
  #, php-format
336
  msgid "Active <span class=\"count\">(%s)</span>"
337
  msgid_plural "Active <span class=\"count\">(%s)</span>"
338
  msgstr[0] ""
339
  msgstr[1] ""
340
 
341
- #: php/class-list-table.php:404
342
  #, php-format
343
  msgid "Inactive <span class=\"count\">(%s)</span>"
344
  msgid_plural "Inactive <span class=\"count\">(%s)</span>"
345
  msgstr[0] ""
346
  msgstr[1] ""
347
 
348
- #: php/class-list-table.php:405
349
  #, php-format
350
  msgid "Recently Active <span class=\"count\">(%s)</span>"
351
  msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
352
  msgstr[0] ""
353
  msgstr[1] ""
354
 
355
- #: php/class-list-table.php:468
356
  msgid "Show all tags"
357
  msgstr ""
358
 
359
- #: php/class-list-table.php:482
360
  msgid "Filter"
361
  msgstr ""
362
 
363
- #: php/class-list-table.php:490
364
  msgid "Clear List"
365
  msgstr ""
366
 
367
- #: php/class-list-table.php:677
368
  #, php-format
369
  msgid ""
370
  "You do not appear to have any snippets available at this time. <a href=\"%s"
371
  "\">Add New&rarr;</a>"
372
  msgstr ""
373
 
374
- #: php/class-list-table.php:956
375
  msgid "Search results"
376
  msgstr ""
377
 
378
- #: php/class-list-table.php:959
379
  #, php-format
380
  msgid " for &#8220;%s&#8221;"
381
  msgstr ""
382
 
383
- #: php/class-list-table.php:963
384
  #, php-format
385
  msgid " in tag &#8220;%s&#8221;"
386
  msgstr ""
387
 
388
- #: php/class-list-table.php:971
389
  msgid "Clear Filters"
390
  msgstr ""
391
 
@@ -557,124 +557,140 @@ msgid ""
557
  "<a href=\"%s\">Manage Snippets</a> page."
558
  msgstr ""
559
 
560
- #: php/settings/class-settings.php:54
561
  msgid "Activate by Default"
562
  msgstr ""
563
 
564
- #: php/settings/class-settings.php:56
565
  msgid ""
566
  "Make the 'Save and Activate' button the default action when saving a snippet."
567
  msgstr ""
568
 
569
- #: php/settings/class-settings.php:62
570
  msgid "Enable Scope Selector"
571
  msgstr ""
572
 
573
- #: php/settings/class-settings.php:64
574
  msgid "Enable the scope selector when editing a snippet"
575
  msgstr ""
576
 
577
- #: php/settings/class-settings.php:74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
578
  msgid "Row Height"
579
  msgstr ""
580
 
581
- #: php/settings/class-settings.php:76
582
  msgid "rows"
583
  msgstr ""
584
 
585
- #: php/settings/class-settings.php:83
586
  msgid "Use Full Editor"
587
  msgstr ""
588
 
589
- #: php/settings/class-settings.php:85
590
  msgid "Enable all features of the visual editor"
591
  msgstr ""
592
 
593
- #: php/settings/class-settings.php:91
594
  msgid "Media Buttons"
595
  msgstr ""
596
 
597
- #: php/settings/class-settings.php:93
598
  msgid "Enable the add media buttons"
599
  msgstr ""
600
 
601
- #: php/settings/class-settings.php:103
602
  msgid "Theme"
603
  msgstr ""
604
 
605
- #: php/settings/class-settings.php:111
606
  msgid "Indent With Tabs"
607
  msgstr ""
608
 
609
- #: php/settings/class-settings.php:113
610
  msgid "Use hard tabs (not spaces) for indentation."
611
  msgstr ""
612
 
613
- #: php/settings/class-settings.php:120
614
  msgid "Tab Size"
615
  msgstr ""
616
 
617
- #: php/settings/class-settings.php:122
618
  msgid "The width of a tab character."
619
  msgstr ""
620
 
621
- #: php/settings/class-settings.php:130
622
  msgid "Indent Unit"
623
  msgstr ""
624
 
625
- #: php/settings/class-settings.php:132
626
  msgid "How many spaces a block should be indented."
627
  msgstr ""
628
 
629
- #: php/settings/class-settings.php:140
630
  msgid "Wrap Lines"
631
  msgstr ""
632
 
633
- #: php/settings/class-settings.php:142
634
  msgid "Whether the editor should scroll or wrap for long lines."
635
  msgstr ""
636
 
637
- #: php/settings/class-settings.php:149
638
  msgid "Line Numbers"
639
  msgstr ""
640
 
641
- #: php/settings/class-settings.php:151
642
  msgid "Show line numbers to the left of the editor."
643
  msgstr ""
644
 
645
- #: php/settings/class-settings.php:158
646
  msgid "Auto Close Brackets"
647
  msgstr ""
648
 
649
- #: php/settings/class-settings.php:160
650
  msgid "Auto-close brackets and quotes when typed."
651
  msgstr ""
652
 
653
- #: php/settings/class-settings.php:167
654
  msgid "Highlight Selection Matches"
655
  msgstr ""
656
 
657
- #: php/settings/class-settings.php:168
658
  msgid "Highlight all instances of a currently selected word."
659
  msgstr ""
660
 
661
- #: php/settings/settings.php:86
662
  msgid "General"
663
  msgstr ""
664
 
665
- #: php/settings/settings.php:87
666
  msgid "Description Editor"
667
  msgstr ""
668
 
669
- #: php/settings/settings.php:88
670
  msgid "Code Editor"
671
  msgstr ""
672
 
673
- #: php/settings/settings.php:136
674
  msgid "Editor Preview"
675
  msgstr ""
676
 
677
- #: php/settings/settings.php:183
678
  msgid "Settings saved."
679
  msgstr ""
680
 
6
  #, fuzzy
7
  msgid ""
8
  msgstr ""
9
+ "Project-Id-Version: code-snippets 2.4.2\n"
10
  "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2015-09-27 23:35+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"
35
  msgid "Add New Snippet"
36
  msgstr ""
37
 
38
+ #: php/admin-menus/class-edit-menu.php:201 php/class-list-table.php:324
39
  msgid "Description"
40
  msgstr ""
41
 
42
+ #: php/admin-menus/class-edit-menu.php:231 php/class-list-table.php:325
43
  msgid "Tags"
44
  msgstr ""
45
 
46
+ #: php/admin-menus/class-edit-menu.php:235
47
  msgid "Enter a list of tags; separated by commas"
48
  msgstr ""
49
 
50
+ #: php/admin-menus/class-edit-menu.php:254
51
  msgid "Run snippet everywhere"
52
  msgstr ""
53
 
54
+ #: php/admin-menus/class-edit-menu.php:255
55
+ msgid "Only run in administration area"
56
  msgstr ""
57
 
58
+ #: php/admin-menus/class-edit-menu.php:256
59
  msgid "Only run on site front-end"
60
  msgstr ""
61
 
62
+ #: php/admin-menus/class-edit-menu.php:260
63
  msgid "Scope"
64
  msgstr ""
65
 
66
+ #: php/admin-menus/class-edit-menu.php:280
67
  msgid "Sharing"
68
  msgstr ""
69
 
70
+ #: php/admin-menus/class-edit-menu.php:284
71
  msgid "Allow this snippet to be activated on individual sites on the network"
72
  msgstr ""
73
 
74
+ #: php/admin-menus/class-edit-menu.php:298
75
  msgid "An error occurred when saving the snippet."
76
  msgstr ""
77
 
78
+ #: php/admin-menus/class-edit-menu.php:308
79
  msgid "Snippet <strong>added</strong>."
80
  msgstr ""
81
 
82
+ #: php/admin-menus/class-edit-menu.php:309
83
  msgid "Snippet <strong>updated</strong>."
84
  msgstr ""
85
 
86
+ #: php/admin-menus/class-edit-menu.php:310
87
  msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
88
  msgstr ""
89
 
90
+ #: php/admin-menus/class-edit-menu.php:311
91
  msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
92
  msgstr ""
93
 
94
+ #: php/admin-menus/class-edit-menu.php:312
95
  msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
96
  msgstr ""
97
 
265
  msgid "Snippets per page"
266
  msgstr ""
267
 
268
+ #: php/class-list-table.php:117 php/class-list-table.php:370
269
  msgid "Network Deactivate"
270
  msgstr ""
271
 
272
  #: php/class-list-table.php:117 php/class-list-table.php:180
273
+ #: php/class-list-table.php:370
274
  msgid "Deactivate"
275
  msgstr ""
276
 
277
+ #: php/class-list-table.php:126 php/class-list-table.php:369
278
  msgid "Network Activate"
279
  msgstr ""
280
 
281
  #: php/class-list-table.php:126 php/class-list-table.php:180
282
+ #: php/class-list-table.php:369
283
  msgid "Activate"
284
  msgstr ""
285
 
288
  msgstr ""
289
 
290
  #: php/class-list-table.php:142 php/class-list-table.php:202
291
+ #: php/class-list-table.php:371 php/views/edit.php:109
292
  msgid "Export"
293
  msgstr ""
294
 
295
  #: php/class-list-table.php:151 php/class-list-table.php:214
296
+ #: php/class-list-table.php:372 php/views/edit.php:121
297
  msgid "Delete"
298
  msgstr ""
299
 
320
  msgid "ID"
321
  msgstr ""
322
 
323
+ #: php/class-list-table.php:373
324
  msgid "Export to PHP"
325
  msgstr ""
326
 
327
+ #: php/class-list-table.php:411
328
  #, php-format
329
  msgid "All <span class=\"count\">(%s)</span>"
330
  msgid_plural "All <span class=\"count\">(%s)</span>"
331
  msgstr[0] ""
332
  msgstr[1] ""
333
 
334
+ #: php/class-list-table.php:412
335
  #, php-format
336
  msgid "Active <span class=\"count\">(%s)</span>"
337
  msgid_plural "Active <span class=\"count\">(%s)</span>"
338
  msgstr[0] ""
339
  msgstr[1] ""
340
 
341
+ #: php/class-list-table.php:413
342
  #, php-format
343
  msgid "Inactive <span class=\"count\">(%s)</span>"
344
  msgid_plural "Inactive <span class=\"count\">(%s)</span>"
345
  msgstr[0] ""
346
  msgstr[1] ""
347
 
348
+ #: php/class-list-table.php:414
349
  #, php-format
350
  msgid "Recently Active <span class=\"count\">(%s)</span>"
351
  msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
352
  msgstr[0] ""
353
  msgstr[1] ""
354
 
355
+ #: php/class-list-table.php:477
356
  msgid "Show all tags"
357
  msgstr ""
358
 
359
+ #: php/class-list-table.php:491
360
  msgid "Filter"
361
  msgstr ""
362
 
363
+ #: php/class-list-table.php:499
364
  msgid "Clear List"
365
  msgstr ""
366
 
367
+ #: php/class-list-table.php:686
368
  #, php-format
369
  msgid ""
370
  "You do not appear to have any snippets available at this time. <a href=\"%s"
371
  "\">Add New&rarr;</a>"
372
  msgstr ""
373
 
374
+ #: php/class-list-table.php:965
375
  msgid "Search results"
376
  msgstr ""
377
 
378
+ #: php/class-list-table.php:968
379
  #, php-format
380
  msgid " for &#8220;%s&#8221;"
381
  msgstr ""
382
 
383
+ #: php/class-list-table.php:972
384
  #, php-format
385
  msgid " in tag &#8220;%s&#8221;"
386
  msgstr ""
387
 
388
+ #: php/class-list-table.php:980
389
  msgid "Clear Filters"
390
  msgstr ""
391
 
557
  "<a href=\"%s\">Manage Snippets</a> page."
558
  msgstr ""
559
 
560
+ #: php/settings/settings-fields.php:42
561
  msgid "Activate by Default"
562
  msgstr ""
563
 
564
+ #: php/settings/settings-fields.php:44
565
  msgid ""
566
  "Make the 'Save and Activate' button the default action when saving a snippet."
567
  msgstr ""
568
 
569
+ #: php/settings/settings-fields.php:49
570
  msgid "Enable Scope Selector"
571
  msgstr ""
572
 
573
+ #: php/settings/settings-fields.php:51
574
  msgid "Enable the scope selector when editing a snippet"
575
  msgstr ""
576
 
577
+ #: php/settings/settings-fields.php:56
578
+ msgid "Enable Snippet Tags"
579
+ msgstr ""
580
+
581
+ #: php/settings/settings-fields.php:58
582
+ msgid "Show snippet tags on admin pages"
583
+ msgstr ""
584
+
585
+ #: php/settings/settings-fields.php:63
586
+ msgid "Enable Snippet Descriptions"
587
+ msgstr ""
588
+
589
+ #: php/settings/settings-fields.php:65
590
+ msgid "Show snippet descriptions on admin pages"
591
+ msgstr ""
592
+
593
+ #: php/settings/settings-fields.php:74
594
  msgid "Row Height"
595
  msgstr ""
596
 
597
+ #: php/settings/settings-fields.php:76
598
  msgid "rows"
599
  msgstr ""
600
 
601
+ #: php/settings/settings-fields.php:82
602
  msgid "Use Full Editor"
603
  msgstr ""
604
 
605
+ #: php/settings/settings-fields.php:84
606
  msgid "Enable all features of the visual editor"
607
  msgstr ""
608
 
609
+ #: php/settings/settings-fields.php:89
610
  msgid "Media Buttons"
611
  msgstr ""
612
 
613
+ #: php/settings/settings-fields.php:91
614
  msgid "Enable the add media buttons"
615
  msgstr ""
616
 
617
+ #: php/settings/settings-fields.php:100
618
  msgid "Theme"
619
  msgstr ""
620
 
621
+ #: php/settings/settings-fields.php:107
622
  msgid "Indent With Tabs"
623
  msgstr ""
624
 
625
+ #: php/settings/settings-fields.php:109
626
  msgid "Use hard tabs (not spaces) for indentation."
627
  msgstr ""
628
 
629
+ #: php/settings/settings-fields.php:115
630
  msgid "Tab Size"
631
  msgstr ""
632
 
633
+ #: php/settings/settings-fields.php:117
634
  msgid "The width of a tab character."
635
  msgstr ""
636
 
637
+ #: php/settings/settings-fields.php:124
638
  msgid "Indent Unit"
639
  msgstr ""
640
 
641
+ #: php/settings/settings-fields.php:126
642
  msgid "How many spaces a block should be indented."
643
  msgstr ""
644
 
645
+ #: php/settings/settings-fields.php:133
646
  msgid "Wrap Lines"
647
  msgstr ""
648
 
649
+ #: php/settings/settings-fields.php:135
650
  msgid "Whether the editor should scroll or wrap for long lines."
651
  msgstr ""
652
 
653
+ #: php/settings/settings-fields.php:141
654
  msgid "Line Numbers"
655
  msgstr ""
656
 
657
+ #: php/settings/settings-fields.php:143
658
  msgid "Show line numbers to the left of the editor."
659
  msgstr ""
660
 
661
+ #: php/settings/settings-fields.php:149
662
  msgid "Auto Close Brackets"
663
  msgstr ""
664
 
665
+ #: php/settings/settings-fields.php:151
666
  msgid "Auto-close brackets and quotes when typed."
667
  msgstr ""
668
 
669
+ #: php/settings/settings-fields.php:157
670
  msgid "Highlight Selection Matches"
671
  msgstr ""
672
 
673
+ #: php/settings/settings-fields.php:158
674
  msgid "Highlight all instances of a currently selected word."
675
  msgstr ""
676
 
677
+ #: php/settings/settings.php:68
678
  msgid "General"
679
  msgstr ""
680
 
681
+ #: php/settings/settings.php:69
682
  msgid "Description Editor"
683
  msgstr ""
684
 
685
+ #: php/settings/settings.php:70
686
  msgid "Code Editor"
687
  msgstr ""
688
 
689
+ #: php/settings/settings.php:119
690
  msgid "Editor Preview"
691
  msgstr ""
692
 
693
+ #: php/settings/settings.php:165
694
  msgid "Settings saved."
695
  msgstr ""
696
 
php/admin-menus/class-edit-menu.php CHANGED
@@ -53,11 +53,17 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
53
  code_snippets_load_edit_help();
54
 
55
  /* Enqueue the code editor and other scripts and styles */
56
- add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_assets' ), 9 );
 
57
 
58
  /* Register action hooks */
59
- add_action( 'code_snippets/admin/single', array( $this, 'render_description_editor' ), 9 );
60
- add_action( 'code_snippets/admin/single', array( $this, 'render_tags_editor' ) );
 
 
 
 
 
61
 
62
  if ( code_snippets_get_setting( 'general', 'snippet_scope_enabled' ) ) {
63
  add_action( 'code_snippets/admin/single/settings', array( $this, 'render_scope_setting' ) );
@@ -126,6 +132,24 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
126
  /* Remove the snippet ID from the array */
127
  $shared_snippets = array_diff( $shared_snippets, array( $snippet_id ) );
128
  update_site_option( 'shared_network_snippets', array_values( $shared_snippets ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
  }
131
 
@@ -174,23 +198,25 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
174
  function render_description_editor( Snippet $snippet ) {
175
  $settings = code_snippets_get_settings();
176
  $settings = $settings['description_editor'];
177
- $media_buttons = $settings['media_buttons'];
178
-
179
- echo '<label for="snippet_description"><h3>';
180
  $heading = __( 'Description', 'code-snippets' );
181
- echo $media_buttons ? $heading : "<div>$heading</div>";
182
- echo '</h3></label>';
 
 
 
 
 
183
 
184
  remove_editor_styles(); // stop custom theme styling interfering with the editor
185
 
186
  wp_editor(
187
- $snippet->description,
188
  'description',
189
  apply_filters( 'code_snippets/admin/description_editor_settings', array(
190
  'textarea_name' => 'snippet_description',
191
  'textarea_rows' => $settings['rows'],
192
  'teeny' => ! $settings['use_full_mce'],
193
- 'media_buttons' => $media_buttons,
194
  ) )
195
  );
196
  }
@@ -226,7 +252,7 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
226
 
227
  $scopes = array(
228
  __( 'Run snippet everywhere', 'code-snippets' ),
229
- __( 'Only run in adminstration area', 'code-snippets' ),
230
  __( 'Only run on site front-end', 'code-snippets' ),
231
  );
232
 
@@ -290,18 +316,12 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
290
  }
291
 
292
  /**
293
- * Registers and loads the code editor's assets
294
- *
295
- * @uses wp_enqueue_style() to add the stylesheets to the queue
296
- * @uses wp_enqueue_script() to add the scripts to the queue
297
  */
298
- function enqueue_assets() {
299
  $tagit_version = '2.0';
300
  $url = plugin_dir_url( CODE_SNIPPETS_FILE );
301
 
302
- /* Enqueue CodeMirror */
303
- code_snippets_enqueue_codemirror();
304
-
305
  /* Tag It UI */
306
  wp_enqueue_script(
307
  'code-snippets-tag-it',
53
  code_snippets_load_edit_help();
54
 
55
  /* Enqueue the code editor and other scripts and styles */
56
+ add_action( 'admin_enqueue_scripts', 'code_snippets_enqueue_codemirror' );
57
+ add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_tagit' ), 9 );
58
 
59
  /* Register action hooks */
60
+ if ( code_snippets_get_setting( 'general', 'enable_description' ) ) {
61
+ add_action( 'code_snippets/admin/single', array( $this, 'render_description_editor' ), 9 );
62
+ }
63
+
64
+ if ( code_snippets_get_setting( 'general', 'enable_tags' ) ) {
65
+ add_action( 'code_snippets/admin/single', array( $this, 'render_tags_editor' ) );
66
+ }
67
 
68
  if ( code_snippets_get_setting( 'general', 'snippet_scope_enabled' ) ) {
69
  add_action( 'code_snippets/admin/single/settings', array( $this, 'render_scope_setting' ) );
132
  /* Remove the snippet ID from the array */
133
  $shared_snippets = array_diff( $shared_snippets, array( $snippet_id ) );
134
  update_site_option( 'shared_network_snippets', array_values( $shared_snippets ) );
135
+
136
+ /* Deactivate on all sites */
137
+ global $wpdb;
138
+ if ( $sites = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) ) {
139
+
140
+ foreach ( $sites as $site ) {
141
+ switch_to_blog( $site );
142
+ $active_shared_snippets = get_option( 'active_shared_network_snippets' );
143
+
144
+ if ( is_array( $active_shared_snippets ) ) {
145
+ $active_shared_snippets = array_diff( $active_shared_snippets, array( $snippet_id ) );
146
+ update_option( 'active_shared_network_snippets', $active_shared_snippets );
147
+ }
148
+ }
149
+
150
+ restore_current_blog();
151
+ }
152
+
153
  }
154
  }
155
 
198
  function render_description_editor( Snippet $snippet ) {
199
  $settings = code_snippets_get_settings();
200
  $settings = $settings['description_editor'];
 
 
 
201
  $heading = __( 'Description', 'code-snippets' );
202
+
203
+ /* Hack to remove space between heading and editor tabs */
204
+ if ( ! $settings['media_buttons'] && 'false' !== get_user_option( 'rich_editing' ) ) {
205
+ $heading = "<div>$heading</div>";
206
+ }
207
+
208
+ echo '<label for="snippet_description"><h3>', $heading, '</h3></label>';
209
 
210
  remove_editor_styles(); // stop custom theme styling interfering with the editor
211
 
212
  wp_editor(
213
+ $snippet->desc,
214
  'description',
215
  apply_filters( 'code_snippets/admin/description_editor_settings', array(
216
  'textarea_name' => 'snippet_description',
217
  'textarea_rows' => $settings['rows'],
218
  'teeny' => ! $settings['use_full_mce'],
219
+ 'media_buttons' => $settings['media_buttons'],
220
  ) )
221
  );
222
  }
252
 
253
  $scopes = array(
254
  __( 'Run snippet everywhere', 'code-snippets' ),
255
+ __( 'Only run in administration area', 'code-snippets' ),
256
  __( 'Only run on site front-end', 'code-snippets' ),
257
  );
258
 
316
  }
317
 
318
  /**
319
+ * Enqueue the Tag It library
 
 
 
320
  */
321
+ function enqueue_tagit() {
322
  $tagit_version = '2.0';
323
  $url = plugin_dir_url( CODE_SNIPPETS_FILE );
324
 
 
 
 
325
  /* Tag It UI */
326
  wp_enqueue_script(
327
  'code-snippets-tag-it',
php/admin-menus/class-settings-menu.php CHANGED
@@ -37,12 +37,14 @@ class Code_Snippets_Settings_Menu extends Code_Snippets_Admin_Menu {
37
 
38
  <?php settings_errors( 'code-snippets-settings-notices' ); ?>
39
 
40
- <form action="<?php admin_url( 'options.php' ); ?>" method="post">
41
- <?php settings_fields( 'code-snippets' ); ?>
42
- <table class="form-table">
43
- <?php do_settings_sections( 'code-snippets' ); ?>
44
- </table>
45
- <?php submit_button(); ?>
 
 
46
  </form>
47
  </div>
48
  <?php
37
 
38
  <?php settings_errors( 'code-snippets-settings-notices' ); ?>
39
 
40
+ <form action="<?php echo admin_url( 'options.php' ); ?>" method="post">
41
+ <?php
42
+
43
+ settings_fields( 'code-snippets' );
44
+ do_settings_sections( 'code-snippets' );
45
+ submit_button();
46
+
47
+ ?>
48
  </form>
49
  </div>
50
  <?php
php/class-list-table.php CHANGED
@@ -94,8 +94,8 @@ class Code_Snippets_List_Table extends WP_List_Table {
94
  case 'id':
95
  return $snippet->id;
96
  case 'description':
97
- return empty( $snippet->description ) ? '&#8212;' :
98
- apply_filters( 'code_snippets/list_table/column_description', $snippet->description );
99
  default:
100
  return apply_filters( "code_snippets/list_table/column_{$column_name}", $snippet );
101
  }
@@ -324,6 +324,15 @@ class Code_Snippets_List_Table extends WP_List_Table {
324
  'description' => __( 'Description', 'code-snippets' ),
325
  'tags' => __( 'Tags', 'code-snippets' ),
326
  );
 
 
 
 
 
 
 
 
 
327
  return apply_filters( 'code_snippets/list_table/columns', $columns );
328
  }
329
 
@@ -980,7 +989,10 @@ class Code_Snippets_List_Table extends WP_List_Table {
980
  */
981
  public function single_row( $snippet ) {
982
  $row_class = ( $snippet->active ? 'active' : 'inactive' );
983
- $row_class .= sprintf( ' %s-scope', $snippet->scope_name );
 
 
 
984
 
985
  if ( $snippet->shared_network ) {
986
  $row_class .= ' shared-network';
94
  case 'id':
95
  return $snippet->id;
96
  case 'description':
97
+ return empty( $snippet->desc ) ? '&#8212;' :
98
+ apply_filters( 'code_snippets/list_table/column_description', $snippet->desc );
99
  default:
100
  return apply_filters( "code_snippets/list_table/column_{$column_name}", $snippet );
101
  }
324
  'description' => __( 'Description', 'code-snippets' ),
325
  'tags' => __( 'Tags', 'code-snippets' ),
326
  );
327
+
328
+ if ( ! code_snippets_get_setting( 'general', 'enable_description' ) ) {
329
+ unset( $columns['description'] );
330
+ }
331
+
332
+ if ( ! code_snippets_get_setting( 'general', 'enable_tags' ) ) {
333
+ unset( $columns['tags'] );
334
+ }
335
+
336
  return apply_filters( 'code_snippets/list_table/columns', $columns );
337
  }
338
 
989
  */
990
  public function single_row( $snippet ) {
991
  $row_class = ( $snippet->active ? 'active' : 'inactive' );
992
+
993
+ if ( code_snippets_get_setting( 'general', 'snippet_scope_enabled' ) ) {
994
+ $row_class .= sprintf( ' %s-scope', $snippet->scope_name );
995
+ }
996
 
997
  if ( $snippet->shared_network ) {
998
  $row_class .= ' shared-network';
php/class-snippet.php CHANGED
@@ -74,6 +74,12 @@ class Snippet {
74
  * @return bool Whether the field is set
75
  */
76
  public function __isset( $field ) {
 
 
 
 
 
 
77
  return isset( $this->fields[ $field ] ) || method_exists( $this, 'get_' . $field );
78
  }
79
 
74
  * @return bool Whether the field is set
75
  */
76
  public function __isset( $field ) {
77
+
78
+ /* Rename the description field */
79
+ if ( 'description' === $field ) {
80
+ $field = 'desc';
81
+ }
82
+
83
  return isset( $this->fields[ $field ] ) || method_exists( $this, 'get_' . $field );
84
  }
85
 
php/editor.php CHANGED
@@ -18,8 +18,8 @@ function code_snippets_get_editor_atts( $override_atts, $json_encode ) {
18
  'matchBrackets' => true,
19
  );
20
 
21
- foreach ( $fields as $field ) {
22
- $saved_atts[ $field['codemirror'] ] = $settings[ $field['id'] ];
23
  }
24
 
25
  $atts = wp_parse_args( $override_atts, $saved_atts );
18
  'matchBrackets' => true,
19
  );
20
 
21
+ foreach ( $fields as $field_id => $field ) {
22
+ $saved_atts[ $field['codemirror'] ] = $settings[ $field_id ];
23
  }
24
 
25
  $atts = wp_parse_args( $override_atts, $saved_atts );
php/settings/class-settings.php DELETED
@@ -1,177 +0,0 @@
1
- <?php
2
-
3
- /**
4
- * This class holds the settings fields array
5
- * @since 2.1.0
6
- */
7
- class Code_Snippets_Settings {
8
-
9
- private static $fields = array();
10
- private static $defaults = array();
11
-
12
- /**
13
- * Retrieve the defined fields
14
- * @return array
15
- */
16
- public static function get_fields() {
17
- if ( empty( self::$fields ) ) {
18
- self::set_fields();
19
- }
20
-
21
- return self::$fields;
22
- }
23
-
24
- /**
25
- * Retrieve the default values of the fields
26
- * @return array the default field values, keyed by ID
27
- */
28
- public static function get_defaults() {
29
- if ( empty( self::$defaults ) ) {
30
- self::set_defaults();
31
- }
32
-
33
- return self::$defaults;
34
- }
35
-
36
- /**
37
- * Loop through the settings fields and extract the default values
38
- */
39
- private static function set_defaults() {
40
-
41
- foreach ( self::get_fields() as $section_id => $section_fields ) {
42
- self::$defaults[ $section_id ] = wp_list_pluck( $section_fields, 'default', 'id' );
43
- }
44
- }
45
-
46
- /**
47
- * Define the settings fields
48
- */
49
- private static function set_fields() {
50
-
51
- self::$fields['general'] = array(
52
- array(
53
- 'id' => 'activate_by_default',
54
- 'name' => __( 'Activate by Default', 'code-snippets' ),
55
- 'type' => 'checkbox',
56
- 'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ),
57
- 'default' => false,
58
- ),
59
-
60
- array(
61
- 'id' => 'snippet_scope_enabled',
62
- 'name' => __( 'Enable Scope Selector', 'code-snippets' ),
63
- 'type' => 'checkbox',
64
- 'label' => __( 'Enable the scope selector when editing a snippet', 'code-snippets' ),
65
- 'default' => true,
66
- ),
67
- );
68
-
69
- /* Description Editor settings section */
70
- self::$fields['description_editor'] = array(
71
-
72
- array(
73
- 'id' => 'rows',
74
- 'name' => __( 'Row Height', 'code-snippets' ),
75
- 'type' => 'number',
76
- 'label' => __( 'rows', 'code-snippets' ),
77
- 'default' => 5,
78
- 'min' => 0,
79
- ),
80
-
81
- array(
82
- 'id' => 'use_full_mce',
83
- 'name' => __( 'Use Full Editor', 'code-snippets' ),
84
- 'type' => 'checkbox',
85
- 'label' => __( 'Enable all features of the visual editor', 'code-snippets' ),
86
- 'default' => false,
87
- ),
88
-
89
- array(
90
- 'id' => 'media_buttons',
91
- 'name' => __( 'Media Buttons', 'code-snippets' ),
92
- 'type' => 'checkbox',
93
- 'label' => __( 'Enable the add media buttons', 'code-snippets' ),
94
- 'default' => false,
95
- ),
96
- );
97
-
98
- /* Code Editor settings section */
99
-
100
- self::$fields['editor'] = array(
101
- array(
102
- 'id' => 'theme',
103
- 'name' => __( 'Theme', 'code-snippets' ),
104
- 'type' => 'codemirror_theme_select',
105
- 'default' => 'default',
106
- 'codemirror' => 'theme',
107
- ),
108
-
109
- array(
110
- 'id' => 'indent_with_tabs',
111
- 'name' => __( 'Indent With Tabs', 'code-snippets' ),
112
- 'type' => 'checkbox',
113
- 'label' => __( 'Use hard tabs (not spaces) for indentation.', 'code-snippets' ),
114
- 'default' => true,
115
- 'codemirror' => 'indentWithTabs',
116
- ),
117
-
118
- array(
119
- 'id' => 'tab_size',
120
- 'name' => __( 'Tab Size', 'code-snippets' ),
121
- 'type' => 'number',
122
- 'desc' => __( 'The width of a tab character.', 'code-snippets' ),
123
- 'default' => 4,
124
- 'codemirror' => 'tabSize',
125
- 'min' => 0,
126
- ),
127
-
128
- array(
129
- 'id' => 'indent_unit',
130
- 'name' => __( 'Indent Unit', 'code-snippets' ),
131
- 'type' => 'number',
132
- 'desc' => __( 'How many spaces a block should be indented.', 'code-snippets' ),
133
- 'default' => 2,
134
- 'codemirror' => 'indentUnit',
135
- 'min' => 0,
136
- ),
137
-
138
- array(
139
- 'id' => 'wrap_lines',
140
- 'name' => __( 'Wrap Lines', 'code-snippets' ),
141
- 'type' => 'checkbox',
142
- 'label' => __( 'Whether the editor should scroll or wrap for long lines.', 'code-snippets' ),
143
- 'default' => true,
144
- 'codemirror' => 'lineWrapping',
145
- ),
146
-
147
- array(
148
- 'id' => 'line_numbers',
149
- 'name' => __( 'Line Numbers', 'code-snippets' ),
150
- 'type' => 'checkbox',
151
- 'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
152
- 'default' => true,
153
- 'codemirror' => 'lineNumbers',
154
- ),
155
-
156
- array(
157
- 'id' => 'auto_close_brackets',
158
- 'name' => __( 'Auto Close Brackets', 'code-snippets' ),
159
- 'type' => 'checkbox',
160
- 'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
161
- 'default' => true,
162
- 'codemirror' => 'autoCloseBrackets',
163
- ),
164
-
165
- array(
166
- 'id' => 'highlight_selection_matches',
167
- 'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
168
- 'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
169
- 'type' => 'checkbox',
170
- 'default' => true,
171
- 'codemirror' => 'highlightSelectionMatches',
172
- ),
173
- );
174
-
175
- self::$fields = apply_filters( 'code_snippets_settings_fields', self::$fields );
176
- }
177
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
php/settings/editor-preview.php CHANGED
@@ -100,57 +100,57 @@ add_filter( 'admin_footer_text', 'example_custom_admin_footer_text' );";
100
  <div style="max-width: 800px" id="code_snippets_editor_preview"></div>
101
 
102
  <script>
103
- (function( $ ) {
104
  'use strict';
105
 
106
- $(function() {
 
 
107
 
108
- // Load CodeMirror
109
- var atts = <?php echo code_snippets_get_editor_atts( $atts, true ); ?>;
110
- var editor = CodeMirror(document.getElementById('code_snippets_editor_preview'), atts);
111
 
112
- // Dynamically change editor settings
 
 
113
 
114
- <?php
115
 
116
- $fields = code_snippets_get_settings_fields();
117
- $fields = $fields['editor'];
118
-
119
- $types = wp_list_pluck( $fields, 'type', 'id' );
120
- $codemirror_atts = wp_list_pluck( $fields, 'codemirror', 'id' );
121
 
122
- foreach ( $codemirror_atts as $setting => $att_name ) {
123
 
124
- switch ( $types[ $setting ] ) {
125
 
126
- case 'codemirror_theme_select': ?>
127
 
128
- $( 'select[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
129
- editor.setOption( '<?php echo $att_name; ?>', $(this).val() );
130
- } );
131
 
132
- <?php break;
133
- case 'checkbox': ?>
134
 
135
- $( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
136
- editor.setOption( '<?php echo $att_name; ?>', $(this).is(':checked') );
137
- } );
138
 
139
- <?php break;
140
- case 'number': ?>
141
 
142
- $( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
143
- editor.setOption( '<?php echo $att_name; ?>', $(this).val() );
144
- } );
145
 
146
- <?php break;
147
- }
148
  }
149
- ?>
150
-
151
- });
152
 
153
- }(jQuery));
 
154
  </script>
155
 
156
  <?php
100
  <div style="max-width: 800px" id="code_snippets_editor_preview"></div>
101
 
102
  <script>
103
+ (function () {
104
  'use strict';
105
 
106
+ // Load CodeMirror
107
+ var atts = <?php echo code_snippets_get_editor_atts( $atts, true ); ?>;
108
+ var editor = CodeMirror(document.getElementById('code_snippets_editor_preview'), atts);
109
 
110
+ // Dynamically change editor settings
111
+ <?php
 
112
 
113
+ /* Retrieve editor settings */
114
+ $fields = code_snippets_get_settings_fields();
115
+ $fields = $fields['editor'];
116
 
117
+ foreach ( $fields as $setting => $field ) {
118
 
119
+ /* Only output settings which have a CodeMirror attribute */
120
+ if ( empty( $field['codemirror'] ) ) {
121
+ continue;
122
+ }
 
123
 
124
+ $att_name = $field['codemirror'];
125
 
126
+ switch ( $field['type'] ) {
127
 
128
+ case 'codemirror_theme_select': ?>
129
 
130
+ document.querySelector('select[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]').onchange = function () {
131
+ editor.setOption('<?php echo $att_name; ?>', this.options[this.selectedIndex].value);
132
+ };
133
 
134
+ <?php break;
135
+ case 'checkbox': ?>
136
 
137
+ document.querySelector('input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]').onchange = function () {
138
+ editor.setOption('<?php echo $att_name; ?>', this.checked);
139
+ };
140
 
141
+ <?php break;
142
+ case 'number': ?>
143
 
144
+ document.querySelector('input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]').onchange = function () {
145
+ editor.setOption( '<?php echo $att_name; ?>', this.value);
146
+ };
147
 
148
+ <?php break;
 
149
  }
150
+ }
 
 
151
 
152
+ ?>
153
+ }());
154
  </script>
155
 
156
  <?php
php/settings/render-fields.php ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This file handles rendering the settings fields
5
+ *
6
+ * @since 2.0.0
7
+ * @package Code_Snippets
8
+ */
9
+
10
+ /**
11
+ * Render a checkbox field for a setting
12
+ *
13
+ * @since 2.0.0
14
+ * @param array $atts The setting field's attributes
15
+ */
16
+ function code_snippets_checkbox_field( $atts ) {
17
+ $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
18
+ $input_name = sprintf( 'code_snippets_settings[%s][%s]', $atts['section'], $atts['id'] );
19
+
20
+ $output = sprintf(
21
+ '<input type="checkbox" name="%s"%s>',
22
+ $input_name,
23
+ checked( $saved_value, true, false )
24
+ );
25
+
26
+ // Output the checkbox field, optionally with label
27
+ if ( isset( $atts['label'] ) ) {
28
+ printf( '<label for="%s">%s %s</label>', $input_name, $output, $atts['label'] );
29
+ } else {
30
+ echo $output;
31
+ }
32
+
33
+ // Add field description if it is set
34
+ if ( ! empty( $atts['desc'] ) ) {
35
+ echo '<p class="description">' . $atts['desc'] . '</p>';
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Render a number select field for an editor setting
41
+ *
42
+ * @since 2.0.0
43
+ * @param array $atts The setting field's attributes
44
+ */
45
+ function code_snippets_number_field( $atts ) {
46
+
47
+ printf(
48
+ '<input type="number" name="code_snippets_settings[%s][%s]" value="%s"',
49
+ $atts['section'],
50
+ $atts['id'],
51
+ code_snippets_get_setting( $atts['section'], $atts['id'] )
52
+ );
53
+
54
+ if ( isset( $atts['min'] ) ) {
55
+ printf( ' min="%d"', $atts['min'] );
56
+ }
57
+
58
+ if ( isset( $atts['max'] ) ) {
59
+ printf( ' max="%d"', $atts['max'] );
60
+ }
61
+
62
+ echo '>';
63
+
64
+ if ( ! empty( $atts['label'] ) ) {
65
+ echo ' ' . $atts['label'];
66
+ }
67
+
68
+ // Add field description if it is set
69
+ if ( ! empty( $atts['desc'] ) ) {
70
+ echo '<p class="description">' . $atts['desc'] . '</p>';
71
+ }
72
+ }
php/settings/settings-fields.php CHANGED
@@ -1,72 +1,167 @@
1
  <?php
2
 
3
  /**
4
- * This file handles rendering the settings fields
5
- *
6
- * @since 2.0.0
7
- * @package Code_Snippets
8
  */
 
 
9
 
10
- /**
11
- * Render a checkbox field for a setting
12
- *
13
- * @since 2.0.0
14
- * @param array $atts The setting field's attributes
15
- */
16
- function code_snippets_checkbox_field( $atts ) {
17
- $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
18
- $input_name = sprintf( 'code_snippets_settings[%s][%s]', $atts['section'], $atts['id'] );
19
-
20
- $output = sprintf(
21
- '<input type="checkbox" name="%s"%s>',
22
- $input_name,
23
- checked( $saved_value, true, false )
24
- );
25
-
26
- // Output the checkbox field, optionally with label
27
- if ( isset( $atts['label'] ) ) {
28
- printf( '<label for="%s">%s %s</label>', $input_name, $output, $atts['label'] );
29
- } else {
30
- echo $output;
31
  }
32
 
33
- // Add field description if it is set
34
- if ( ! empty( $atts['desc'] ) ) {
35
- echo '<p class="description">' . $atts['desc'] . '</p>';
 
 
 
 
 
36
  }
 
 
37
  }
38
 
39
  /**
40
- * Render a number select field for an editor setting
41
- *
42
- * @since 2.0.0
43
- * @param array $atts The setting field's attributes
44
  */
45
- function code_snippets_number_field( $atts ) {
 
46
 
47
- printf(
48
- '<input type="number" name="code_snippets_settings[%s][%s]" value="%s"',
49
- $atts['section'],
50
- $atts['id'],
51
- code_snippets_get_setting( $atts['section'], $atts['id'] )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  );
53
 
54
- if ( isset( $atts['min'] ) ) {
55
- printf( ' min="%d"', $atts['min'] );
56
- }
57
 
58
- if ( isset( $atts['max'] ) ) {
59
- printf( ' max="%d"', $atts['max'] );
60
- }
 
 
 
 
61
 
62
- echo '>';
 
 
 
 
 
63
 
64
- if ( ! empty( $atts['label'] ) ) {
65
- echo ' ' . $atts['label'];
66
- }
 
 
 
 
67
 
68
- // Add field description if it is set
69
- if ( ! empty( $atts['desc'] ) ) {
70
- echo '<p class="description">' . $atts['desc'] . '</p>';
71
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
1
  <?php
2
 
3
  /**
4
+ * Retrieve the default setting values
5
+ * @return array
 
 
6
  */
7
+ function code_snippets_get_default_settings() {
8
+ static $defaults;
9
 
10
+ if ( isset( $defaults ) ) {
11
+ return $defaults;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  }
13
 
14
+ $defaults = array();
15
+
16
+ foreach ( code_snippets_get_settings_fields() as $section_id => $fields ) {
17
+ $defaults[ $section_id ] = array();
18
+
19
+ foreach ( $fields as $field_id => $field_atts ) {
20
+ $defaults[ $section_id ][ $field_id ] = $field_atts['default'];
21
+ }
22
  }
23
+
24
+ return $defaults;
25
  }
26
 
27
  /**
28
+ * Retrieve the settings fields
29
+ * @return array
 
 
30
  */
31
+ function code_snippets_get_settings_fields() {
32
+ static $fields;
33
 
34
+ if ( isset( $fields ) ) {
35
+ return $fields;
36
+ }
37
+
38
+ $fields = array();
39
+
40
+ $fields['general'] = array(
41
+ 'activate_by_default' => array(
42
+ 'name' => __( 'Activate by Default', 'code-snippets' ),
43
+ 'type' => 'checkbox',
44
+ 'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ),
45
+ 'default' => false,
46
+ ),
47
+
48
+ 'snippet_scope_enabled' => array(
49
+ 'name' => __( 'Enable Scope Selector', 'code-snippets' ),
50
+ 'type' => 'checkbox',
51
+ 'label' => __( 'Enable the scope selector when editing a snippet', 'code-snippets' ),
52
+ 'default' => true,
53
+ ),
54
+
55
+ 'enable_tags' => array(
56
+ 'name' => __( 'Enable Snippet Tags', 'code-snippets' ),
57
+ 'type' => 'checkbox',
58
+ 'label' => __( 'Show snippet tags on admin pages' ),
59
+ 'default' => true,
60
+ ),
61
+
62
+ 'enable_description' => array(
63
+ 'name' => __( 'Enable Snippet Descriptions', 'code-snippets' ),
64
+ 'type' => 'checkbox',
65
+ 'label' => __( 'Show snippet descriptions on admin pages' ),
66
+ 'default' => true,
67
+ ),
68
  );
69
 
70
+ /* Description Editor settings section */
71
+ $fields['description_editor'] = array(
 
72
 
73
+ 'rows' => array(
74
+ 'name' => __( 'Row Height', 'code-snippets' ),
75
+ 'type' => 'number',
76
+ 'label' => __( 'rows', 'code-snippets' ),
77
+ 'default' => 5,
78
+ 'min' => 0,
79
+ ),
80
 
81
+ 'use_full_mce' => array(
82
+ 'name' => __( 'Use Full Editor', 'code-snippets' ),
83
+ 'type' => 'checkbox',
84
+ 'label' => __( 'Enable all features of the visual editor', 'code-snippets' ),
85
+ 'default' => false,
86
+ ),
87
 
88
+ 'media_buttons' => array(
89
+ 'name' => __( 'Media Buttons', 'code-snippets' ),
90
+ 'type' => 'checkbox',
91
+ 'label' => __( 'Enable the add media buttons', 'code-snippets' ),
92
+ 'default' => false,
93
+ ),
94
+ );
95
 
96
+ /* Code Editor settings section */
97
+
98
+ $fields['editor'] = array(
99
+ 'theme' => array(
100
+ 'name' => __( 'Theme', 'code-snippets' ),
101
+ 'type' => 'codemirror_theme_select',
102
+ 'default' => 'default',
103
+ 'codemirror' => 'theme',
104
+ ),
105
+
106
+ 'indent_with_tabs' => array(
107
+ 'name' => __( 'Indent With Tabs', 'code-snippets' ),
108
+ 'type' => 'checkbox',
109
+ 'label' => __( 'Use hard tabs (not spaces) for indentation.', 'code-snippets' ),
110
+ 'default' => true,
111
+ 'codemirror' => 'indentWithTabs',
112
+ ),
113
+
114
+ 'tab_size' => array(
115
+ 'name' => __( 'Tab Size', 'code-snippets' ),
116
+ 'type' => 'number',
117
+ 'desc' => __( 'The width of a tab character.', 'code-snippets' ),
118
+ 'default' => 4,
119
+ 'codemirror' => 'tabSize',
120
+ 'min' => 0,
121
+ ),
122
+
123
+ 'indent_unit' => array(
124
+ 'name' => __( 'Indent Unit', 'code-snippets' ),
125
+ 'type' => 'number',
126
+ 'desc' => __( 'How many spaces a block should be indented.', 'code-snippets' ),
127
+ 'default' => 2,
128
+ 'codemirror' => 'indentUnit',
129
+ 'min' => 0,
130
+ ),
131
+
132
+ 'wrap_lines' => array(
133
+ 'name' => __( 'Wrap Lines', 'code-snippets' ),
134
+ 'type' => 'checkbox',
135
+ 'label' => __( 'Whether the editor should scroll or wrap for long lines.', 'code-snippets' ),
136
+ 'default' => true,
137
+ 'codemirror' => 'lineWrapping',
138
+ ),
139
+
140
+ 'line_numbers' => array(
141
+ 'name' => __( 'Line Numbers', 'code-snippets' ),
142
+ 'type' => 'checkbox',
143
+ 'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
144
+ 'default' => true,
145
+ 'codemirror' => 'lineNumbers',
146
+ ),
147
+
148
+ 'auto_close_brackets' => array(
149
+ 'name' => __( 'Auto Close Brackets', 'code-snippets' ),
150
+ 'type' => 'checkbox',
151
+ 'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
152
+ 'default' => true,
153
+ 'codemirror' => 'autoCloseBrackets',
154
+ ),
155
+
156
+ 'highlight_selection_matches' => array(
157
+ 'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
158
+ 'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
159
+ 'type' => 'checkbox',
160
+ 'default' => true,
161
+ 'codemirror' => 'highlightSelectionMatches',
162
+ ),
163
+ );
164
+
165
+ $fields = apply_filters( 'code_snippets_settings_fields', $fields );
166
+ return $fields;
167
  }
php/settings/settings.php CHANGED
@@ -6,24 +6,6 @@
6
  * @package Code_Snippets
7
  */
8
 
9
- require plugin_dir_path( __FILE__ ) . 'class-settings.php';
10
-
11
- /**
12
- * Retrieve the default setting values
13
- * @return array
14
- */
15
- function code_snippets_get_default_settings() {
16
- return Code_Snippets_Settings::get_defaults();
17
- }
18
-
19
- /**
20
- * Retrieve the settings fields
21
- * @return array
22
- */
23
- function code_snippets_get_settings_fields() {
24
- return Code_Snippets_Settings::get_fields();
25
- }
26
-
27
  /**
28
  * Retrieve the setting values from the database.
29
  * If a setting does not exist in the database, the default value will be returned.
@@ -38,7 +20,7 @@ function code_snippets_get_settings() {
38
  }
39
 
40
  /* Begin with the default settings */
41
- $settings = Code_Snippets_Settings::get_defaults();
42
 
43
  /* Retrieve saved settings from the database */
44
  $saved = get_option( 'code_snippets_settings', array() );
@@ -114,13 +96,14 @@ function code_snippets_register_settings() {
114
  }
115
 
116
  /* Register settings fields */
117
- foreach ( Code_Snippets_Settings::get_fields() as $section_id => $fields ) {
118
- foreach ( $fields as $field ) {
119
  $atts = $field;
 
120
  $atts['section'] = $section_id;
121
 
122
  add_settings_field(
123
- 'code_snippets_' . $field['id'],
124
  $field['name'],
125
  "code_snippets_{$field['type']}_field",
126
  'code-snippets',
@@ -156,8 +139,7 @@ function code_snippets_settings_validate( array $input ) {
156
  foreach ( $settings_fields as $section_id => $fields ) {
157
 
158
  // Loop through fields
159
- foreach ( $fields as $field ) {
160
- $field_id = $field['id'];
161
 
162
  switch ( $field['type'] ) {
163
 
6
  * @package Code_Snippets
7
  */
8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  /**
10
  * Retrieve the setting values from the database.
11
  * If a setting does not exist in the database, the default value will be returned.
20
  }
21
 
22
  /* Begin with the default settings */
23
+ $settings = code_snippets_get_default_settings();
24
 
25
  /* Retrieve saved settings from the database */
26
  $saved = get_option( 'code_snippets_settings', array() );
96
  }
97
 
98
  /* Register settings fields */
99
+ foreach ( code_snippets_get_settings_fields() as $section_id => $fields ) {
100
+ foreach ( $fields as $field_id => $field ) {
101
  $atts = $field;
102
+ $atts['id'] = $field_id;
103
  $atts['section'] = $section_id;
104
 
105
  add_settings_field(
106
+ 'code_snippets_' . $field_id,
107
  $field['name'],
108
  "code_snippets_{$field['type']}_field",
109
  'code-snippets',
139
  foreach ( $settings_fields as $section_id => $fields ) {
140
 
141
  // Loop through fields
142
+ foreach ( $fields as $field_id => $field ) {
 
143
 
144
  switch ( $field['type'] ) {
145
 
php/snippet-ops.php CHANGED
@@ -383,9 +383,7 @@ function execute_snippet( $code, $id = 0 ) {
383
  $result = eval( $code );
384
  ob_end_clean();
385
 
386
- if ( $id ) {
387
- do_action( 'code_snippets/after_execute_snippet', $id, $code );
388
- }
389
 
390
  return $result;
391
  }
@@ -404,6 +402,10 @@ function execute_active_snippets() {
404
  return false;
405
  }
406
 
 
 
 
 
407
  /** @var wpdb $wpdb */
408
  global $wpdb;
409
 
@@ -416,6 +418,7 @@ function execute_active_snippets() {
416
  /* Check if the snippets tables exist */
417
  $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets;
418
  $ms_table_exists = is_multisite() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets;
 
419
 
420
  /* Fetch snippets from site table */
421
  if ( $table_exists ) {
383
  $result = eval( $code );
384
  ob_end_clean();
385
 
386
+ do_action( 'code_snippets/after_execute_snippet', $id, $code, $result );
 
 
387
 
388
  return $result;
389
  }
402
  return false;
403
  }
404
 
405
+ if ( isset( $_GET['code_snippets_safe_mode'] ) && $_GET['code_snippets_safe_mode'] && current_user_can( get_snippets_cap() ) ) {
406
+ return false;
407
+ }
408
+
409
  /** @var wpdb $wpdb */
410
  global $wpdb;
411
 
418
  /* Check if the snippets tables exist */
419
  $table_exists = $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets;
420
  $ms_table_exists = is_multisite() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets;
421
+ $sql = '';
422
 
423
  /* Fetch snippets from site table */
424
  if ( $table_exists ) {
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: bungeshea
3
  Donate link: http://bungeshea.com/donate/
4
  Tags: code-snippets, snippets, code, php, network, multisite
5
  Requires at least: 3.6
6
- Tested up to: 4.3.1
7
- Stable tag: 2.4.1
8
  License: MIT
9
  License URI: license.txt
10
 
@@ -116,6 +116,17 @@ That's fantastic! Fork the [repository on GitHub](http://github.com/sheabunge/co
116
 
117
  == Changelog ==
118
 
 
 
 
 
 
 
 
 
 
 
 
119
  = 2.4.1 =
120
  * Fixed CodeMirror themes not being detected on settings page
121
 
3
  Donate link: http://bungeshea.com/donate/
4
  Tags: code-snippets, snippets, code, php, network, multisite
5
  Requires at least: 3.6
6
+ Tested up to: 4.3.2
7
+ Stable tag: 2.4.2
8
  License: MIT
9
  License URI: license.txt
10
 
116
 
117
  == Changelog ==
118
 
119
+ = 2.4.2 =
120
+ * Added query variable to activate safe mode
121
+ * Fixed settings not saving
122
+ * Fixed snippet descriptions not displaying on manage menu
123
+ * Added settings to disable description and tag editors
124
+ * Fixed: Load CodeMirror after plugin styles to fix error with Zenburn theme
125
+ * Fixed: Hide snippet scope icons when the scope selector is disabled
126
+ * Fixed description heading on edt snippet menu being hidden when visual editor disabled
127
+ * Updated editor preview updating code to use vanilla JavaScript instead of jQuery
128
+ * Fixed: Deactivate a shared network snippet on all subsites when it looses its sharing status
129
+
130
  = 2.4.1 =
131
  * Fixed CodeMirror themes not being detected on settings page
132