Version Description
- Reconfigured plugin to use classloader and converted a lot of functional code into OOP code
- Updated CodeMirror to version 5.10.0
- Added
[code_snippets]
shortcode for embedding snippet code in a post - Fixed broken snippet search feature [#]
- Added front-end syntax highlighting for shortcode using PrismJS
Download this release
Release Info
Developer | bungeshea |
Plugin | Code Snippets |
Version | 2.6.0 |
Comparing to | |
See all releases |
Code changes from version 2.4.2 to 2.6.0
- code-snippets.php +37 -46
- css/min/cmthemes/abcdef.css +1 -1
- css/min/cmthemes/bespin.css +1 -0
- css/min/cmthemes/hopscotch.css +1 -0
- css/min/cmthemes/icecoder.css +1 -1
- css/min/cmthemes/isotope.css +1 -0
- css/min/cmthemes/liquibyte.css +1 -1
- css/min/cmthemes/material.css +1 -1
- css/min/cmthemes/railscasts.css +1 -0
- languages/code-snippets.pot +55 -18
- php/admin-menus/class-admin-menu.php +17 -9
- php/admin-menus/class-edit-menu.php +235 -101
- php/admin-menus/class-import-menu.php +4 -1
- php/admin-menus/class-manage-menu.php +4 -4
- php/admin.php +0 -203
- php/caps.php +0 -60
- php/class-admin.php +196 -0
- php/class-code-snippets.php +208 -0
- php/class-contextual-help.php +140 -0
- php/class-db.php +135 -0
- php/class-list-table.php +10 -16
- php/class-shortcode.php +72 -0
- php/contextual-help.php +0 -124
- php/db.php +0 -122
- php/editor.php +1 -1
- php/functions.php +46 -43
- php/settings/editor-preview.php +1 -1
- php/settings/settings-fields.php +6 -0
- php/snippet-ops.php +0 -4
- php/upgrade.php +1 -1
- php/views/edit.php +3 -3
- readme.txt +25 -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.
|
11 |
* @author Shea Bunge <http://bungeshea.com/>
|
12 |
* @copyright Copyright (c) 2012-2015, Shea Bunge
|
13 |
* @link https://github.com/sheabunge/code-snippets
|
@@ -19,8 +19,8 @@ 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:
|
23 |
-
Version: 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.
|
46 |
|
47 |
/**
|
48 |
* The full path to the main file of this plugin
|
@@ -57,61 +57,52 @@ define( 'CODE_SNIPPETS_VERSION', '2.4.2' );
|
|
57 |
define( 'CODE_SNIPPETS_FILE', __FILE__ );
|
58 |
|
59 |
/**
|
60 |
-
*
|
|
|
61 |
*/
|
62 |
-
|
63 |
|
64 |
-
/*
|
65 |
-
'
|
|
|
|
|
66 |
|
67 |
-
/*
|
68 |
-
'
|
69 |
|
70 |
-
/*
|
71 |
-
|
|
|
72 |
|
73 |
-
|
74 |
-
'snippet-ops.php',
|
75 |
|
76 |
-
|
77 |
-
|
|
|
78 |
|
79 |
-
/*
|
80 |
-
|
81 |
-
|
82 |
-
/* General functions */
|
83 |
-
'functions.php',
|
84 |
|
85 |
-
|
86 |
-
'contextual-help.php',
|
87 |
-
'admin.php',
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
94 |
|
95 |
-
|
|
|
|
|
96 |
|
97 |
-
|
98 |
}
|
99 |
|
100 |
-
|
101 |
-
set_snippet_table_vars();
|
102 |
|
103 |
/* Execute the snippets once the plugins are loaded */
|
104 |
add_action( 'plugins_loaded', 'execute_active_snippets', 1 );
|
105 |
-
|
106 |
-
/**
|
107 |
-
* Load up the localization file if we're using WordPress in a different language.
|
108 |
-
* Place it in this plugin's "languages" folder and name it "code-snippets-[language_COUNTRY].mo"
|
109 |
-
*
|
110 |
-
* If you wish to contribute a language file to be included in the Code Snippets package,
|
111 |
-
* please see create an issue on GitHub: https://github.com/sheabunge/code-snippets/issues
|
112 |
-
*/
|
113 |
-
function code_snippets_load_textdomain() {
|
114 |
-
load_plugin_textdomain( 'code-snippets', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
|
115 |
-
}
|
116 |
-
|
117 |
-
add_action( 'plugins_loaded', 'code_snippets_load_textdomain' );
|
7 |
* contribute to the localization, please see https://github.com/sheabunge/code-snippets
|
8 |
*
|
9 |
* @package Code_Snippets
|
10 |
+
* @version 2.5.1
|
11 |
* @author Shea Bunge <http://bungeshea.com/>
|
12 |
* @copyright Copyright (c) 2012-2015, Shea Bunge
|
13 |
* @link https://github.com/sheabunge/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: https://bungeshea.com
|
23 |
+
Version: 2.6.0
|
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.5.1' );
|
46 |
|
47 |
/**
|
48 |
* The full path to the main file of this plugin
|
57 |
define( 'CODE_SNIPPETS_FILE', __FILE__ );
|
58 |
|
59 |
/**
|
60 |
+
* Enable autoloading of plugin classes
|
61 |
+
* @param $class_name
|
62 |
*/
|
63 |
+
function code_snippets_autoload( $class_name ) {
|
64 |
|
65 |
+
/* Only autoload classes from this plugin */
|
66 |
+
if ( 'Snippet' !== $class_name && 'Code_Snippets' !== substr( $class_name, 0, 13 ) ) {
|
67 |
+
return;
|
68 |
+
}
|
69 |
|
70 |
+
/* Remove namespace from class name */
|
71 |
+
$class_file = str_replace( 'Code_Snippets_', '', $class_name );
|
72 |
|
73 |
+
/* Convert class name format to file name format */
|
74 |
+
$class_file = strtolower( $class_file );
|
75 |
+
$class_file = str_replace( '_', '-', $class_file );
|
76 |
|
77 |
+
$class_path = dirname( __FILE__ ) . '/php/';
|
|
|
78 |
|
79 |
+
if ( 'Menu' === substr( $class_name, -4, 4 ) ) {
|
80 |
+
$class_path .= 'admin-menus/';
|
81 |
+
}
|
82 |
|
83 |
+
/* Load the class */
|
84 |
+
require_once $class_path . "class-{$class_file}.php";
|
85 |
+
}
|
|
|
|
|
86 |
|
87 |
+
spl_autoload_register( 'code_snippets_autoload' );
|
|
|
|
|
88 |
|
89 |
+
/**
|
90 |
+
* Retrieve the instance of the main plugin class
|
91 |
+
*
|
92 |
+
* @since [NEXT_VERSION]
|
93 |
+
* @return Code_Snippets
|
94 |
+
*/
|
95 |
+
function code_snippets() {
|
96 |
+
static $plugin;
|
97 |
|
98 |
+
if ( is_null( $plugin ) ) {
|
99 |
+
$plugin = new Code_Snippets( CODE_SNIPPETS_VERSION, __FILE__ );
|
100 |
+
}
|
101 |
|
102 |
+
return $plugin;
|
103 |
}
|
104 |
|
105 |
+
code_snippets()->load_plugin();
|
|
|
106 |
|
107 |
/* Execute the snippets once the plugins are loaded */
|
108 |
add_action( 'plugins_loaded', 'execute_active_snippets', 1 );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css/min/cmthemes/abcdef.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.cm-s-abcdef.CodeMirror{background:#0f0f0f;color:#defdef}.cm-s-abcdef div.CodeMirror-selected{background:#515151}.cm-s-abcdef .CodeMirror-line::selection,.cm-s-abcdef .CodeMirror-line>span::selection,.cm-s-abcdef .CodeMirror-line>span>span::selection{background:rgba(56,56,56,.99)}.cm-s-abcdef .CodeMirror-line::-moz-selection,.cm-s-abcdef .CodeMirror-line>span::-moz-selection,.cm-s-abcdef .CodeMirror-line>span>span::-moz-selection{background:rgba(56,56,56,.99)}.cm-s-abcdef .CodeMirror-gutters{background:#555;border-right:2px solid #314151}.cm-s-abcdef .CodeMirror-guttermarker{color:#222}.cm-s-abcdef .CodeMirror-guttermarker-subtle{color:azure}.cm-s-abcdef .CodeMirror-linenumber{color:#fff}.cm-s-abcdef .CodeMirror-cursor{border-left:1px solid #0f0}.cm-s-abcdef span.cm-keyword{color:darkgoldenrod;font-weight:700}.cm-s-abcdef span.cm-atom{color:#77F}.cm-s-abcdef span.cm-number{color:violet}.cm-s-abcdef span.cm-def{color:#fffabc}.cm-s-abcdef span.cm-variable{color:#abcdef}.cm-s-abcdef span.cm-variable-2{color:#cacbcc}.cm-s-abcdef span.cm-variable-3{color:#def}.cm-s-abcdef span.cm-property{color:#fedcba}.cm-s-abcdef span.cm-operator{color:#ff0}.cm-s-abcdef span.cm-comment{color:#7a7b7c;font-style:italic}.cm-s-abcdef span.cm-string{color:#2b4}.cm-s-abcdef span.cm-meta{color:#C9F}.cm-s-abcdef span.cm-qualifier{color:#FFF700}.cm-s-abcdef span.cm-builtin{color:#30aabc}.cm-s-abcdef span.cm-bracket{color:#8a8a8a}.cm-s-abcdef span.cm-tag{color:#fd4}.cm-s-abcdef span.cm-attribute{color:#df0}.cm-s-abcdef span.cm-error{color:red}.cm-s-abcdef span.cm-header{color:aquamarine;font-weight:700}.cm-s-abcdef span.cm-link{color
|
1 |
+
.cm-s-abcdef.CodeMirror{background:#0f0f0f;color:#defdef}.cm-s-abcdef div.CodeMirror-selected{background:#515151}.cm-s-abcdef .CodeMirror-line::selection,.cm-s-abcdef .CodeMirror-line>span::selection,.cm-s-abcdef .CodeMirror-line>span>span::selection{background:rgba(56,56,56,.99)}.cm-s-abcdef .CodeMirror-line::-moz-selection,.cm-s-abcdef .CodeMirror-line>span::-moz-selection,.cm-s-abcdef .CodeMirror-line>span>span::-moz-selection{background:rgba(56,56,56,.99)}.cm-s-abcdef .CodeMirror-gutters{background:#555;border-right:2px solid #314151}.cm-s-abcdef .CodeMirror-guttermarker{color:#222}.cm-s-abcdef .CodeMirror-guttermarker-subtle{color:azure}.cm-s-abcdef .CodeMirror-linenumber{color:#fff}.cm-s-abcdef .CodeMirror-cursor{border-left:1px solid #0f0}.cm-s-abcdef span.cm-keyword{color:darkgoldenrod;font-weight:700}.cm-s-abcdef span.cm-atom{color:#77F}.cm-s-abcdef span.cm-number{color:violet}.cm-s-abcdef span.cm-def{color:#fffabc}.cm-s-abcdef span.cm-variable{color:#abcdef}.cm-s-abcdef span.cm-variable-2{color:#cacbcc}.cm-s-abcdef span.cm-variable-3{color:#def}.cm-s-abcdef span.cm-property{color:#fedcba}.cm-s-abcdef span.cm-operator{color:#ff0}.cm-s-abcdef span.cm-comment{color:#7a7b7c;font-style:italic}.cm-s-abcdef span.cm-string{color:#2b4}.cm-s-abcdef span.cm-meta{color:#C9F}.cm-s-abcdef span.cm-qualifier{color:#FFF700}.cm-s-abcdef span.cm-builtin{color:#30aabc}.cm-s-abcdef span.cm-bracket{color:#8a8a8a}.cm-s-abcdef span.cm-tag{color:#fd4}.cm-s-abcdef span.cm-attribute{color:#df0}.cm-s-abcdef span.cm-error{color:red}.cm-s-abcdef span.cm-header{color:aquamarine;font-weight:700}.cm-s-abcdef span.cm-link{color:blueviolet}.cm-s-abcdef .CodeMirror-activeline-background{background:#314151}
|
css/min/cmthemes/bespin.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.cm-s-bespin.CodeMirror{background:#28211c;color:#9d9b97}.cm-s-bespin div.CodeMirror-selected{background:#36312e!important}.cm-s-bespin .CodeMirror-gutters{background:#28211c;border-right:0}.cm-s-bespin .CodeMirror-linenumber{color:#666}.cm-s-bespin .CodeMirror-cursor{border-left:1px solid #797977!important}.cm-s-bespin span.cm-comment{color:#937121}.cm-s-bespin span.cm-atom,.cm-s-bespin span.cm-number{color:#9b859d}.cm-s-bespin span.cm-property,.cm-s-bespin span.cm-attribute{color:#54be0d}.cm-s-bespin span.cm-keyword{color:#cf6a4c}.cm-s-bespin span.cm-string{color:#f9ee98}.cm-s-bespin span.cm-variable{color:#54be0d}.cm-s-bespin span.cm-variable-2{color:#5ea6ea}.cm-s-bespin span.cm-def{color:#cf7d34}.cm-s-bespin span.cm-error{background:#cf6a4c;color:#797977}.cm-s-bespin span.cm-bracket{color:#9d9b97}.cm-s-bespin span.cm-tag{color:#cf6a4c}.cm-s-bespin span.cm-link{color:#9b859d}.cm-s-bespin .CodeMirror-matchingbracket{text-decoration:underline;color:#fff!important}.cm-s-bespin .CodeMirror-activeline-background{background:#404040}
|
css/min/cmthemes/hopscotch.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.cm-s-hopscotch.CodeMirror{background:#322931;color:#d5d3d5}.cm-s-hopscotch div.CodeMirror-selected{background:#433b42!important}.cm-s-hopscotch .CodeMirror-gutters{background:#322931;border-right:0}.cm-s-hopscotch .CodeMirror-linenumber{color:#797379}.cm-s-hopscotch .CodeMirror-cursor{border-left:1px solid #989498!important}.cm-s-hopscotch span.cm-comment{color:#b33508}.cm-s-hopscotch span.cm-atom,.cm-s-hopscotch span.cm-number{color:#c85e7c}.cm-s-hopscotch span.cm-property,.cm-s-hopscotch span.cm-attribute{color:#8fc13e}.cm-s-hopscotch span.cm-keyword{color:#dd464c}.cm-s-hopscotch span.cm-string{color:#fdcc59}.cm-s-hopscotch span.cm-variable{color:#8fc13e}.cm-s-hopscotch span.cm-variable-2{color:#1290bf}.cm-s-hopscotch span.cm-def{color:#fd8b19}.cm-s-hopscotch span.cm-error{background:#dd464c;color:#989498}.cm-s-hopscotch span.cm-bracket{color:#d5d3d5}.cm-s-hopscotch span.cm-tag{color:#dd464c}.cm-s-hopscotch span.cm-link{color:#c85e7c}.cm-s-hopscotch .CodeMirror-matchingbracket{text-decoration:underline;color:#fff!important}.cm-s-hopscotch .CodeMirror-activeline-background{background:#302020}
|
css/min/cmthemes/icecoder.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.cm-s-icecoder{color:#666;background:#141612}.cm-s-icecoder span.cm-keyword{color:#eee;font-weight:700}.cm-s-icecoder span.cm-atom{color:#e1c76e}.cm-s-icecoder span.cm-number{color:#6cb5d9}.cm-s-icecoder span.cm-def{color:#b9ca4a}.cm-s-icecoder span.cm-variable{color:#6cb5d9}.cm-s-icecoder span.cm-variable-2{color:#cc1e5c}.cm-s-icecoder span.cm-variable-3{color:#f9602c}.cm-s-icecoder span.cm-property{color:#eee}.cm-s-icecoder span.cm-operator{color:#9179bb}.cm-s-icecoder span.cm-comment{color:#97a3aa}.cm-s-icecoder span.cm-string{color:#b9ca4a}.cm-s-icecoder span.cm-string-2{color:#6cb5d9}.cm-s-icecoder span.cm-meta,.cm-s-icecoder span.cm-qualifier{color:#555}.cm-s-icecoder span.cm-builtin{color:#214e7b}.cm-s-icecoder span.cm-bracket{color:#cc7}.cm-s-icecoder span.cm-tag{color:#e8e8e8}.cm-s-icecoder span.cm-attribute{color:#099}.cm-s-icecoder span.cm-header{color:#6a0d6a}.cm-s-icecoder span.cm-quote{color:#186718}.cm-s-icecoder span.cm-hr{color:#888}.cm-s-icecoder span.cm-link{color:#e1c76e}.cm-s-icecoder span.cm-error{color:#d00}.cm-s-icecoder .CodeMirror-cursor{border-left:1px solid #fff}.cm-s-icecoder div.CodeMirror-selected{color:#fff;background:#037}.cm-s-icecoder .CodeMirror-gutters{background:#141612;min-width:41px;border-right:0}.cm-s-icecoder .CodeMirror-linenumber{color:#555;cursor:default}.cm-s-icecoder .CodeMirror-matchingbracket{border:1px solid grey;color:#000!important}
|
1 |
+
.cm-s-icecoder{color:#666;background:#141612}.cm-s-icecoder span.cm-keyword{color:#eee;font-weight:700}.cm-s-icecoder span.cm-atom{color:#e1c76e}.cm-s-icecoder span.cm-number{color:#6cb5d9}.cm-s-icecoder span.cm-def{color:#b9ca4a}.cm-s-icecoder span.cm-variable{color:#6cb5d9}.cm-s-icecoder span.cm-variable-2{color:#cc1e5c}.cm-s-icecoder span.cm-variable-3{color:#f9602c}.cm-s-icecoder span.cm-property{color:#eee}.cm-s-icecoder span.cm-operator{color:#9179bb}.cm-s-icecoder span.cm-comment{color:#97a3aa}.cm-s-icecoder span.cm-string{color:#b9ca4a}.cm-s-icecoder span.cm-string-2{color:#6cb5d9}.cm-s-icecoder span.cm-meta,.cm-s-icecoder span.cm-qualifier{color:#555}.cm-s-icecoder span.cm-builtin{color:#214e7b}.cm-s-icecoder span.cm-bracket{color:#cc7}.cm-s-icecoder span.cm-tag{color:#e8e8e8}.cm-s-icecoder span.cm-attribute{color:#099}.cm-s-icecoder span.cm-header{color:#6a0d6a}.cm-s-icecoder span.cm-quote{color:#186718}.cm-s-icecoder span.cm-hr{color:#888}.cm-s-icecoder span.cm-link{color:#e1c76e}.cm-s-icecoder span.cm-error{color:#d00}.cm-s-icecoder .CodeMirror-cursor{border-left:1px solid #fff}.cm-s-icecoder div.CodeMirror-selected{color:#fff;background:#037}.cm-s-icecoder .CodeMirror-gutters{background:#141612;min-width:41px;border-right:0}.cm-s-icecoder .CodeMirror-linenumber{color:#555;cursor:default}.cm-s-icecoder .CodeMirror-matchingbracket{border:1px solid grey;color:#000!important}.cm-s-icecoder .CodeMirror-activeline-background{background:#000}
|
css/min/cmthemes/isotope.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.cm-s-isotope.CodeMirror{background:#000;color:#e0e0e0}.cm-s-isotope div.CodeMirror-selected{background:#404040!important}.cm-s-isotope .CodeMirror-gutters{background:#000;border-right:0}.cm-s-isotope .CodeMirror-linenumber{color:gray}.cm-s-isotope .CodeMirror-cursor{border-left:1px solid silver!important}.cm-s-isotope span.cm-comment{color:#30f}.cm-s-isotope span.cm-atom,.cm-s-isotope span.cm-number{color:#c0f}.cm-s-isotope span.cm-property,.cm-s-isotope span.cm-attribute{color:#3f0}.cm-s-isotope span.cm-keyword{color:red}.cm-s-isotope span.cm-string{color:#f09}.cm-s-isotope span.cm-variable{color:#3f0}.cm-s-isotope span.cm-variable-2{color:#06f}.cm-s-isotope span.cm-def{color:#f90}.cm-s-isotope span.cm-error{background:red;color:silver}.cm-s-isotope span.cm-bracket{color:#e0e0e0}.cm-s-isotope span.cm-tag{color:red}.cm-s-isotope span.cm-link{color:#c0f}.cm-s-isotope .CodeMirror-matchingbracket{text-decoration:underline;color:#fff!important}.cm-s-isotope .CodeMirror-activeline-background{background:#202020}
|
css/min/cmthemes/liquibyte.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.cm-s-liquibyte.CodeMirror{background-color:#000;color:#fff;line-height:1.2em;font-size:1em}.CodeMirror-focused .cm-matchhighlight{text-decoration:underline;text-decoration-color:#0f0;text-decoration-style:wavy}.cm-
|
1 |
+
.cm-s-liquibyte.CodeMirror{background-color:#000;color:#fff;line-height:1.2em;font-size:1em}.cm-s-liquibyte .CodeMirror-focused .cm-matchhighlight{text-decoration:underline;text-decoration-color:#0f0;text-decoration-style:wavy}.cm-s-liquibyte .cm-trailingspace{text-decoration:line-through;text-decoration-color:red;text-decoration-style:dotted}.cm-s-liquibyte .cm-tab{text-decoration:line-through;text-decoration-color:#404040;text-decoration-style:dotted}.cm-s-liquibyte .CodeMirror-gutters{background-color:#262626;border-right:1px solid #505050;padding-right:.8em}.cm-s-liquibyte .CodeMirror-gutter-elt div{font-size:1.2em}.cm-s-liquibyte .CodeMirror-linenumber{color:#606060;padding-left:0}.cm-s-liquibyte .CodeMirror-cursor{border-left:1px solid #eee}.cm-s-liquibyte span.cm-comment{color:green}.cm-s-liquibyte span.cm-def{color:#ffaf40;font-weight:700}.cm-s-liquibyte span.cm-keyword{color:#c080ff;font-weight:700}.cm-s-liquibyte span.cm-builtin{color:#ffaf40;font-weight:700}.cm-s-liquibyte span.cm-variable{color:#5967ff;font-weight:700}.cm-s-liquibyte span.cm-string{color:#ff8000}.cm-s-liquibyte span.cm-number{color:#0f0;font-weight:700}.cm-s-liquibyte span.cm-atom{color:#bf3030;font-weight:700}.cm-s-liquibyte span.cm-variable-2{color:#007f7f;font-weight:700}.cm-s-liquibyte span.cm-variable-3{color:#c080ff;font-weight:700}.cm-s-liquibyte span.cm-property{color:#999;font-weight:700}.cm-s-liquibyte span.cm-operator{color:#fff}.cm-s-liquibyte span.cm-meta{color:#0f0}.cm-s-liquibyte span.cm-qualifier{color:#fff700;font-weight:700}.cm-s-liquibyte span.cm-bracket{color:#cc7}.cm-s-liquibyte span.cm-tag{color:#ff0;font-weight:700}.cm-s-liquibyte span.cm-attribute{color:#c080ff;font-weight:700}.cm-s-liquibyte span.cm-error{color:red}.cm-s-liquibyte div.CodeMirror-selected{background-color:rgba(255,0,0,.25)}.cm-s-liquibyte span.cm-compilation{background-color:rgba(255,255,255,.12)}.cm-s-liquibyte .CodeMirror-activeline-background{background-color:rgba(0,255,0,.15)}.cm-s-liquibyte .CodeMirror span.CodeMirror-matchingbracket{color:#0f0;font-weight:700}.cm-s-liquibyte .CodeMirror span.CodeMirror-nonmatchingbracket{color:red;font-weight:700}.CodeMirror-matchingtag{background-color:rgba(150,255,0,.3)}.cm-s-liquibyte div.CodeMirror-simplescroll-horizontal div:hover,div.CodeMirror-simplescroll-vertical div:hover{background-color:rgba(80,80,80,.7)}.cm-s-liquibyte div.CodeMirror-simplescroll-horizontal div,div.CodeMirror-simplescroll-vertical div{background-color:rgba(80,80,80,.3);border:1px solid #404040;border-radius:5px}.cm-s-liquibyte div.CodeMirror-simplescroll-vertical div{border-top:1px solid #404040;border-bottom:1px solid #404040}.cm-s-liquibyte div.CodeMirror-simplescroll-horizontal div{border-left:1px solid #404040;border-right:1px solid #404040}.cm-s-liquibyte div.CodeMirror-simplescroll-vertical{background-color:#262626}.cm-s-liquibyte div.CodeMirror-simplescroll-horizontal{background-color:#262626;border-top:1px solid #404040}.cm-s-liquibyte div.CodeMirror-overlayscroll-horizontal div,div.CodeMirror-overlayscroll-vertical div{background-color:#404040;border-radius:5px}.cm-s-liquibyte div.CodeMirror-overlayscroll-vertical div,.cm-s-liquibyte div.CodeMirror-overlayscroll-horizontal div{border:1px solid #404040}
|
css/min/cmthemes/material.css
CHANGED
@@ -1 +1 @@
|
|
1 |
-
.cm-s-material{background-color:#263238;color:rgba(233,237,237,1)}.cm-s-material .CodeMirror-gutters{background:#263238;color:#537f7e;border:none}.cm-s-material .CodeMirror-guttermarker,.cm-s-material .CodeMirror-guttermarker-subtle,.cm-s-material .CodeMirror-linenumber{color:#537f7e}.cm-s-material .CodeMirror-cursor{border-left:1px solid #f8f8f0}.cm-s-material div.CodeMirror-selected{background:rgba(255,255,255,.15)}.cm-s-material.CodeMirror-focused div.CodeMirror-selected{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-line::selection,.cm-s-material .CodeMirror-line>span::selection,.cm-s-material .CodeMirror-line>span>span::selection{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-line::-moz-selection,.cm-s-material .CodeMirror-line>span::-moz-selection,.cm-s-material .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-activeline-background{background:rgba(0,0,0,0)}.cm-s-material .cm-keyword{color:rgba(199,146,234,1)}.cm-s-material .cm-operator{color:rgba(233,237,237,1)}.cm-s-material .cm-variable-2{color:#80CBC4}.cm-s-material .cm-builtin{color:#DECB6B}.cm-s-material .cm-atom,.cm-s-material .cm-number{color:#F77669}.cm-s-material .cm-def{color:rgba(233,237,237,1)}.cm-s-material .cm-
|
1 |
+
.cm-s-material{background-color:#263238;color:rgba(233,237,237,1)}.cm-s-material .CodeMirror-gutters{background:#263238;color:#537f7e;border:none}.cm-s-material .CodeMirror-guttermarker,.cm-s-material .CodeMirror-guttermarker-subtle,.cm-s-material .CodeMirror-linenumber{color:#537f7e}.cm-s-material .CodeMirror-cursor{border-left:1px solid #f8f8f0}.cm-s-material div.CodeMirror-selected{background:rgba(255,255,255,.15)}.cm-s-material.CodeMirror-focused div.CodeMirror-selected{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-line::selection,.cm-s-material .CodeMirror-line>span::selection,.cm-s-material .CodeMirror-line>span>span::selection{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-line::-moz-selection,.cm-s-material .CodeMirror-line>span::-moz-selection,.cm-s-material .CodeMirror-line>span>span::-moz-selection{background:rgba(255,255,255,.1)}.cm-s-material .CodeMirror-activeline-background{background:rgba(0,0,0,0)}.cm-s-material .cm-keyword{color:rgba(199,146,234,1)}.cm-s-material .cm-operator{color:rgba(233,237,237,1)}.cm-s-material .cm-variable-2{color:#80CBC4}.cm-s-material .cm-builtin{color:#DECB6B}.cm-s-material .cm-atom,.cm-s-material .cm-number{color:#F77669}.cm-s-material .cm-def{color:rgba(233,237,237,1)}.cm-s-material .cm-string{color:#C3E88D}.cm-s-material .cm-string-2{color:#80CBC4}.cm-s-material .cm-comment{color:#546E7A}.cm-s-material .cm-variable{color:#82B1FF}.cm-s-material .cm-tag,.cm-s-material .cm-meta{color:#80CBC4}.cm-s-material .cm-attribute{color:#FFCB6B}.cm-s-material .cm-property{color:#80CBAE}.cm-s-material .cm-qualifier,.cm-s-material .cm-variable-3{color:#DECB6B}.cm-s-material .cm-tag{color:rgba(255,83,112,1)}.cm-s-material .cm-error{color:rgba(255,255,255,1);background-color:#EC5F67}.cm-s-material .CodeMirror-matchingbracket{text-decoration:underline;color:#fff!important}
|
css/min/cmthemes/railscasts.css
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
.cm-s-railscasts.CodeMirror{background:#2b2b2b;color:#f4f1ed}.cm-s-railscasts div.CodeMirror-selected{background:#272935!important}.cm-s-railscasts .CodeMirror-gutters{background:#2b2b2b;border-right:0}.cm-s-railscasts .CodeMirror-linenumber{color:#5a647e}.cm-s-railscasts .CodeMirror-cursor{border-left:1px solid #d4cfc9!important}.cm-s-railscasts span.cm-comment{color:#bc9458}.cm-s-railscasts span.cm-atom,.cm-s-railscasts span.cm-number{color:#b6b3eb}.cm-s-railscasts span.cm-property,.cm-s-railscasts span.cm-attribute{color:#a5c261}.cm-s-railscasts span.cm-keyword{color:#da4939}.cm-s-railscasts span.cm-string{color:#ffc66d}.cm-s-railscasts span.cm-variable{color:#a5c261}.cm-s-railscasts span.cm-variable-2{color:#6d9cbe}.cm-s-railscasts span.cm-def{color:#cc7833}.cm-s-railscasts span.cm-error{background:#da4939;color:#d4cfc9}.cm-s-railscasts span.cm-bracket{color:#f4f1ed}.cm-s-railscasts span.cm-tag{color:#da4939}.cm-s-railscasts span.cm-link{color:#b6b3eb}.cm-s-railscasts .CodeMirror-matchingbracket{text-decoration:underline;color:#fff!important}.cm-s-railscasts .CodeMirror-activeline-background{background:#303040}
|
languages/code-snippets.pot
CHANGED
@@ -6,9 +6,9 @@
|
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
-
"Project-Id-Version: code-snippets 2.
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
-
"POT-Creation-Date: 2015-
|
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"
|
@@ -18,7 +18,7 @@ msgstr ""
|
|
18 |
"Content-Transfer-Encoding: 8bit\n"
|
19 |
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
20 |
|
21 |
-
#: php/admin-menus/class-admin-menu.php:
|
22 |
msgid "You are not authorized to access this page."
|
23 |
msgstr ""
|
24 |
|
@@ -35,63 +35,100 @@ msgstr ""
|
|
35 |
msgid "Add New Snippet"
|
36 |
msgstr ""
|
37 |
|
38 |
-
#: php/admin-menus/class-edit-menu.php:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
msgid "Description"
|
40 |
msgstr ""
|
41 |
|
42 |
-
#: php/admin-menus/class-edit-menu.php:
|
43 |
msgid "Tags"
|
44 |
msgstr ""
|
45 |
|
46 |
-
#: php/admin-menus/class-edit-menu.php:
|
47 |
msgid "Enter a list of tags; separated by commas"
|
48 |
msgstr ""
|
49 |
|
50 |
-
#: php/admin-menus/class-edit-menu.php:
|
51 |
msgid "Run snippet everywhere"
|
52 |
msgstr ""
|
53 |
|
54 |
-
#: php/admin-menus/class-edit-menu.php:
|
55 |
msgid "Only run in administration area"
|
56 |
msgstr ""
|
57 |
|
58 |
-
#: php/admin-menus/class-edit-menu.php:
|
59 |
msgid "Only run on site front-end"
|
60 |
msgstr ""
|
61 |
|
62 |
-
#: php/admin-menus/class-edit-menu.php:
|
63 |
msgid "Scope"
|
64 |
msgstr ""
|
65 |
|
66 |
-
#: php/admin-menus/class-edit-menu.php:
|
67 |
msgid "Sharing"
|
68 |
msgstr ""
|
69 |
|
70 |
-
#: php/admin-menus/class-edit-menu.php:
|
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:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
msgid "An error occurred when saving the snippet."
|
76 |
msgstr ""
|
77 |
|
78 |
-
#: php/admin-menus/class-edit-menu.php:
|
79 |
msgid "Snippet <strong>added</strong>."
|
80 |
msgstr ""
|
81 |
|
82 |
-
#: php/admin-menus/class-edit-menu.php:
|
83 |
msgid "Snippet <strong>updated</strong>."
|
84 |
msgstr ""
|
85 |
|
86 |
-
#: php/admin-menus/class-edit-menu.php:
|
87 |
msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
|
88 |
msgstr ""
|
89 |
|
90 |
-
#: php/admin-menus/class-edit-menu.php:
|
91 |
msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
|
92 |
msgstr ""
|
93 |
|
94 |
-
#: php/admin-menus/class-edit-menu.php:
|
95 |
msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
|
96 |
msgstr ""
|
97 |
|
6 |
#, fuzzy
|
7 |
msgid ""
|
8 |
msgstr ""
|
9 |
+
"Project-Id-Version: code-snippets 2.5.1\n"
|
10 |
"Report-Msgid-Bugs-To: \n"
|
11 |
+
"POT-Creation-Date: 2015-10-11 20:33+1100\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"
|
18 |
"Content-Transfer-Encoding: 8bit\n"
|
19 |
"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
|
20 |
|
21 |
+
#: php/admin-menus/class-admin-menu.php:95
|
22 |
msgid "You are not authorized to access this page."
|
23 |
msgstr ""
|
24 |
|
35 |
msgid "Add New Snippet"
|
36 |
msgstr ""
|
37 |
|
38 |
+
#: php/admin-menus/class-edit-menu.php:149
|
39 |
+
msgid "Don't Panic"
|
40 |
+
msgstr ""
|
41 |
+
|
42 |
+
#: php/admin-menus/class-edit-menu.php:150
|
43 |
+
#, php-format
|
44 |
+
msgid ""
|
45 |
+
"The code snippet you are trying to save produced a fatal error on line %d:"
|
46 |
+
msgstr ""
|
47 |
+
|
48 |
+
#: php/admin-menus/class-edit-menu.php:152
|
49 |
+
msgid ""
|
50 |
+
"The previous version of the snippet is unchanged, and the rest of this site "
|
51 |
+
"should be functioning normally as before."
|
52 |
+
msgstr ""
|
53 |
+
|
54 |
+
#: php/admin-menus/class-edit-menu.php:153
|
55 |
+
msgid ""
|
56 |
+
"Please use the back button in your browser to return to the previous page "
|
57 |
+
"and try to fix the code error."
|
58 |
+
msgstr ""
|
59 |
+
|
60 |
+
#: php/admin-menus/class-edit-menu.php:154
|
61 |
+
msgid ""
|
62 |
+
"If you prefer, you can close this page and discard the changes you just "
|
63 |
+
"made. No changes will be made to this site."
|
64 |
+
msgstr ""
|
65 |
+
|
66 |
+
#: php/admin-menus/class-edit-menu.php:279 php/class-list-table.php:324
|
67 |
msgid "Description"
|
68 |
msgstr ""
|
69 |
|
70 |
+
#: php/admin-menus/class-edit-menu.php:309 php/class-list-table.php:325
|
71 |
msgid "Tags"
|
72 |
msgstr ""
|
73 |
|
74 |
+
#: php/admin-menus/class-edit-menu.php:313
|
75 |
msgid "Enter a list of tags; separated by commas"
|
76 |
msgstr ""
|
77 |
|
78 |
+
#: php/admin-menus/class-edit-menu.php:332
|
79 |
msgid "Run snippet everywhere"
|
80 |
msgstr ""
|
81 |
|
82 |
+
#: php/admin-menus/class-edit-menu.php:333
|
83 |
msgid "Only run in administration area"
|
84 |
msgstr ""
|
85 |
|
86 |
+
#: php/admin-menus/class-edit-menu.php:334
|
87 |
msgid "Only run on site front-end"
|
88 |
msgstr ""
|
89 |
|
90 |
+
#: php/admin-menus/class-edit-menu.php:338
|
91 |
msgid "Scope"
|
92 |
msgstr ""
|
93 |
|
94 |
+
#: php/admin-menus/class-edit-menu.php:358
|
95 |
msgid "Sharing"
|
96 |
msgstr ""
|
97 |
|
98 |
+
#: php/admin-menus/class-edit-menu.php:362
|
99 |
msgid "Allow this snippet to be activated on individual sites on the network"
|
100 |
msgstr ""
|
101 |
|
102 |
+
#: php/admin-menus/class-edit-menu.php:415
|
103 |
+
#, php-format
|
104 |
+
msgid "The snippet has been deactivated due to an error on line %d:"
|
105 |
+
msgstr ""
|
106 |
+
|
107 |
+
#: php/admin-menus/class-edit-menu.php:420
|
108 |
+
msgid "The snippet has been deactivated due to an error in the code."
|
109 |
+
msgstr ""
|
110 |
+
|
111 |
+
#: php/admin-menus/class-edit-menu.php:427
|
112 |
msgid "An error occurred when saving the snippet."
|
113 |
msgstr ""
|
114 |
|
115 |
+
#: php/admin-menus/class-edit-menu.php:432
|
116 |
msgid "Snippet <strong>added</strong>."
|
117 |
msgstr ""
|
118 |
|
119 |
+
#: php/admin-menus/class-edit-menu.php:433
|
120 |
msgid "Snippet <strong>updated</strong>."
|
121 |
msgstr ""
|
122 |
|
123 |
+
#: php/admin-menus/class-edit-menu.php:434
|
124 |
msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
|
125 |
msgstr ""
|
126 |
|
127 |
+
#: php/admin-menus/class-edit-menu.php:435
|
128 |
msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
|
129 |
msgstr ""
|
130 |
|
131 |
+
#: php/admin-menus/class-edit-menu.php:436
|
132 |
msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
|
133 |
msgstr ""
|
134 |
|
php/admin-menus/class-admin-menu.php
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
3 |
class Code_Snippets_Admin_Menu {
|
4 |
|
5 |
public $name, $label, $title;
|
@@ -28,10 +31,10 @@ class Code_Snippets_Admin_Menu {
|
|
28 |
*/
|
29 |
public function add_menu( $slug, $label, $title ) {
|
30 |
$hook = add_submenu_page(
|
31 |
-
|
32 |
$title,
|
33 |
$label,
|
34 |
-
|
35 |
$slug,
|
36 |
array( $this, 'render' )
|
37 |
);
|
@@ -43,7 +46,7 @@ class Code_Snippets_Admin_Menu {
|
|
43 |
* Register the admin menu
|
44 |
*/
|
45 |
public function register() {
|
46 |
-
$this->add_menu(
|
47 |
}
|
48 |
|
49 |
/**
|
@@ -51,7 +54,7 @@ class Code_Snippets_Admin_Menu {
|
|
51 |
*/
|
52 |
public function render() {
|
53 |
$this->print_messages();
|
54 |
-
include dirname(
|
55 |
}
|
56 |
|
57 |
/**
|
@@ -61,19 +64,24 @@ class Code_Snippets_Admin_Menu {
|
|
61 |
|
62 |
/**
|
63 |
* Retrieve a result message based on a posted status
|
64 |
-
*
|
|
|
|
|
|
|
|
|
|
|
65 |
*/
|
66 |
protected function get_result_message( $messages, $request_var = 'result', $class = 'updated' ) {
|
67 |
|
68 |
if ( empty( $_REQUEST[ $request_var ] ) ) {
|
69 |
-
return;
|
70 |
}
|
71 |
|
72 |
$result = $_REQUEST[ $request_var ];
|
73 |
|
74 |
if ( isset( $messages[ $result ] ) ) {
|
75 |
return sprintf(
|
76 |
-
'<div id="message" class="%
|
77 |
$messages[ $result ], $class
|
78 |
);
|
79 |
}
|
@@ -86,11 +94,11 @@ class Code_Snippets_Admin_Menu {
|
|
86 |
*/
|
87 |
public function load() {
|
88 |
/* Make sure the user has permission to be here */
|
89 |
-
if ( ! current_user_can(
|
90 |
wp_die( __( 'You are not authorized to access this page.', 'code-snippets' ) );
|
91 |
}
|
92 |
|
93 |
/* Create the snippet tables if they don't exist */
|
94 |
-
|
95 |
}
|
96 |
}
|
1 |
<?php
|
2 |
|
3 |
+
/**
|
4 |
+
* Base class for a snippets admin menu
|
5 |
+
*/
|
6 |
class Code_Snippets_Admin_Menu {
|
7 |
|
8 |
public $name, $label, $title;
|
31 |
*/
|
32 |
public function add_menu( $slug, $label, $title ) {
|
33 |
$hook = add_submenu_page(
|
34 |
+
code_snippets()->get_menu_slug(),
|
35 |
$title,
|
36 |
$label,
|
37 |
+
code_snippets()->get_cap(),
|
38 |
$slug,
|
39 |
array( $this, 'render' )
|
40 |
);
|
46 |
* Register the admin menu
|
47 |
*/
|
48 |
public function register() {
|
49 |
+
$this->add_menu( code_snippets()->get_menu_slug( $this->name ), $this->label, $this->title );
|
50 |
}
|
51 |
|
52 |
/**
|
54 |
*/
|
55 |
public function render() {
|
56 |
$this->print_messages();
|
57 |
+
include dirname( dirname( __FILE__ ) ) . "/views/{$this->name}.php";
|
58 |
}
|
59 |
|
60 |
/**
|
64 |
|
65 |
/**
|
66 |
* Retrieve a result message based on a posted status
|
67 |
+
*
|
68 |
+
* @param array $messages
|
69 |
+
* @param string $request_var
|
70 |
+
* @param string $class
|
71 |
+
*
|
72 |
+
* @return string|bool The result message if a valid status was received, otherwise false
|
73 |
*/
|
74 |
protected function get_result_message( $messages, $request_var = 'result', $class = 'updated' ) {
|
75 |
|
76 |
if ( empty( $_REQUEST[ $request_var ] ) ) {
|
77 |
+
return false;
|
78 |
}
|
79 |
|
80 |
$result = $_REQUEST[ $request_var ];
|
81 |
|
82 |
if ( isset( $messages[ $result ] ) ) {
|
83 |
return sprintf(
|
84 |
+
'<div id="message" class="%2$s fade"><p>%1$s</p></div>',
|
85 |
$messages[ $result ], $class
|
86 |
);
|
87 |
}
|
94 |
*/
|
95 |
public function load() {
|
96 |
/* Make sure the user has permission to be here */
|
97 |
+
if ( ! current_user_can( code_snippets()->get_cap() ) ) {
|
98 |
wp_die( __( 'You are not authorized to access this page.', 'code-snippets' ) );
|
99 |
}
|
100 |
|
101 |
/* Create the snippet tables if they don't exist */
|
102 |
+
code_snippets()->db->create_tables();
|
103 |
}
|
104 |
}
|
php/admin-menus/class-edit-menu.php
CHANGED
@@ -24,13 +24,13 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
24 |
|
25 |
/* Add New Snippet menu */
|
26 |
$this->add_menu(
|
27 |
-
|
28 |
__( 'Add New', 'code-snippets' ),
|
29 |
__( 'Add New Snippet', 'code-snippets' )
|
30 |
);
|
31 |
|
32 |
/* Add edit menu if we are currently editing a snippet */
|
33 |
-
if ( isset( $_REQUEST['page'] ) &&
|
34 |
parent::register();
|
35 |
}
|
36 |
}
|
@@ -42,15 +42,16 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
42 |
parent::load();
|
43 |
|
44 |
/* Don't allow visiting the edit snippet page without a valid ID */
|
45 |
-
if (
|
46 |
if ( ! isset( $_REQUEST['id'] ) || 0 == $_REQUEST['id'] ) {
|
47 |
-
wp_redirect(
|
48 |
exit;
|
49 |
}
|
50 |
}
|
51 |
|
52 |
/* Load the contextual help tabs */
|
53 |
-
|
|
|
54 |
|
55 |
/* Enqueue the code editor and other scripts and styles */
|
56 |
add_action( 'admin_enqueue_scripts', 'code_snippets_enqueue_codemirror' );
|
@@ -73,122 +74,200 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
73 |
add_action( 'code_snippets/admin/single/settings', array( $this, 'render_multisite_sharing_setting' ) );
|
74 |
}
|
75 |
|
76 |
-
$this->
|
77 |
}
|
78 |
|
79 |
/**
|
80 |
-
*
|
81 |
-
* @uses wp_redirect() to pass the results to the page
|
82 |
-
* @uses save_snippet() to save the snippet to the database
|
83 |
*/
|
84 |
-
private function
|
85 |
|
86 |
-
/*
|
87 |
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'save_snippet' ) ) {
|
88 |
return;
|
89 |
}
|
90 |
|
91 |
-
/* Save the snippet if one has been submitted */
|
92 |
if ( isset( $_POST['save_snippet'] ) || isset( $_POST['save_snippet_activate'] ) || isset( $_POST['save_snippet_deactivate'] ) ) {
|
|
|
|
|
93 |
|
94 |
-
|
95 |
-
$snippet = new Snippet();
|
96 |
-
foreach ( $_POST as $field => $value ) {
|
97 |
-
if ( 'snippet_' === substr( $field, 0, 8 ) ) {
|
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 |
exit;
|
179 |
}
|
180 |
|
181 |
-
/*
|
182 |
-
|
183 |
-
|
184 |
-
|
|
|
|
|
185 |
exit;
|
186 |
}
|
187 |
|
188 |
-
/*
|
189 |
-
|
190 |
-
|
|
|
|
|
|
|
|
|
|
|
191 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
192 |
}
|
193 |
|
194 |
/**
|
@@ -288,30 +367,85 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
288 |
<?php
|
289 |
}
|
290 |
|
291 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
* Print the status and error messages
|
293 |
*/
|
294 |
protected function print_messages() {
|
295 |
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
300 |
);
|
301 |
|
302 |
-
|
303 |
-
|
304 |
-
echo $error;
|
305 |
-
} else {
|
306 |
-
echo $this->get_result_message(
|
307 |
-
array(
|
308 |
-
'added' => __( 'Snippet <strong>added</strong>.', 'code-snippets' ),
|
309 |
-
'updated' => __( 'Snippet <strong>updated</strong>.', 'code-snippets' ),
|
310 |
-
'added-and-activated' => __( 'Snippet <strong>added</strong> and <strong>activated</strong>.', 'code-snippets' ),
|
311 |
-
'updated-and-activated' => __( 'Snippet <strong>updated</strong> and <strong>activated</strong>.', 'code-snippets' ),
|
312 |
-
'updated-and-deactivated' => __( 'Snippet <strong>updated</strong> and <strong>deactivated</strong>.', 'code-snippets' ),
|
313 |
-
)
|
314 |
-
);
|
315 |
}
|
316 |
}
|
317 |
|
@@ -352,7 +486,7 @@ class Code_Snippets_Edit_Menu extends Code_Snippets_Admin_Menu {
|
|
352 |
global $pagenow;
|
353 |
|
354 |
/* Try to discern if we are on the single snippet page as best as we can at this early time */
|
355 |
-
is_admin() && 'admin.php' === $pagenow && isset( $_GET['page'] ) &&
|
356 |
|
357 |
/* Remove the action and stop all Debug Bar Console scripts */
|
358 |
&& remove_action( 'debug_bar_enqueue_scripts', 'debug_bar_console_scripts' );
|
24 |
|
25 |
/* Add New Snippet menu */
|
26 |
$this->add_menu(
|
27 |
+
code_snippets()->get_menu_slug( 'add' ),
|
28 |
__( 'Add New', 'code-snippets' ),
|
29 |
__( 'Add New Snippet', 'code-snippets' )
|
30 |
);
|
31 |
|
32 |
/* Add edit menu if we are currently editing a snippet */
|
33 |
+
if ( isset( $_REQUEST['page'] ) && code_snippets()->get_menu_slug( 'edit' ) === $_REQUEST['page'] ) {
|
34 |
parent::register();
|
35 |
}
|
36 |
}
|
42 |
parent::load();
|
43 |
|
44 |
/* Don't allow visiting the edit snippet page without a valid ID */
|
45 |
+
if ( code_snippets()->get_menu_slug( 'edit' ) === $_REQUEST['page'] ) {
|
46 |
if ( ! isset( $_REQUEST['id'] ) || 0 == $_REQUEST['id'] ) {
|
47 |
+
wp_redirect( code_snippets()->get_menu_url( 'add' ) );
|
48 |
exit;
|
49 |
}
|
50 |
}
|
51 |
|
52 |
/* Load the contextual help tabs */
|
53 |
+
$contextual_help = new Code_Snippets_Contextual_Help( 'edit' );
|
54 |
+
$contextual_help->load();
|
55 |
|
56 |
/* Enqueue the code editor and other scripts and styles */
|
57 |
add_action( 'admin_enqueue_scripts', 'code_snippets_enqueue_codemirror' );
|
74 |
add_action( 'code_snippets/admin/single/settings', array( $this, 'render_multisite_sharing_setting' ) );
|
75 |
}
|
76 |
|
77 |
+
$this->process_actions();
|
78 |
}
|
79 |
|
80 |
/**
|
81 |
+
* Process data sent from the edit page
|
|
|
|
|
82 |
*/
|
83 |
+
private function process_actions() {
|
84 |
|
85 |
+
/* Check for a valid nonce */
|
86 |
if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'save_snippet' ) ) {
|
87 |
return;
|
88 |
}
|
89 |
|
|
|
90 |
if ( isset( $_POST['save_snippet'] ) || isset( $_POST['save_snippet_activate'] ) || isset( $_POST['save_snippet_deactivate'] ) ) {
|
91 |
+
$this->save_posted_snippet();
|
92 |
+
}
|
93 |
|
94 |
+
if ( isset( $_POST['snippet_id'] ) ) {
|
|
|
|
|
|
|
95 |
|
96 |
+
/* Delete the snippet if the button was clicked */
|
97 |
+
if ( isset( $_POST['delete_snippet'] ) ) {
|
98 |
+
delete_snippet( $_POST['snippet_id'] );
|
99 |
+
wp_redirect( add_query_arg( 'result', 'delete', code_snippets()->get_menu_url( 'manage' ) ) );
|
100 |
+
exit;
|
101 |
}
|
102 |
|
103 |
+
/* Export the snippet if the button was clicked */
|
104 |
+
if ( isset( $_POST['export_snippet'] ) ) {
|
105 |
+
export_snippets( $_POST['snippet_id'] );
|
106 |
+
}
|
107 |
+
}
|
108 |
+
}
|
109 |
|
110 |
+
/**
|
111 |
+
* Remove the sharing status from a network snippet
|
112 |
+
* @param int $snippet_id
|
113 |
+
*/
|
114 |
+
private function unshare_network_snippet( $snippet_id ) {
|
115 |
+
$shared_snippets = get_site_option( 'shared_network_snippets', array() );
|
116 |
+
|
117 |
+
if ( ! in_array( $snippet_id, $shared_snippets ) ) {
|
118 |
+
return;
|
119 |
+
}
|
120 |
+
|
121 |
+
/* Remove the snippet ID from the array */
|
122 |
+
$shared_snippets = array_diff( $shared_snippets, array( $snippet_id ) );
|
123 |
+
update_site_option( 'shared_network_snippets', array_values( $shared_snippets ) );
|
124 |
+
|
125 |
+
/* Deactivate on all sites */
|
126 |
+
global $wpdb;
|
127 |
+
if ( $sites = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ) ) {
|
128 |
+
|
129 |
+
foreach ( $sites as $site ) {
|
130 |
+
switch_to_blog( $site );
|
131 |
+
$active_shared_snippets = get_option( 'active_shared_network_snippets' );
|
132 |
+
|
133 |
+
if ( is_array( $active_shared_snippets ) ) {
|
134 |
+
$active_shared_snippets = array_diff( $active_shared_snippets, array( $snippet_id ) );
|
135 |
+
update_option( 'active_shared_network_snippets', $active_shared_snippets );
|
136 |
+
}
|
137 |
}
|
138 |
|
139 |
+
restore_current_blog();
|
140 |
+
}
|
141 |
+
}
|
142 |
+
|
143 |
+
private function code_error_callback( $out ) {
|
144 |
+
$error = error_get_last();
|
145 |
|
146 |
+
if ( is_null( $error ) || ! in_array( $error['type'], array( E_ERROR, E_COMPILE_ERROR, E_USER_ERROR ) ) ) {
|
147 |
+
return $out;
|
148 |
+
}
|
149 |
|
150 |
+
$m = '<h2>' . __( "Don't Panic", 'code-snippets' ) . '</h2>';
|
151 |
+
$m .= '<p>' . sprintf( __( 'The code snippet you are trying to save produced a fatal error on line %d:', 'code_snippets' ), $error['line'] ) . '</p>';
|
152 |
+
$m .= '<strong>' . $error['message'] . '</strong>';
|
153 |
+
$m .= '<p>' . __( 'The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.' ) . '</p>';
|
154 |
+
$m .= '<p>' . __( 'Please use the back button in your browser to return to the previous page and try to fix the code error.', 'code-snippets' );
|
155 |
+
$m .= ' ' . __( 'If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.', 'code-snippets' ) . '</p>';
|
156 |
|
157 |
+
return $m;
|
158 |
+
}
|
159 |
+
|
160 |
+
/**
|
161 |
+
* Validate the snippet code before saving to database
|
162 |
+
*
|
163 |
+
* @param Snippet $snippet
|
164 |
+
*
|
165 |
+
* @return bool true if code produces errors
|
166 |
+
*/
|
167 |
+
private function validate_code( Snippet $snippet ) {
|
168 |
|
169 |
+
if ( empty( $snippet->code ) ) {
|
170 |
+
return false;
|
171 |
+
}
|
172 |
|
173 |
+
/* Skip snippets that contain named functions */
|
174 |
+
if ( preg_match( '/(?:function|class)\s+\w+/i', $snippet->code ) ) {
|
175 |
+
return false;
|
176 |
+
}
|
177 |
|
178 |
+
ob_start( array( $this, 'code_error_callback' ) );
|
179 |
+
$result = eval( $snippet->code );
|
180 |
+
ob_end_clean();
|
|
|
|
|
181 |
|
182 |
+
return false === $result;
|
183 |
+
}
|
184 |
|
185 |
+
/**
|
186 |
+
* Save the posted snippet data to the database and redirect
|
187 |
+
*/
|
188 |
+
private function save_posted_snippet() {
|
189 |
+
|
190 |
+
/* Build snippet object from fields with 'snippet_' prefix */
|
191 |
+
$snippet = new Snippet();
|
192 |
+
foreach ( $_POST as $field => $value ) {
|
193 |
+
if ( 'snippet_' === substr( $field, 0, 8 ) ) {
|
194 |
+
|
195 |
+
/* Remove 'snippet_' prefix from field name */
|
196 |
+
$field = substr( $field, 8 );
|
197 |
+
$snippet->$field = stripslashes( $value );
|
198 |
}
|
199 |
+
}
|
200 |
|
201 |
+
/* Activate or deactivate the snippet before saving if we clicked the button */
|
202 |
+
|
203 |
+
// Shared network snippets cannot be network activated
|
204 |
+
if ( isset( $_POST['snippet_sharing'] ) && 'on' === $_POST['snippet_sharing'] ) {
|
205 |
+
$snippet->active = 0;
|
206 |
+
unset( $_POST['save_snippet_activate'], $_POST['save_snippet_deactivate'] );
|
207 |
+
} elseif ( isset( $_POST['save_snippet_activate'] ) ) {
|
208 |
+
$snippet->active = 1;
|
209 |
+
} elseif ( isset( $_POST['save_snippet_deactivate'] ) ) {
|
210 |
+
$snippet->active = 0;
|
211 |
+
}
|
212 |
+
|
213 |
+
/* Deactivate snippet if code contains errors */
|
214 |
+
if ( $snippet->active ) {
|
215 |
+
if ( $code_error = $this->validate_code( $snippet ) ) {
|
216 |
+
$snippet->active = 0;
|
217 |
}
|
218 |
+
}
|
219 |
+
|
220 |
+
/* Save the snippet to the database */
|
221 |
+
$snippet_id = save_snippet( $snippet );
|
222 |
+
|
223 |
+
/* Update the shared network snippets if necessary */
|
224 |
+
if ( $snippet_id && get_current_screen()->in_admin( 'network' ) ) {
|
225 |
|
226 |
+
if ( isset( $_POST['snippet_sharing'] ) && 'on' === $_POST['snippet_sharing'] ) {
|
227 |
+
$shared_snippets = get_site_option( 'shared_network_snippets', array() );
|
228 |
|
229 |
+
/* Add the snippet ID to the array if it isn't already */
|
230 |
+
if ( ! in_array( $snippet_id, $shared_snippets ) ) {
|
231 |
+
$shared_snippets[] = $snippet_id;
|
232 |
+
update_site_option( 'shared_network_snippets', array_values( $shared_snippets ) );
|
233 |
+
}
|
234 |
+
} else {
|
235 |
+
$this->unshare_network_snippet( $snippet_id );
|
236 |
}
|
237 |
+
}
|
238 |
|
239 |
+
/* If the saved snippet ID is invalid, display an error message */
|
240 |
+
if ( ! $snippet_id || $snippet_id < 1 ) {
|
241 |
+
/* An error occurred */
|
242 |
+
wp_redirect( add_query_arg( 'result', 'save-error', code_snippets()->get_menu_url( 'add' ) ) );
|
|
|
243 |
exit;
|
244 |
}
|
245 |
|
246 |
+
/* Display message if a parse error occurred */
|
247 |
+
if ( isset( $code_error ) && $code_error ) {
|
248 |
+
wp_redirect( add_query_arg(
|
249 |
+
array( 'id' => $snippet_id, 'result' => 'code-error' ),
|
250 |
+
code_snippets()->get_menu_url( 'edit' )
|
251 |
+
) );
|
252 |
exit;
|
253 |
}
|
254 |
|
255 |
+
/* Set the result depending on if the snippet was just added */
|
256 |
+
$result = isset( $_POST['snippet_id'] ) ? 'updated' : 'added';
|
257 |
+
|
258 |
+
/* Append a suffix if the snippet was activated or deactivated */
|
259 |
+
if ( isset( $_POST['save_snippet_activate'] ) ) {
|
260 |
+
$result .= '-and-activated';
|
261 |
+
} elseif ( isset( $_POST['save_snippet_deactivate'] ) ) {
|
262 |
+
$result .= '-and-deactivated';
|
263 |
}
|
264 |
+
|
265 |
+
/* Redirect to edit snippet page */
|
266 |
+
wp_redirect( add_query_arg(
|
267 |
+
array( 'id' => $snippet_id, 'result' => $result ),
|
268 |
+
code_snippets()->get_menu_url( 'edit' )
|
269 |
+
) );
|
270 |
+
exit;
|
271 |
}
|
272 |
|
273 |
/**
|
367 |
<?php
|
368 |
}
|
369 |
|
370 |
+
/**
|
371 |
+
* Retrieve the first error in a snippet's code
|
372 |
+
*
|
373 |
+
* @param $snippet_id
|
374 |
+
*
|
375 |
+
* @return array|bool
|
376 |
+
*/
|
377 |
+
private function get_snippet_error( $snippet_id ) {
|
378 |
+
|
379 |
+
if ( ! intval( $snippet_id ) ) {
|
380 |
+
return false;
|
381 |
+
}
|
382 |
+
|
383 |
+
$snippet = get_snippet( intval( $snippet_id ) );
|
384 |
+
|
385 |
+
if ( '' === $snippet->code ) {
|
386 |
+
return false;
|
387 |
+
}
|
388 |
+
|
389 |
+
ob_start();
|
390 |
+
$result = eval( $snippet->code );
|
391 |
+
ob_end_clean();
|
392 |
+
|
393 |
+
if ( false !== $result ) {
|
394 |
+
return false;
|
395 |
+
}
|
396 |
+
|
397 |
+
$error = error_get_last();
|
398 |
+
|
399 |
+
if ( is_null( $error ) ) {
|
400 |
+
return false;
|
401 |
+
}
|
402 |
+
|
403 |
+
return $error;
|
404 |
+
}
|
405 |
+
|
406 |
+
/**
|
407 |
* Print the status and error messages
|
408 |
*/
|
409 |
protected function print_messages() {
|
410 |
|
411 |
+
if ( ! isset( $_REQUEST['result'] ) ) {
|
412 |
+
return;
|
413 |
+
}
|
414 |
+
|
415 |
+
$result = $_REQUEST['result'];
|
416 |
+
|
417 |
+
if ( 'code-error' === $result ) {
|
418 |
+
|
419 |
+
if ( isset( $_REQUEST['id'] ) && $error = $this->get_snippet_error( $_REQUEST['id'] ) ) {
|
420 |
+
|
421 |
+
printf(
|
422 |
+
'<div id="message" class="error fade"><p>%s</p><p><strong>%s</strong></p></div>',
|
423 |
+
sprintf( __( 'The snippet has been deactivated due to an error on line %d:', 'code-snippets' ), $error['line'] ),
|
424 |
+
$error['message']
|
425 |
+
);
|
426 |
+
|
427 |
+
} else {
|
428 |
+
echo '<div id="message" class="error fade"><p>', __( 'The snippet has been deactivated due to an error in the code.', 'code-snippets' ), '</p></div>';
|
429 |
+
}
|
430 |
+
|
431 |
+
return;
|
432 |
+
}
|
433 |
+
|
434 |
+
if ( 'save-error' === $result ) {
|
435 |
+
echo '<div id="message" class="error fade"><p>', __( 'An error occurred when saving the snippet.', 'code-snippets' ), '</p></div>';
|
436 |
+
return;
|
437 |
+
}
|
438 |
+
|
439 |
+
$messages = array(
|
440 |
+
'added' => __( 'Snippet <strong>added</strong>.', 'code-snippets' ),
|
441 |
+
'updated' => __( 'Snippet <strong>updated</strong>.', 'code-snippets' ),
|
442 |
+
'added-and-activated' => __( 'Snippet <strong>added</strong> and <strong>activated</strong>.', 'code-snippets' ),
|
443 |
+
'updated-and-activated' => __( 'Snippet <strong>updated</strong> and <strong>activated</strong>.', 'code-snippets' ),
|
444 |
+
'updated-and-deactivated' => __( 'Snippet <strong>updated</strong> and <strong>deactivated</strong>.', 'code-snippets' ),
|
445 |
);
|
446 |
|
447 |
+
if ( isset( $messages[ $result ] ) ) {
|
448 |
+
echo '<div id="message" class="updated fade"><p>', $messages[ $result ], '</p></div>';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
449 |
}
|
450 |
}
|
451 |
|
486 |
global $pagenow;
|
487 |
|
488 |
/* Try to discern if we are on the single snippet page as best as we can at this early time */
|
489 |
+
is_admin() && 'admin.php' === $pagenow && isset( $_GET['page'] ) && code_snippets()->get_menu_slug( 'edit' ) === $_GET['page']
|
490 |
|
491 |
/* Remove the action and stop all Debug Bar Console scripts */
|
492 |
&& remove_action( 'debug_bar_enqueue_scripts', 'debug_bar_console_scripts' );
|
php/admin-menus/class-import-menu.php
CHANGED
@@ -25,7 +25,10 @@ class Code_Snippets_Import_Menu extends Code_Snippets_Admin_Menu {
|
|
25 |
*/
|
26 |
public function load() {
|
27 |
parent::load();
|
28 |
-
|
|
|
|
|
|
|
29 |
$this->process_import_file();
|
30 |
}
|
31 |
|
25 |
*/
|
26 |
public function load() {
|
27 |
parent::load();
|
28 |
+
|
29 |
+
$contextual_help = new Code_Snippets_Contextual_Help( 'import' );
|
30 |
+
$contextual_help->load();
|
31 |
+
|
32 |
$this->process_import_file();
|
33 |
}
|
34 |
|
php/admin-menus/class-manage-menu.php
CHANGED
@@ -38,8 +38,8 @@ class Code_Snippets_Manage_Menu extends Code_Snippets_Admin_Menu {
|
|
38 |
add_menu_page(
|
39 |
__( 'Snippets', 'code-snippets' ),
|
40 |
__( 'Snippets', 'code-snippets' ),
|
41 |
-
|
42 |
-
|
43 |
array( $this, 'render' ),
|
44 |
'div', // icon is added through CSS
|
45 |
is_network_admin() ? 21 : 67
|
@@ -56,10 +56,10 @@ class Code_Snippets_Manage_Menu extends Code_Snippets_Admin_Menu {
|
|
56 |
parent::load();
|
57 |
|
58 |
/* Load the contextual help tabs */
|
59 |
-
|
|
|
60 |
|
61 |
/* Initialize the list table class */
|
62 |
-
require_once plugin_dir_path( CODE_SNIPPETS_FILE ) . 'php/class-list-table.php';
|
63 |
$this->list_table = new Code_Snippets_List_Table();
|
64 |
$this->list_table->prepare_items();
|
65 |
}
|
38 |
add_menu_page(
|
39 |
__( 'Snippets', 'code-snippets' ),
|
40 |
__( 'Snippets', 'code-snippets' ),
|
41 |
+
code_snippets()->get_cap(),
|
42 |
+
code_snippets()->get_menu_slug(),
|
43 |
array( $this, 'render' ),
|
44 |
'div', // icon is added through CSS
|
45 |
is_network_admin() ? 21 : 67
|
56 |
parent::load();
|
57 |
|
58 |
/* Load the contextual help tabs */
|
59 |
+
$contextual_help = new Code_Snippets_Contextual_Help( 'manage' );
|
60 |
+
$contextual_help->load();
|
61 |
|
62 |
/* Initialize the list table class */
|
|
|
63 |
$this->list_table = new Code_Snippets_List_Table();
|
64 |
$this->list_table->prepare_items();
|
65 |
}
|
php/admin.php
DELETED
@@ -1,203 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* General functions specific to the administration interface
|
5 |
-
*
|
6 |
-
* @package Code_Snippets
|
7 |
-
*/
|
8 |
-
|
9 |
-
/* Bail if not in admin area */
|
10 |
-
if ( ! is_admin() ) {
|
11 |
-
return;
|
12 |
-
}
|
13 |
-
|
14 |
-
/**
|
15 |
-
* Load the admin menu classes
|
16 |
-
*/
|
17 |
-
function code_snippets_load_admin_classes() {
|
18 |
-
$admin_classes = plugin_dir_path( __FILE__ ) . 'admin-menus/';
|
19 |
-
require_once $admin_classes . 'class-admin-menu.php';
|
20 |
-
|
21 |
-
/* Manage menu */
|
22 |
-
require_once $admin_classes . 'class-manage-menu.php';
|
23 |
-
new Code_Snippets_Manage_Menu();
|
24 |
-
|
25 |
-
/* Edit/add new menu */
|
26 |
-
require_once $admin_classes . 'class-edit-menu.php';
|
27 |
-
new Code_Snippets_Edit_Menu();
|
28 |
-
|
29 |
-
/* Import menu */
|
30 |
-
require_once $admin_classes . 'class-import-menu.php';
|
31 |
-
new Code_Snippets_Import_Menu();
|
32 |
-
|
33 |
-
if ( ! is_network_admin() ) {
|
34 |
-
|
35 |
-
/* Settings menu */
|
36 |
-
require_once $admin_classes . 'class-settings-menu.php';
|
37 |
-
new Code_Snippets_Settings_Menu();
|
38 |
-
}
|
39 |
-
}
|
40 |
-
|
41 |
-
code_snippets_load_admin_classes();
|
42 |
-
|
43 |
-
/**
|
44 |
-
* Allow super admins to control site admin access to
|
45 |
-
* snippet admin menus
|
46 |
-
*
|
47 |
-
* Adds a checkbox to the *Settings > Network Settings*
|
48 |
-
* network admin menu
|
49 |
-
*
|
50 |
-
* @since 1.7.1
|
51 |
-
*
|
52 |
-
* @param array $menu_items The current mu menu items
|
53 |
-
* @return array The modified mu menu items
|
54 |
-
*/
|
55 |
-
function code_snippets_mu_menu_items( $menu_items ) {
|
56 |
-
$menu_items['snippets'] = __( 'Snippets', 'code-snippets' );
|
57 |
-
return $menu_items;
|
58 |
-
}
|
59 |
-
|
60 |
-
add_filter( 'mu_menu_items', 'code_snippets_mu_menu_items' );
|
61 |
-
|
62 |
-
/**
|
63 |
-
* Enqueue the stylesheet for a snippet menu
|
64 |
-
*
|
65 |
-
* @since 2.2.0
|
66 |
-
* @uses wp_enqueue_style() to add the stylesheet to the queue
|
67 |
-
* @uses get_user_option() to check if MP6 mode is active
|
68 |
-
* @uses plugins_url() to retrieve a URL to assets
|
69 |
-
* @param string $hook the current page hook
|
70 |
-
*/
|
71 |
-
function code_snippets_enqueue_admin_stylesheet( $hook ) {
|
72 |
-
$pages = array( 'manage', 'add', 'edit', 'settings' );
|
73 |
-
$hooks = array_map( 'code_snippets_get_menu_hook', $pages );
|
74 |
-
|
75 |
-
/* First, load the menu icon stylesheet */
|
76 |
-
wp_enqueue_style(
|
77 |
-
'menu-icon-snippets',
|
78 |
-
plugins_url( 'css/min/menu-icon.css', CODE_SNIPPETS_FILE ),
|
79 |
-
false,
|
80 |
-
CODE_SNIPPETS_VERSION
|
81 |
-
);
|
82 |
-
|
83 |
-
/* Only load the stylesheet on the right snippets page */
|
84 |
-
if ( ! in_array( $hook, $hooks ) ) {
|
85 |
-
return;
|
86 |
-
}
|
87 |
-
|
88 |
-
$hooks = array_combine( $hooks, $pages );
|
89 |
-
$page = $hooks[ $hook ];
|
90 |
-
|
91 |
-
// add snippet page uses edit stylesheet
|
92 |
-
'add' === $page && $page = 'edit';
|
93 |
-
|
94 |
-
wp_enqueue_style(
|
95 |
-
"code-snippets-$page",
|
96 |
-
plugins_url( "css/min/$page.css", CODE_SNIPPETS_FILE ),
|
97 |
-
false,
|
98 |
-
CODE_SNIPPETS_VERSION
|
99 |
-
);
|
100 |
-
}
|
101 |
-
|
102 |
-
add_action( 'admin_enqueue_scripts', 'code_snippets_enqueue_admin_stylesheet' );
|
103 |
-
|
104 |
-
/**
|
105 |
-
* Adds a link pointing to the Manage Snippets page
|
106 |
-
*
|
107 |
-
* @since 2.0
|
108 |
-
*
|
109 |
-
* @param array $links The existing plugin action links
|
110 |
-
* @return array The modified plugin action links
|
111 |
-
*/
|
112 |
-
function code_snippets_plugin_settings_link( $links ) {
|
113 |
-
array_unshift( $links, sprintf(
|
114 |
-
'<a href="%1$s" title="%2$s">%3$s</a>',
|
115 |
-
code_snippets_get_menu_url(),
|
116 |
-
__( 'Manage your existing snippets', 'code-snippets' ),
|
117 |
-
__( 'Manage', 'code-snippets' )
|
118 |
-
) );
|
119 |
-
return $links;
|
120 |
-
}
|
121 |
-
|
122 |
-
add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), 'code_snippets_plugin_settings_link' );
|
123 |
-
|
124 |
-
/**
|
125 |
-
* Adds extra links related to the plugin
|
126 |
-
*
|
127 |
-
* @since 2.0
|
128 |
-
|
129 |
-
* @param array $links The existing plugin info links
|
130 |
-
* @param string $file The plugin the links are for
|
131 |
-
* @return array The modified plugin info links
|
132 |
-
*/
|
133 |
-
function code_snippets_plugin_meta( $links, $file ) {
|
134 |
-
|
135 |
-
/* We only want to affect the Code Snippets plugin listing */
|
136 |
-
if ( plugin_basename( CODE_SNIPPETS_FILE ) !== $file ) {
|
137 |
-
return $links;
|
138 |
-
}
|
139 |
-
|
140 |
-
$format = '<a href="%1$s" title="%2$s">%3$s</a>';
|
141 |
-
|
142 |
-
/* array_merge appends the links to the end */
|
143 |
-
return array_merge( $links, array(
|
144 |
-
sprintf( $format,
|
145 |
-
'http://wordpress.org/plugins/code-snippets/',
|
146 |
-
__( 'Visit the WordPress.org plugin page', 'code-snippets' ),
|
147 |
-
__( 'About', 'code-snippets' )
|
148 |
-
),
|
149 |
-
sprintf( $format,
|
150 |
-
'http://wordpress.org/support/plugin/code-snippets/',
|
151 |
-
__( 'Visit the support forums', 'code-snippets' ),
|
152 |
-
__( 'Support', 'code-snippets' )
|
153 |
-
),
|
154 |
-
sprintf( $format,
|
155 |
-
'http://bungeshea.com/donate/',
|
156 |
-
__( "Support this plugin's development", 'code-snippets' ),
|
157 |
-
__( 'Donate', 'code-snippets' )
|
158 |
-
),
|
159 |
-
) );
|
160 |
-
}
|
161 |
-
|
162 |
-
add_filter( 'plugin_row_meta', 'code_snippets_plugin_meta', 10, 2 );
|
163 |
-
|
164 |
-
/**
|
165 |
-
* Print a notice inviting people to participate in the Code Snippets Survey
|
166 |
-
*
|
167 |
-
* @since 1.9
|
168 |
-
* @return void
|
169 |
-
*/
|
170 |
-
function code_snippets_survey_message() {
|
171 |
-
global $current_user;
|
172 |
-
|
173 |
-
$key = 'ignore_code_snippets_survey_message';
|
174 |
-
|
175 |
-
/* Bail now if the user has dismissed the message */
|
176 |
-
if ( get_user_meta( $current_user->ID, $key ) ) {
|
177 |
-
return;
|
178 |
-
}
|
179 |
-
elseif ( isset( $_GET[ $key ], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $key ) ) {
|
180 |
-
add_user_meta( $current_user->ID, $key, true, true );
|
181 |
-
return;
|
182 |
-
}
|
183 |
-
|
184 |
-
?>
|
185 |
-
|
186 |
-
<br />
|
187 |
-
|
188 |
-
<div class="updated"><p>
|
189 |
-
|
190 |
-
<?php _e( "<strong>Have feedback on Code Snippets?</strong> Please take the time to answer a short survey on how you use this plugin and what you'd like to see changed or added in the future.", 'code-snippets' ); ?>
|
191 |
-
|
192 |
-
<a href="http://sheabunge.polldaddy.com/s/code-snippets-feedback" class="button secondary" target="_blank" style="margin: auto .5em;">
|
193 |
-
<?php _e( 'Take the survey now', 'code-snippets' ); ?>
|
194 |
-
</a>
|
195 |
-
|
196 |
-
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( $key, true ), $key ) ); ?>">Dismiss</a>
|
197 |
-
|
198 |
-
</p></div>
|
199 |
-
|
200 |
-
<?php
|
201 |
-
}
|
202 |
-
|
203 |
-
add_action( 'code_snippets/admin/manage', 'code_snippets_survey_message' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
php/caps.php
DELETED
@@ -1,60 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Get the required capability to perform a certain action on snippets.
|
5 |
-
* Does not check if the user has this capability or not.
|
6 |
-
*
|
7 |
-
* If multisite, checks if *Enable Administration Menus: Snippets* is active
|
8 |
-
* under the *Settings > Network Settings* network admin menu
|
9 |
-
*
|
10 |
-
* @since 2.0
|
11 |
-
* @return string The capability required to manage snippets
|
12 |
-
*/
|
13 |
-
function get_snippets_cap() {
|
14 |
-
|
15 |
-
if ( is_multisite() ) {
|
16 |
-
$menu_perms = get_site_option( 'menu_items', array() );
|
17 |
-
|
18 |
-
/* If multisite is enabled and the snippet menu is not activated,
|
19 |
-
restrict snippet operations to super admins only */
|
20 |
-
if ( empty( $menu_perms['snippets'] ) ) {
|
21 |
-
return apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
|
22 |
-
}
|
23 |
-
}
|
24 |
-
|
25 |
-
return apply_filters( 'code_snippets_cap', 'manage_snippets' );
|
26 |
-
}
|
27 |
-
|
28 |
-
/**
|
29 |
-
* Add the multisite capabilities to a user
|
30 |
-
*
|
31 |
-
* @since 2.0
|
32 |
-
* @param int $user_id The ID of the user to add the cap to
|
33 |
-
*/
|
34 |
-
function grant_network_snippets_cap( $user_id ) {
|
35 |
-
|
36 |
-
/* Get the user from the ID */
|
37 |
-
$user = new WP_User( $user_id );
|
38 |
-
|
39 |
-
/* Add the capability */
|
40 |
-
$user->add_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
|
41 |
-
}
|
42 |
-
|
43 |
-
add_action( 'grant_super_admin', 'grant_network_snippets_cap' );
|
44 |
-
|
45 |
-
/**
|
46 |
-
* Remove the multisite capabilities from a user
|
47 |
-
*
|
48 |
-
* @since 2.0
|
49 |
-
* @param int $user_id The ID of the user to remove the cap from
|
50 |
-
*/
|
51 |
-
function remove_network_snippets_cap( $user_id ) {
|
52 |
-
|
53 |
-
/* Get the user from the ID */
|
54 |
-
$user = new WP_User( $user_id );
|
55 |
-
|
56 |
-
/* Remove the capability */
|
57 |
-
$user->remove_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
|
58 |
-
}
|
59 |
-
|
60 |
-
add_action( 'remove_super_admin', 'remove_network_snippets_cap' );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
php/class-admin.php
ADDED
@@ -0,0 +1,196 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Functions specific to the administration interface
|
5 |
+
*
|
6 |
+
* @package Code_Snippets
|
7 |
+
*/
|
8 |
+
class Code_Snippets_Admin {
|
9 |
+
|
10 |
+
public $menus = array();
|
11 |
+
|
12 |
+
function __construct() {
|
13 |
+
|
14 |
+
if ( is_admin() ) {
|
15 |
+
$this->load_classes();
|
16 |
+
$this->run();
|
17 |
+
}
|
18 |
+
}
|
19 |
+
|
20 |
+
private function load_classes() {
|
21 |
+
$this->menus['manage'] = new Code_Snippets_Manage_Menu();
|
22 |
+
$this->menus['edit'] = new Code_Snippets_Edit_Menu();
|
23 |
+
$this->menus['import'] = new Code_Snippets_Import_Menu();
|
24 |
+
|
25 |
+
if ( ! is_network_admin() ) {
|
26 |
+
$this->menus['settings'] = new Code_Snippets_Settings_Menu();
|
27 |
+
}
|
28 |
+
}
|
29 |
+
|
30 |
+
function run() {
|
31 |
+
add_filter( 'mu_menu_items', array( $this, 'mu_menu_items' ) );
|
32 |
+
add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_stylesheet' ) );
|
33 |
+
add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), array( $this, 'plugin_settings_link' ) );
|
34 |
+
add_filter( 'plugin_row_meta', array( $this, 'plugin_meta_links' ), 10, 2 );
|
35 |
+
add_action( 'code_snippets/admin/manage', array( $this, 'survey_message' ) );
|
36 |
+
}
|
37 |
+
|
38 |
+
/**
|
39 |
+
* Allow super admins to control site admin access to
|
40 |
+
* snippet admin menus
|
41 |
+
*
|
42 |
+
* Adds a checkbox to the *Settings > Network Settings*
|
43 |
+
* network admin menu
|
44 |
+
*
|
45 |
+
* @since 1.7.1
|
46 |
+
*
|
47 |
+
* @param array $menu_items The current mu menu items
|
48 |
+
*
|
49 |
+
* @return array The modified mu menu items
|
50 |
+
*/
|
51 |
+
function mu_menu_items( $menu_items ) {
|
52 |
+
$menu_items['snippets'] = __( 'Snippets', 'code-snippets' );
|
53 |
+
return $menu_items;
|
54 |
+
}
|
55 |
+
|
56 |
+
/**
|
57 |
+
* Enqueue the stylesheet for a snippet menu
|
58 |
+
*
|
59 |
+
* @since 2.2.0
|
60 |
+
* @uses wp_enqueue_style() to add the stylesheet to the queue
|
61 |
+
* @uses get_user_option() to check if MP6 mode is active
|
62 |
+
* @uses plugins_url() to retrieve a URL to assets
|
63 |
+
*
|
64 |
+
* @param string $hook the current page hook
|
65 |
+
*/
|
66 |
+
function enqueue_admin_stylesheet( $hook ) {
|
67 |
+
$pages = array( 'manage', 'add', 'edit', 'settings' );
|
68 |
+
$hooks = array_map( 'code_snippets_get_menu_hook', $pages );
|
69 |
+
|
70 |
+
/* First, load the menu icon stylesheet */
|
71 |
+
wp_enqueue_style(
|
72 |
+
'menu-icon-snippets',
|
73 |
+
plugins_url( 'css/min/menu-icon.css', CODE_SNIPPETS_FILE ),
|
74 |
+
false,
|
75 |
+
CODE_SNIPPETS_VERSION
|
76 |
+
);
|
77 |
+
|
78 |
+
/* Only load the stylesheet on the right snippets page */
|
79 |
+
if ( ! in_array( $hook, $hooks ) ) {
|
80 |
+
return;
|
81 |
+
}
|
82 |
+
|
83 |
+
$hooks = array_combine( $hooks, $pages );
|
84 |
+
$page = $hooks[ $hook ];
|
85 |
+
|
86 |
+
// add snippet page uses edit stylesheet
|
87 |
+
'add' === $page && $page = 'edit';
|
88 |
+
|
89 |
+
wp_enqueue_style(
|
90 |
+
"code-snippets-$page",
|
91 |
+
plugins_url( "css/min/$page.css", CODE_SNIPPETS_FILE ),
|
92 |
+
false,
|
93 |
+
CODE_SNIPPETS_VERSION
|
94 |
+
);
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Adds a link pointing to the Manage Snippets page
|
99 |
+
*
|
100 |
+
* @since 2.0
|
101 |
+
*
|
102 |
+
* @param array $links The existing plugin action links
|
103 |
+
*
|
104 |
+
* @return array The modified plugin action links
|
105 |
+
*/
|
106 |
+
function plugin_settings_link( $links ) {
|
107 |
+
array_unshift( $links, sprintf(
|
108 |
+
'<a href="%1$s" title="%2$s">%3$s</a>',
|
109 |
+
code_snippets()->get_menu_url(),
|
110 |
+
__( 'Manage your existing snippets', 'code-snippets' ),
|
111 |
+
__( 'Manage', 'code-snippets' )
|
112 |
+
) );
|
113 |
+
|
114 |
+
return $links;
|
115 |
+
}
|
116 |
+
|
117 |
+
/**
|
118 |
+
* Adds extra links related to the plugin
|
119 |
+
*
|
120 |
+
* @since 2.0
|
121 |
+
*
|
122 |
+
* @param array $links The existing plugin info links
|
123 |
+
* @param string $file The plugin the links are for
|
124 |
+
*
|
125 |
+
* @return array The modified plugin info links
|
126 |
+
*/
|
127 |
+
function plugin_meta_links( $links, $file ) {
|
128 |
+
|
129 |
+
/* We only want to affect the Code Snippets plugin listing */
|
130 |
+
if ( plugin_basename( CODE_SNIPPETS_FILE ) !== $file ) {
|
131 |
+
return $links;
|
132 |
+
}
|
133 |
+
|
134 |
+
$format = '<a href="%1$s" title="%2$s">%3$s</a>';
|
135 |
+
|
136 |
+
/* array_merge appends the links to the end */
|
137 |
+
|
138 |
+
return array_merge( $links, array(
|
139 |
+
sprintf( $format,
|
140 |
+
'http://wordpress.org/plugins/code-snippets/',
|
141 |
+
__( 'Visit the WordPress.org plugin page', 'code-snippets' ),
|
142 |
+
__( 'About', 'code-snippets' )
|
143 |
+
),
|
144 |
+
sprintf( $format,
|
145 |
+
'http://wordpress.org/support/plugin/code-snippets/',
|
146 |
+
__( 'Visit the support forums', 'code-snippets' ),
|
147 |
+
__( 'Support', 'code-snippets' )
|
148 |
+
),
|
149 |
+
sprintf( $format,
|
150 |
+
'http://bungeshea.com/donate/',
|
151 |
+
__( "Support this plugin's development", 'code-snippets' ),
|
152 |
+
__( 'Donate', 'code-snippets' )
|
153 |
+
),
|
154 |
+
) );
|
155 |
+
}
|
156 |
+
|
157 |
+
/**
|
158 |
+
* Print a notice inviting people to participate in the Code Snippets Survey
|
159 |
+
*
|
160 |
+
* @since 1.9
|
161 |
+
* @return void
|
162 |
+
*/
|
163 |
+
function survey_message() {
|
164 |
+
global $current_user;
|
165 |
+
|
166 |
+
$key = 'ignore_code_snippets_survey_message';
|
167 |
+
|
168 |
+
/* Bail now if the user has dismissed the message */
|
169 |
+
if ( get_user_meta( $current_user->ID, $key ) ) {
|
170 |
+
return;
|
171 |
+
} elseif ( isset( $_GET[ $key ], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $key ) ) {
|
172 |
+
add_user_meta( $current_user->ID, $key, true, true );
|
173 |
+
|
174 |
+
return;
|
175 |
+
}
|
176 |
+
|
177 |
+
?>
|
178 |
+
|
179 |
+
<br/>
|
180 |
+
|
181 |
+
<div class="updated"><p>
|
182 |
+
|
183 |
+
<?php _e( "<strong>Have feedback on Code Snippets?</strong> Please take the time to answer a short survey on how you use this plugin and what you'd like to see changed or added in the future.", 'code-snippets' ); ?>
|
184 |
+
|
185 |
+
<a href="http://sheabunge.polldaddy.com/s/code-snippets-feedback" class="button secondary"
|
186 |
+
target="_blank" style="margin: auto .5em;">
|
187 |
+
<?php _e( 'Take the survey now', 'code-snippets' ); ?>
|
188 |
+
</a>
|
189 |
+
|
190 |
+
<a href="<?php echo esc_url( wp_nonce_url( add_query_arg( $key, true ), $key ) ); ?>">Dismiss</a>
|
191 |
+
|
192 |
+
</p></div>
|
193 |
+
|
194 |
+
<?php
|
195 |
+
}
|
196 |
+
}
|
php/class-code-snippets.php
ADDED
@@ -0,0 +1,208 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* The main plugin class
|
5 |
+
*
|
6 |
+
* @package Code_Snippets
|
7 |
+
*/
|
8 |
+
class Code_Snippets {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* The current plugin version
|
12 |
+
* @var string
|
13 |
+
*/
|
14 |
+
public $version;
|
15 |
+
|
16 |
+
/**
|
17 |
+
* Filesystem path to the main plugin file
|
18 |
+
* @var string
|
19 |
+
*/
|
20 |
+
public $file;
|
21 |
+
|
22 |
+
/**
|
23 |
+
* @var Code_Snippets_DB
|
24 |
+
*/
|
25 |
+
public $db;
|
26 |
+
|
27 |
+
/**
|
28 |
+
* @var Code_Snippets_Admin
|
29 |
+
*/
|
30 |
+
public $admin;
|
31 |
+
|
32 |
+
/**
|
33 |
+
* Class constructor
|
34 |
+
*
|
35 |
+
* @param string $version The current plugin version
|
36 |
+
* @param string $file The main plugin file
|
37 |
+
*/
|
38 |
+
function __construct( $version, $file ) {
|
39 |
+
$this->version = $version;
|
40 |
+
$this->file = $file;
|
41 |
+
|
42 |
+
add_action( 'grant_super_admin', array( $this, 'grant_network_cap' ) );
|
43 |
+
add_action( 'remove_super_admin', array( $this, 'remove_network_cap' ) );
|
44 |
+
}
|
45 |
+
|
46 |
+
function load_plugin() {
|
47 |
+
$includes_path = dirname( __FILE__ );
|
48 |
+
|
49 |
+
/* Database operation functions */
|
50 |
+
$this->db = new Code_Snippets_DB();
|
51 |
+
|
52 |
+
/* Snippet operation functions */
|
53 |
+
require_once $includes_path . '/snippet-ops.php';
|
54 |
+
|
55 |
+
/* Upgrade function */
|
56 |
+
require_once $includes_path . '/upgrade.php';
|
57 |
+
|
58 |
+
/* CodeMirror editor functions */
|
59 |
+
require_once $includes_path . '/editor.php';
|
60 |
+
|
61 |
+
/* Backwards compatability functions */
|
62 |
+
require_once $includes_path . '/functions.php';
|
63 |
+
|
64 |
+
/* General Administration functions */
|
65 |
+
if ( is_admin() ) {
|
66 |
+
$this->admin = new Code_Snippets_Admin();
|
67 |
+
}
|
68 |
+
|
69 |
+
/* Settings component */
|
70 |
+
require_once $includes_path . '/settings/settings-fields.php';
|
71 |
+
require_once $includes_path . '/settings/editor-preview.php';
|
72 |
+
require_once $includes_path . '/settings/render-fields.php';
|
73 |
+
require_once $includes_path . '/settings/settings.php';
|
74 |
+
|
75 |
+
$this->shortcode = new Code_Snippets_Shortcode();
|
76 |
+
}
|
77 |
+
|
78 |
+
/**
|
79 |
+
* Fetch the admin menu slug for a snippets menu
|
80 |
+
* @param string $menu The menu to retrieve the slug for
|
81 |
+
* @return string The menu's slug
|
82 |
+
*/
|
83 |
+
public function get_menu_slug( $menu = '' ) {
|
84 |
+
$add = array( 'single', 'add', 'add-new', 'add-snippet', 'new-snippet', 'add-new-snippet' );
|
85 |
+
$edit = array( 'edit', 'edit-snippet' );
|
86 |
+
$import = array( 'import', 'import-snippets' );
|
87 |
+
$settings = array( 'settings', 'snippets-settings' );
|
88 |
+
|
89 |
+
if ( in_array( $menu, $edit ) ) {
|
90 |
+
return 'edit-snippet';
|
91 |
+
} elseif ( in_array( $menu, $add ) ) {
|
92 |
+
return 'add-snippet';
|
93 |
+
} elseif ( in_array( $menu, $import ) ) {
|
94 |
+
return 'import-snippets';
|
95 |
+
} elseif ( in_array( $menu, $settings ) ) {
|
96 |
+
return 'snippets-settings';
|
97 |
+
} else {
|
98 |
+
return 'snippets';
|
99 |
+
}
|
100 |
+
}
|
101 |
+
|
102 |
+
/**
|
103 |
+
* Fetch the URL to a snippets admin menu
|
104 |
+
* @param string $menu The menu to retrieve the URL to
|
105 |
+
* @param string $context The URL scheme to use
|
106 |
+
* @return string The menu's URL
|
107 |
+
*/
|
108 |
+
public function get_menu_url( $menu = '', $context = 'self' ) {
|
109 |
+
$slug = $this->get_menu_slug( $menu );
|
110 |
+
$url = 'admin.php?page=' . $slug;
|
111 |
+
|
112 |
+
if ( 'network' === $context ) {
|
113 |
+
return network_admin_url( $url );
|
114 |
+
} elseif ( 'admin' === $context ) {
|
115 |
+
return admin_url( $url );
|
116 |
+
} else {
|
117 |
+
return self_admin_url( $url );
|
118 |
+
}
|
119 |
+
}
|
120 |
+
|
121 |
+
/**
|
122 |
+
* Fetch the admin menu hook for a snippets menu
|
123 |
+
* @param string $menu The menu to retrieve the hook for
|
124 |
+
* @return string The menu's hook
|
125 |
+
*/
|
126 |
+
public function get_menu_hook( $menu = '' ) {
|
127 |
+
$slug = $this->get_menu_slug( $menu );
|
128 |
+
return get_plugin_page_hookname( $slug, 'snippets' );
|
129 |
+
}
|
130 |
+
|
131 |
+
/**
|
132 |
+
* Fetch the admin menu slug for a snippets menu
|
133 |
+
* @param int $snippet_id The snippet
|
134 |
+
* @param string $context The URL scheme to use
|
135 |
+
* @return string The URL to the edit snippet page for that snippet
|
136 |
+
*/
|
137 |
+
public function get_snippet_edit_url( $snippet_id, $context = 'self' ) {
|
138 |
+
return add_query_arg(
|
139 |
+
'id', absint( $snippet_id ),
|
140 |
+
$this->get_menu_url( 'edit', $context )
|
141 |
+
);
|
142 |
+
}
|
143 |
+
|
144 |
+
/**
|
145 |
+
* Determine whether the current user can perform actions on snippets.
|
146 |
+
*
|
147 |
+
* @since [NEXT_VERSION]
|
148 |
+
* @return boolean Whether the current user has the required capability
|
149 |
+
*/
|
150 |
+
public function current_user_can() {
|
151 |
+
return current_user_can( $this->get_cap() );
|
152 |
+
}
|
153 |
+
|
154 |
+
/**
|
155 |
+
* Get the required capability to perform a certain action on snippets.
|
156 |
+
* Does not check if the user has this capability or not.
|
157 |
+
*
|
158 |
+
* If multisite, checks if *Enable Administration Menus: Snippets* is active
|
159 |
+
* under the *Settings > Network Settings* network admin menu
|
160 |
+
*
|
161 |
+
* @since 2.0
|
162 |
+
* @return string The capability required to manage snippets
|
163 |
+
*/
|
164 |
+
public function get_cap() {
|
165 |
+
|
166 |
+
if ( is_multisite() ) {
|
167 |
+
$menu_perms = get_site_option( 'menu_items', array() );
|
168 |
+
|
169 |
+
/* If multisite is enabled and the snippet menu is not activated,
|
170 |
+
restrict snippet operations to super admins only */
|
171 |
+
if ( empty( $menu_perms['snippets'] ) ) {
|
172 |
+
return apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
|
173 |
+
}
|
174 |
+
}
|
175 |
+
|
176 |
+
return apply_filters( 'code_snippets_cap', 'manage_snippets' );
|
177 |
+
}
|
178 |
+
|
179 |
+
/**
|
180 |
+
* Add the multisite capabilities to a user
|
181 |
+
*
|
182 |
+
* @since 2.0
|
183 |
+
* @param int $user_id The ID of the user to add the cap to
|
184 |
+
*/
|
185 |
+
function grant_network_cap( $user_id ) {
|
186 |
+
|
187 |
+
/* Get the user from the ID */
|
188 |
+
$user = new WP_User( $user_id );
|
189 |
+
|
190 |
+
/* Add the capability */
|
191 |
+
$user->add_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
|
192 |
+
}
|
193 |
+
|
194 |
+
/**
|
195 |
+
* Remove the multisite capabilities from a user
|
196 |
+
*
|
197 |
+
* @since 2.0
|
198 |
+
* @param int $user_id The ID of the user to remove the cap from
|
199 |
+
*/
|
200 |
+
function remove_network_cap( $user_id ) {
|
201 |
+
|
202 |
+
/* Get the user from the ID */
|
203 |
+
$user = new WP_User( $user_id );
|
204 |
+
|
205 |
+
/* Remove the capability */
|
206 |
+
$user->remove_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
|
207 |
+
}
|
208 |
+
}
|
php/class-contextual-help.php
ADDED
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* This file holds all of the content for the contextual help screens
|
5 |
+
* @package Code_Snippets
|
6 |
+
*/
|
7 |
+
class Code_Snippets_Contextual_Help {
|
8 |
+
|
9 |
+
/**
|
10 |
+
* @var WP_Screen
|
11 |
+
*/
|
12 |
+
public $screen;
|
13 |
+
|
14 |
+
/**
|
15 |
+
* @param string $screen_name
|
16 |
+
*/
|
17 |
+
function __construct( $screen_name ) {
|
18 |
+
$this->screen_name = $screen_name;
|
19 |
+
}
|
20 |
+
|
21 |
+
/**
|
22 |
+
* Load the contextual help
|
23 |
+
*/
|
24 |
+
public function load() {
|
25 |
+
$this->screen = get_current_screen();
|
26 |
+
|
27 |
+
if ( method_exists( $this, "load_{$this->screen_name}_help" ) ) {
|
28 |
+
call_user_func( array( $this, "load_{$this->screen_name}_help" ) );
|
29 |
+
}
|
30 |
+
|
31 |
+
$this->load_help_sidebar();
|
32 |
+
}
|
33 |
+
|
34 |
+
/**
|
35 |
+
* Load the help sidebar
|
36 |
+
*/
|
37 |
+
private function load_help_sidebar() {
|
38 |
+
|
39 |
+
$this->screen->set_help_sidebar(
|
40 |
+
'<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
|
41 |
+
'<p><a href="https://wordpress.org/plugins/code-snippets">' . __( 'About Plugin', 'code-snippets' ) . '</a></p>' .
|
42 |
+
'<p><a href="https://wordpress.org/plugins/code-snippets/faq">' . __( 'FAQ', 'code-snippets' ) . '</a></p>' .
|
43 |
+
'<p><a href="https://wordpress.org/support/plugin/code-snippets">' . __( 'Support Forums', 'code-snippets' ) . '</a></p>' .
|
44 |
+
'<p><a href="http://bungeshea.com/plugins/code-snippets/">' . __( 'Plugin Website', 'code-snippets' ) . '</a></p>'
|
45 |
+
);
|
46 |
+
}
|
47 |
+
|
48 |
+
/**
|
49 |
+
* Register and handle the help tabs for the manage snippets admin page
|
50 |
+
*/
|
51 |
+
private function load_manage_help() {
|
52 |
+
|
53 |
+
$this->screen->add_help_tab( array(
|
54 |
+
'id' => 'overview',
|
55 |
+
'title' => __( 'Overview', 'code-snippets' ),
|
56 |
+
'content' =>
|
57 |
+
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can manage your existing snippets and preform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' ) . '</p>',
|
58 |
+
) );
|
59 |
+
|
60 |
+
$this->screen->add_help_tab( array(
|
61 |
+
'id' => 'safe-mode',
|
62 |
+
'title' => __( 'Safe Mode', 'code-snippets' ),
|
63 |
+
'content' =>
|
64 |
+
'<p>' . __( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ) . '</p>' .
|
65 |
+
'<p>' . __( "If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>.", 'code-snippets' ) . '</p>',
|
66 |
+
) );
|
67 |
+
|
68 |
+
$this->screen->add_help_tab( array(
|
69 |
+
'id' => 'uninstall',
|
70 |
+
'title' => __( 'Uninstall', 'code-snippets' ),
|
71 |
+
'content' =>
|
72 |
+
'<p>' . sprintf( __( 'When you delete Code Snippets through the Plugins menu in WordPress it will clear up the <code>%1$s</code> table and a few other bits of data stored in the database. If you want to keep this data (ie: you are only temporally uninstalling Code Snippets) then remove the <code>%2$s</code> folder using FTP.', 'code-snippets' ), get_snippets_table_name(), dirname( CODE_SNIPPETS_FILE ) ) .
|
73 |
+
'<p>' . __( "Even if you're sure that you don't want to use Code Snippets ever again on this WordPress installation, you may want to use the export feature to back up your snippets.", 'code-snippets' ) . '</p>',
|
74 |
+
) );
|
75 |
+
}
|
76 |
+
|
77 |
+
/**
|
78 |
+
* Register and handle the help tabs for the single snippet admin page
|
79 |
+
*/
|
80 |
+
private function load_edit_help() {
|
81 |
+
|
82 |
+
$this->screen->add_help_tab( array(
|
83 |
+
'id' => 'overview',
|
84 |
+
'title' => __( 'Overview', 'code-snippets' ),
|
85 |
+
'content' =>
|
86 |
+
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can add a new snippet, or edit an existing one.', 'code-snippets' ) . '</p>',
|
87 |
+
) );
|
88 |
+
|
89 |
+
$this->screen->add_help_tab( array(
|
90 |
+
'id' => 'finding',
|
91 |
+
'title' => __( 'Finding Snippets', 'code-snippets' ),
|
92 |
+
'content' =>
|
93 |
+
'<p>' . __( 'Here are some links to websites which host a large number of snippets that you can add to your site.
|
94 |
+
<ul>
|
95 |
+
<li><a href="http://wp-snippets.com" title="WordPress Snippets">WP-Snippets</a></li>
|
96 |
+
<li><a href="http://wpsnipp.com" title="WP Snipp">WP Snipp</a></li>
|
97 |
+
<li><a href="http://www.catswhocode.com/blog/snippets" title="Cats Who Code Snippet Library">Cats Who Code</a></li>
|
98 |
+
<li><a href="http://www.wpfunction.me">WP Function Me</a></li>
|
99 |
+
</ul>', 'code-snippets' ) .
|
100 |
+
__( 'More places to find snippets, as well as a selection of example snippets, can be found in the <a href="https://github.com/sheabunge/code-snippets/wiki/Finding-snippets">plugin documentation</a>', 'code-snippets' ) . '</p>',
|
101 |
+
) );
|
102 |
+
|
103 |
+
$this->screen->add_help_tab( array(
|
104 |
+
'id' => 'adding',
|
105 |
+
'title' => __( 'Adding Snippets', 'code-snippets' ),
|
106 |
+
'content' =>
|
107 |
+
'<p>' . __( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ) . '</p>' .
|
108 |
+
'<p>' . __( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ) . '</p>',
|
109 |
+
) );
|
110 |
+
}
|
111 |
+
|
112 |
+
/**
|
113 |
+
* Register and handle the help tabs for the import snippets admin page
|
114 |
+
*/
|
115 |
+
private function load_import_help() {
|
116 |
+
$manage_url = code_snippets()->get_menu_url( 'manage' );
|
117 |
+
|
118 |
+
$this->screen->add_help_tab( array(
|
119 |
+
'id' => 'overview',
|
120 |
+
'title' => __( 'Overview', 'code-snippets' ),
|
121 |
+
'content' =>
|
122 |
+
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets' ) . '</p>',
|
123 |
+
) );
|
124 |
+
|
125 |
+
$this->screen->add_help_tab( array(
|
126 |
+
'id' => 'import',
|
127 |
+
'title' => __( 'Importing', 'code-snippets' ),
|
128 |
+
'content' =>
|
129 |
+
'<p>' . __( 'You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets' ) .
|
130 |
+
sprintf( __( 'Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets' ), $manage_url ) . '</p>',
|
131 |
+
) );
|
132 |
+
|
133 |
+
$this->screen->add_help_tab( array(
|
134 |
+
'id' => 'export',
|
135 |
+
'title' => __( 'Exporting', 'code-snippets' ),
|
136 |
+
'content' =>
|
137 |
+
'<p>' . sprintf( __( 'You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url ) . '</p>',
|
138 |
+
) );
|
139 |
+
}
|
140 |
+
}
|
php/class-db.php
ADDED
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
/**
|
4 |
+
* Functions used to manage the database tables
|
5 |
+
*
|
6 |
+
* @package Code_Snippets
|
7 |
+
*/
|
8 |
+
class Code_Snippets_DB {
|
9 |
+
|
10 |
+
/**
|
11 |
+
* Class constructor
|
12 |
+
*/
|
13 |
+
function __construct() {
|
14 |
+
$this->set_table_vars();
|
15 |
+
}
|
16 |
+
|
17 |
+
/**
|
18 |
+
* Register the snippet table names with WordPress
|
19 |
+
*
|
20 |
+
* @since 2.0
|
21 |
+
* @uses $wpdb
|
22 |
+
*/
|
23 |
+
function set_table_vars() {
|
24 |
+
global $wpdb;
|
25 |
+
|
26 |
+
/* Register the snippet table names with WordPress */
|
27 |
+
$wpdb->tables[] = 'snippets';
|
28 |
+
$wpdb->ms_global_tables[] = 'ms_snippets';
|
29 |
+
|
30 |
+
/* Setup initial table variables */
|
31 |
+
$wpdb->snippets = $wpdb->prefix . 'snippets';
|
32 |
+
$wpdb->ms_snippets = $wpdb->base_prefix . 'ms_snippets';
|
33 |
+
}
|
34 |
+
|
35 |
+
/**
|
36 |
+
* Return the appropriate snippet table name
|
37 |
+
*
|
38 |
+
* @since 2.0
|
39 |
+
*
|
40 |
+
* @param string|bool|null $multisite Retrieve the multisite table name or the site table name?
|
41 |
+
*
|
42 |
+
* @return string The snippet table name
|
43 |
+
*/
|
44 |
+
function get_table_name( $multisite = null ) {
|
45 |
+
global $wpdb;
|
46 |
+
|
47 |
+
/* If the first parameter is a string, assume it is a table name */
|
48 |
+
if ( is_string( $multisite ) ) {
|
49 |
+
return $multisite;
|
50 |
+
}
|
51 |
+
|
52 |
+
/* If $multisite is null, try to base it on the current admin page */
|
53 |
+
if ( ! isset( $multisite ) && function_exists( 'get_current_screen' ) ) {
|
54 |
+
$multisite = get_current_screen()->in_admin( 'network' );
|
55 |
+
}
|
56 |
+
|
57 |
+
/* If multisite is not active, always return the site-wide table name */
|
58 |
+
if ( ! is_multisite() ) {
|
59 |
+
$multisite = false;
|
60 |
+
}
|
61 |
+
|
62 |
+
/* Retrieve the table name from $wpdb depending on the above conditionals */
|
63 |
+
|
64 |
+
return ( $multisite ? $wpdb->ms_snippets : $wpdb->snippets );
|
65 |
+
}
|
66 |
+
|
67 |
+
/**
|
68 |
+
* Create the snippet tables
|
69 |
+
* This function will only execute once per page load, except if $redo is true
|
70 |
+
*
|
71 |
+
* @since 1.7.1
|
72 |
+
*
|
73 |
+
* @param bool $upgrade Run the table creation code even if the table exists
|
74 |
+
*/
|
75 |
+
function create_tables( $upgrade = false ) {
|
76 |
+
global $wpdb;
|
77 |
+
|
78 |
+
/* Set the table name variables if not yet defined */
|
79 |
+
if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
|
80 |
+
$this->set_table_vars();
|
81 |
+
}
|
82 |
+
|
83 |
+
if ( is_multisite() ) {
|
84 |
+
|
85 |
+
/* Create the network snippets table if it doesn't exist, or upgrade it */
|
86 |
+
if ( $upgrade || $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) !== $wpdb->ms_snippets ) {
|
87 |
+
$this->create_table( $wpdb->ms_snippets );
|
88 |
+
}
|
89 |
+
}
|
90 |
+
|
91 |
+
/* Create the table if it doesn't exist, or upgrade it */
|
92 |
+
if ( $upgrade || $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) !== $wpdb->snippets ) {
|
93 |
+
$this->create_table( $wpdb->snippets );
|
94 |
+
}
|
95 |
+
}
|
96 |
+
|
97 |
+
/**
|
98 |
+
* Create a single snippet table
|
99 |
+
*
|
100 |
+
* @since 1.6
|
101 |
+
* @uses dbDelta() to apply the SQL code
|
102 |
+
*
|
103 |
+
* @param string $table_name The name of the table to create
|
104 |
+
*/
|
105 |
+
function create_table( $table_name ) {
|
106 |
+
global $wpdb;
|
107 |
+
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
108 |
+
|
109 |
+
/* Set the database charset */
|
110 |
+
$charset_collate = '';
|
111 |
+
|
112 |
+
if ( ! empty( $wpdb->charset ) ) {
|
113 |
+
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
114 |
+
}
|
115 |
+
|
116 |
+
if ( ! empty( $wpdb->collate ) ) {
|
117 |
+
$charset_collate .= " COLLATE $wpdb->collate";
|
118 |
+
}
|
119 |
+
|
120 |
+
/* Create the database table */
|
121 |
+
$sql = "CREATE TABLE $table_name (
|
122 |
+
id bigint(20) NOT NULL AUTO_INCREMENT,
|
123 |
+
name tinytext NOT NULL default '',
|
124 |
+
description text NOT NULL default '',
|
125 |
+
code longtext NOT NULL default '',
|
126 |
+
tags longtext NOT NULL default '',
|
127 |
+
scope tinyint(1) NOT NULL default 0,
|
128 |
+
active tinyint(1) NOT NULL default 0,
|
129 |
+
PRIMARY KEY (id)
|
130 |
+
) $charset_collate;";
|
131 |
+
|
132 |
+
dbDelta( $sql );
|
133 |
+
do_action( 'code_snippets/create_table', $table_name );
|
134 |
+
}
|
135 |
+
}
|
php/class-list-table.php
CHANGED
@@ -341,7 +341,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
341 |
*
|
342 |
* @return array The IDs of the columns that can be sorted
|
343 |
*/
|
344 |
-
|
345 |
$sortable_columns = array(
|
346 |
'id' => array( 'id', true ),
|
347 |
'name' => array( 'name', false ),
|
@@ -364,7 +364,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
364 |
*
|
365 |
* @return array An array of menu items with the ID paired to the label
|
366 |
*/
|
367 |
-
|
368 |
$actions = array(
|
369 |
'activate-selected' => $this->is_network ? __( 'Network Activate', 'code-snippets' ) : __( 'Activate', 'code-snippets' ),
|
370 |
'deactivate-selected' => $this->is_network ? __( 'Network Deactivate', 'code-snippets' ) : __( 'Deactivate', 'code-snippets' ),
|
@@ -382,7 +382,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
382 |
*
|
383 |
* @return array The classes to include on the table element
|
384 |
*/
|
385 |
-
|
386 |
$classes = array( 'widefat', $this->_args['plural'] );
|
387 |
return apply_filters( 'code_snippets/list_table/table_classes', $classes );
|
388 |
}
|
@@ -394,7 +394,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
394 |
*
|
395 |
* @return array A list of the view labels linked to the view
|
396 |
*/
|
397 |
-
|
398 |
global $totals, $status;
|
399 |
$status_links = array();
|
400 |
|
@@ -458,7 +458,7 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
458 |
* Add filters and extra actions above and below the table
|
459 |
* @param string $which Are the actions displayed on the table top or bottom
|
460 |
*/
|
461 |
-
|
462 |
global $status, $wpdb;
|
463 |
|
464 |
if ( 'top' === $which ) {
|
@@ -919,20 +919,14 @@ class Code_Snippets_List_Table extends WP_List_Table {
|
|
919 |
$term = stripslashes( $_REQUEST['s'] );
|
920 |
}
|
921 |
|
922 |
-
|
923 |
|
924 |
-
|
925 |
-
|
926 |
-
|
927 |
-
}
|
928 |
-
}
|
929 |
-
elseif ( is_array( $value ) ) {
|
930 |
-
if ( false !== in_array( $term, $value ) ) {
|
931 |
-
return true;
|
932 |
-
}
|
933 |
}
|
934 |
}
|
935 |
-
|
936 |
return false;
|
937 |
}
|
938 |
|
341 |
*
|
342 |
* @return array The IDs of the columns that can be sorted
|
343 |
*/
|
344 |
+
public function get_sortable_columns() {
|
345 |
$sortable_columns = array(
|
346 |
'id' => array( 'id', true ),
|
347 |
'name' => array( 'name', false ),
|
364 |
*
|
365 |
* @return array An array of menu items with the ID paired to the label
|
366 |
*/
|
367 |
+
public function get_bulk_actions() {
|
368 |
$actions = array(
|
369 |
'activate-selected' => $this->is_network ? __( 'Network Activate', 'code-snippets' ) : __( 'Activate', 'code-snippets' ),
|
370 |
'deactivate-selected' => $this->is_network ? __( 'Network Deactivate', 'code-snippets' ) : __( 'Deactivate', 'code-snippets' ),
|
382 |
*
|
383 |
* @return array The classes to include on the table element
|
384 |
*/
|
385 |
+
public function get_table_classes() {
|
386 |
$classes = array( 'widefat', $this->_args['plural'] );
|
387 |
return apply_filters( 'code_snippets/list_table/table_classes', $classes );
|
388 |
}
|
394 |
*
|
395 |
* @return array A list of the view labels linked to the view
|
396 |
*/
|
397 |
+
public function get_views() {
|
398 |
global $totals, $status;
|
399 |
$status_links = array();
|
400 |
|
458 |
* Add filters and extra actions above and below the table
|
459 |
* @param string $which Are the actions displayed on the table top or bottom
|
460 |
*/
|
461 |
+
public function extra_tablenav( $which ) {
|
462 |
global $status, $wpdb;
|
463 |
|
464 |
if ( 'top' === $which ) {
|
919 |
$term = stripslashes( $_REQUEST['s'] );
|
920 |
}
|
921 |
|
922 |
+
$fields = array( 'name', 'desc', 'code', 'tags_list' );
|
923 |
|
924 |
+
foreach ( $fields as $field ) {
|
925 |
+
if ( false !== stripos( $snippet->$field, $term ) ) {
|
926 |
+
return true;
|
|
|
|
|
|
|
|
|
|
|
|
|
927 |
}
|
928 |
}
|
929 |
+
|
930 |
return false;
|
931 |
}
|
932 |
|
php/class-shortcode.php
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
|
3 |
+
class Code_Snippets_Shortcode {
|
4 |
+
|
5 |
+
function __construct() {
|
6 |
+
add_shortcode( 'code_snippet', array( $this, 'render_shortcode' ) );
|
7 |
+
add_action( 'the_posts', array( $this, 'enqueue_prism' ) );
|
8 |
+
}
|
9 |
+
|
10 |
+
function enqueue_prism( $posts ) {
|
11 |
+
|
12 |
+
if ( empty( $posts ) || code_snippets_get_setting( 'general', 'disable_prism' ) ) {
|
13 |
+
return $posts;
|
14 |
+
}
|
15 |
+
|
16 |
+
$found = false;
|
17 |
+
|
18 |
+
foreach ( $posts as $post ) {
|
19 |
+
|
20 |
+
if ( false !== stripos( $post->post_content, '[code_snippet' ) ) {
|
21 |
+
$found = true;
|
22 |
+
break;
|
23 |
+
}
|
24 |
+
}
|
25 |
+
|
26 |
+
if ( ! $found ) {
|
27 |
+
return $posts;
|
28 |
+
}
|
29 |
+
|
30 |
+
$plugin = code_snippets();
|
31 |
+
|
32 |
+
wp_enqueue_style(
|
33 |
+
'code-snippets-prism',
|
34 |
+
plugins_url( 'js/vendor/prism.css', $plugin->file ),
|
35 |
+
array(), $plugin->version
|
36 |
+
);
|
37 |
+
|
38 |
+
wp_enqueue_script(
|
39 |
+
'code-snippets-prism',
|
40 |
+
plugins_url( 'js/vendor/prism.js', $plugin->file ),
|
41 |
+
array(), $plugin->version, true
|
42 |
+
);
|
43 |
+
|
44 |
+
return $posts;
|
45 |
+
}
|
46 |
+
|
47 |
+
function render_shortcode( $atts ) {
|
48 |
+
|
49 |
+
$atts = shortcode_atts(
|
50 |
+
array(
|
51 |
+
'id' => 0,
|
52 |
+
'network' => false,
|
53 |
+
),
|
54 |
+
$atts, 'code_snippet'
|
55 |
+
);
|
56 |
+
|
57 |
+
if ( ! $id = intval( $atts['id'] ) ) {
|
58 |
+
return '';
|
59 |
+
}
|
60 |
+
|
61 |
+
$network = $atts['network'] ? true : false;
|
62 |
+
$snippet = get_snippet( $id, $network );
|
63 |
+
|
64 |
+
if ( ! trim( $snippet->code ) ) {
|
65 |
+
return '';
|
66 |
+
}
|
67 |
+
|
68 |
+
return '<pre><code class="language-php">' . esc_html( $snippet->code ) . '</code></pre>';
|
69 |
+
}
|
70 |
+
|
71 |
+
}
|
72 |
+
|
php/contextual-help.php
DELETED
@@ -1,124 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* This file holds all of the content for the contextual help screens
|
5 |
-
* @package Code_Snippets
|
6 |
-
*/
|
7 |
-
|
8 |
-
/* Exit from file if not loaded from inside WordPress admin */
|
9 |
-
if ( ! function_exists( 'is_admin' ) || ! is_admin() ) {
|
10 |
-
return;
|
11 |
-
}
|
12 |
-
|
13 |
-
/**
|
14 |
-
* Load the help sidebar
|
15 |
-
* @param WP_Screen $screen Screen object
|
16 |
-
*/
|
17 |
-
function code_snippets_load_help_sidebar( $screen ) {
|
18 |
-
$screen->set_help_sidebar(
|
19 |
-
'<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
|
20 |
-
'<p><a href="https://wordpress.org/plugins/code-snippets">' . __( 'About Plugin', 'code-snippets' ) . '</a></p>' .
|
21 |
-
'<p><a href="https://wordpress.org/plugins/code-snippets/faq">' . __( 'FAQ', 'code-snippets' ) . '</a></p>' .
|
22 |
-
'<p><a href="https://wordpress.org/support/plugin/code-snippets">' . __( 'Support Forums', 'code-snippets' ) . '</a></p>' .
|
23 |
-
'<p><a href="http://bungeshea.com/plugins/code-snippets/">' . __( 'Plugin Website</a>', 'code-snippets' ) . '</a></p>'
|
24 |
-
);
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Register and handle the help tabs for the manage snippets admin page
|
29 |
-
*/
|
30 |
-
function code_snippets_load_manage_help() {
|
31 |
-
$screen = get_current_screen();
|
32 |
-
code_snippets_load_help_sidebar( $screen );
|
33 |
-
|
34 |
-
$screen->add_help_tab( array(
|
35 |
-
'id' => 'overview',
|
36 |
-
'title' => __( 'Overview', 'code-snippets' ),
|
37 |
-
'content' =>
|
38 |
-
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can manage your existing snippets and preform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' ) . '</p>',
|
39 |
-
) );
|
40 |
-
|
41 |
-
$screen->add_help_tab( array(
|
42 |
-
'id' => 'safe-mode',
|
43 |
-
'title' => __( 'Safe Mode', 'code-snippets' ),
|
44 |
-
'content' =>
|
45 |
-
'<p>' . __( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ) . '</p>' .
|
46 |
-
'<p>' . __( "If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>.", 'code-snippets' ) . '</p>',
|
47 |
-
) );
|
48 |
-
|
49 |
-
$screen->add_help_tab( array(
|
50 |
-
'id' => 'uninstall',
|
51 |
-
'title' => __( 'Uninstall', 'code-snippets' ),
|
52 |
-
'content' =>
|
53 |
-
'<p>' . sprintf( __( 'When you delete Code Snippets through the Plugins menu in WordPress it will clear up the <code>%1$s</code> table and a few other bits of data stored in the database. If you want to keep this data (ie: you are only temporally uninstalling Code Snippets) then remove the <code>%2$s</code> folder using FTP.', 'code-snippets' ), get_snippets_table_name(), dirname( CODE_SNIPPETS_FILE ) ) .
|
54 |
-
'<p>' . __( "Even if you're sure that you don't want to use Code Snippets ever again on this WordPress installation, you may want to use the export feature to back up your snippets.", 'code-snippets' ) . '</p>',
|
55 |
-
) );
|
56 |
-
}
|
57 |
-
|
58 |
-
/**
|
59 |
-
* Register and handle the help tabs for the single snippet admin page
|
60 |
-
*/
|
61 |
-
function code_snippets_load_edit_help() {
|
62 |
-
$screen = get_current_screen();
|
63 |
-
code_snippets_load_help_sidebar( $screen );
|
64 |
-
|
65 |
-
$screen->add_help_tab( array(
|
66 |
-
'id' => 'overview',
|
67 |
-
'title' => __( 'Overview', 'code-snippets' ),
|
68 |
-
'content' =>
|
69 |
-
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can add a new snippet, or edit an existing one.', 'code-snippets' ) . '</p>',
|
70 |
-
) );
|
71 |
-
|
72 |
-
$screen->add_help_tab( array(
|
73 |
-
'id' => 'finding',
|
74 |
-
'title' => __( 'Finding Snippets', 'code-snippets' ),
|
75 |
-
'content' =>
|
76 |
-
'<p>' . __( 'Here are some links to websites which host a large number of snippets that you can add to your site.
|
77 |
-
<ul>
|
78 |
-
<li><a href="http://wp-snippets.com" title="WordPress Snippets">WP-Snippets</a></li>
|
79 |
-
<li><a href="http://wpsnipp.com" title="WP Snipp">WP Snipp</a></li>
|
80 |
-
<li><a href="http://www.catswhocode.com/blog/snippets" title="Cats Who Code Snippet Library">Cats Who Code</a></li>
|
81 |
-
<li><a href="http://www.wpfunction.me">WP Function Me</a></li>
|
82 |
-
</ul>', 'code-snippets' ) .
|
83 |
-
__( 'More places to find snippets, as well as a selection of example snippets, can be found in the <a href="https://github.com/sheabunge/code-snippets/wiki/Finding-snippets">plugin documentation</a>', 'code-snippets' ) . '</p>',
|
84 |
-
) );
|
85 |
-
|
86 |
-
$screen->add_help_tab( array(
|
87 |
-
'id' => 'adding',
|
88 |
-
'title' => __( 'Adding Snippets', 'code-snippets' ),
|
89 |
-
'content' =>
|
90 |
-
'<p>' . __( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ) . '</p>' .
|
91 |
-
'<p>' . __( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ) . '</p>',
|
92 |
-
) );
|
93 |
-
}
|
94 |
-
|
95 |
-
/**
|
96 |
-
* Register and handle the help tabs for the import snippets admin page
|
97 |
-
*/
|
98 |
-
function code_snippets_load_import_help() {
|
99 |
-
$screen = get_current_screen();
|
100 |
-
$manage_url = code_snippets_get_menu_url( 'manage' );
|
101 |
-
code_snippets_load_help_sidebar( $screen );
|
102 |
-
|
103 |
-
$screen->add_help_tab( array(
|
104 |
-
'id' => 'overview',
|
105 |
-
'title' => __( 'Overview', 'code-snippets' ),
|
106 |
-
'content' =>
|
107 |
-
'<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets' ) . '</p>',
|
108 |
-
) );
|
109 |
-
|
110 |
-
$screen->add_help_tab( array(
|
111 |
-
'id' => 'import',
|
112 |
-
'title' => __( 'Importing', 'code-snippets' ),
|
113 |
-
'content' =>
|
114 |
-
'<p>' . __( 'You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets' ) .
|
115 |
-
sprintf( __( 'Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets' ), $manage_url ) . '</p>',
|
116 |
-
) );
|
117 |
-
|
118 |
-
$screen->add_help_tab( array(
|
119 |
-
'id' => 'export',
|
120 |
-
'title' => __( 'Exporting', 'code-snippets' ),
|
121 |
-
'content' =>
|
122 |
-
'<p>' . sprintf( __( 'You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url ) . '</p>',
|
123 |
-
) );
|
124 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
php/db.php
DELETED
@@ -1,122 +0,0 @@
|
|
1 |
-
<?php
|
2 |
-
|
3 |
-
/**
|
4 |
-
* Functions used to manage the database tables
|
5 |
-
*
|
6 |
-
* @package Code_Snippets
|
7 |
-
*/
|
8 |
-
|
9 |
-
/**
|
10 |
-
* Register the snippet table names with WordPress
|
11 |
-
*
|
12 |
-
* @since 2.0
|
13 |
-
* @uses $wpdb
|
14 |
-
*/
|
15 |
-
function set_snippet_table_vars() {
|
16 |
-
global $wpdb;
|
17 |
-
|
18 |
-
/* Register the snippet table names with WordPress */
|
19 |
-
$wpdb->tables[] = 'snippets';
|
20 |
-
$wpdb->ms_global_tables[] = 'ms_snippets';
|
21 |
-
|
22 |
-
/* Setup initial table variables */
|
23 |
-
$wpdb->snippets = $wpdb->prefix . 'snippets';
|
24 |
-
$wpdb->ms_snippets = $wpdb->base_prefix . 'ms_snippets';
|
25 |
-
}
|
26 |
-
|
27 |
-
/**
|
28 |
-
* Return the appropriate snippet table name
|
29 |
-
*
|
30 |
-
* @since 2.0
|
31 |
-
* @param string|bool|null $multisite Retrieve the multisite table name or the site table name?
|
32 |
-
* @return string The snippet table name
|
33 |
-
*/
|
34 |
-
function get_snippets_table_name( $multisite = null ) {
|
35 |
-
global $wpdb;
|
36 |
-
|
37 |
-
/* If the first parameter is a string, assume it is a table name */
|
38 |
-
if ( is_string( $multisite ) ) {
|
39 |
-
return $multisite;
|
40 |
-
}
|
41 |
-
|
42 |
-
/* If $multisite is null, try to base it on the current admin page */
|
43 |
-
if ( ! isset( $multisite ) && function_exists( 'get_current_screen' ) ) {
|
44 |
-
$multisite = get_current_screen()->in_admin( 'network' );
|
45 |
-
}
|
46 |
-
|
47 |
-
/* If multisite is not active, always return the site-wide table name */
|
48 |
-
if ( ! is_multisite() ) {
|
49 |
-
$multisite = false;
|
50 |
-
}
|
51 |
-
|
52 |
-
/* Retrieve the table name from $wpdb depending on the above conditionals */
|
53 |
-
return ( $multisite ? $wpdb->ms_snippets : $wpdb->snippets );
|
54 |
-
}
|
55 |
-
|
56 |
-
/**
|
57 |
-
* Create the snippet tables
|
58 |
-
* This function will only execute once per page load, except if $redo is true
|
59 |
-
*
|
60 |
-
* @since 1.7.1
|
61 |
-
*
|
62 |
-
* @param bool $upgrade Run the table creation code even if the table exists
|
63 |
-
*/
|
64 |
-
function create_code_snippets_tables( $upgrade = false ) {
|
65 |
-
global $wpdb;
|
66 |
-
|
67 |
-
/* Set the table name variables if not yet defined */
|
68 |
-
if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
|
69 |
-
set_snippet_table_vars();
|
70 |
-
}
|
71 |
-
|
72 |
-
if ( is_multisite() ) {
|
73 |
-
|
74 |
-
/* Create the network snippets table if it doesn't exist, or upgrade it */
|
75 |
-
if ( $upgrade || $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) !== $wpdb->ms_snippets ) {
|
76 |
-
create_code_snippets_table( $wpdb->ms_snippets );
|
77 |
-
}
|
78 |
-
}
|
79 |
-
|
80 |
-
/* Create the table if it doesn't exist, or upgrade it */
|
81 |
-
if ( $upgrade || $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) !== $wpdb->snippets ) {
|
82 |
-
create_code_snippets_table( $wpdb->snippets );
|
83 |
-
}
|
84 |
-
}
|
85 |
-
|
86 |
-
/**
|
87 |
-
* Create a single snippet table
|
88 |
-
*
|
89 |
-
* @since 1.6
|
90 |
-
* @uses dbDelta() to apply the SQL code
|
91 |
-
* @param string $table_name The name of the table to create
|
92 |
-
*/
|
93 |
-
function create_code_snippets_table( $table_name ) {
|
94 |
-
global $wpdb;
|
95 |
-
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
|
96 |
-
|
97 |
-
/* Set the database charset */
|
98 |
-
$charset_collate = '';
|
99 |
-
|
100 |
-
if ( ! empty( $wpdb->charset ) ) {
|
101 |
-
$charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
|
102 |
-
}
|
103 |
-
|
104 |
-
if ( ! empty( $wpdb->collate ) ) {
|
105 |
-
$charset_collate .= " COLLATE $wpdb->collate";
|
106 |
-
}
|
107 |
-
|
108 |
-
/* Create the database table */
|
109 |
-
$sql = "CREATE TABLE $table_name (
|
110 |
-
id bigint(20) NOT NULL AUTO_INCREMENT,
|
111 |
-
name tinytext NOT NULL default '',
|
112 |
-
description text NOT NULL default '',
|
113 |
-
code longtext NOT NULL default '',
|
114 |
-
tags longtext NOT NULL default '',
|
115 |
-
scope tinyint(1) NOT NULL default 0,
|
116 |
-
active tinyint(1) NOT NULL default 0,
|
117 |
-
PRIMARY KEY (id)
|
118 |
-
) $charset_collate;";
|
119 |
-
|
120 |
-
dbDelta( $sql );
|
121 |
-
do_action( 'code_snippets/create_table', $table_name );
|
122 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
php/editor.php
CHANGED
@@ -46,7 +46,7 @@ function code_snippets_get_editor_atts( $override_atts, $json_encode ) {
|
|
46 |
* @uses wp_enqueue_script() to add the scripts to the queue
|
47 |
*/
|
48 |
function code_snippets_enqueue_codemirror() {
|
49 |
-
$codemirror_version = '5.
|
50 |
$url = plugin_dir_url( CODE_SNIPPETS_FILE );
|
51 |
|
52 |
/* Remove other CodeMirror styles */
|
46 |
* @uses wp_enqueue_script() to add the scripts to the queue
|
47 |
*/
|
48 |
function code_snippets_enqueue_codemirror() {
|
49 |
+
$codemirror_version = '5.10.0';
|
50 |
$url = plugin_dir_url( CODE_SNIPPETS_FILE );
|
51 |
|
52 |
/* Remove other CodeMirror styles */
|
php/functions.php
CHANGED
@@ -1,72 +1,75 @@
|
|
1 |
<?php
|
2 |
|
3 |
-
/**
|
4 |
-
* This file holds general-use non-admin-specific functions
|
5 |
-
* @package Code_Snippets
|
6 |
-
*/
|
7 |
-
|
8 |
/**
|
9 |
* Fetch the admin menu slug for a snippets menu
|
|
|
10 |
* @param string $menu The menu to retrieve the slug for
|
11 |
* @return string The menu's slug
|
12 |
*/
|
13 |
function code_snippets_get_menu_slug( $menu = '' ) {
|
14 |
-
|
15 |
-
$edit = array( 'edit', 'edit-snippet' );
|
16 |
-
$import = array( 'import', 'import-snippets' );
|
17 |
-
$settings = array( 'settings', 'snippets-settings' );
|
18 |
-
|
19 |
-
if ( in_array( $menu, $edit ) ) {
|
20 |
-
return 'edit-snippet';
|
21 |
-
} elseif ( in_array( $menu, $add ) ) {
|
22 |
-
return 'add-snippet';
|
23 |
-
} elseif ( in_array( $menu, $import ) ) {
|
24 |
-
return 'import-snippets';
|
25 |
-
} elseif ( in_array( $menu, $settings ) ) {
|
26 |
-
return 'snippets-settings';
|
27 |
-
} else {
|
28 |
-
return 'snippets';
|
29 |
-
}
|
30 |
}
|
31 |
|
32 |
/**
|
33 |
* Fetch the URL to a snippets admin menu
|
|
|
|
|
34 |
* @param string $menu The menu to retrieve the URL to
|
35 |
* @param string $context The URL scheme to use
|
36 |
-
*
|
|
|
37 |
*/
|
38 |
function code_snippets_get_menu_url( $menu = '', $context = 'self' ) {
|
39 |
-
|
40 |
-
$url = 'admin.php?page=' . $slug;
|
41 |
-
|
42 |
-
if ( 'network' === $context ) {
|
43 |
-
return network_admin_url( $url );
|
44 |
-
} elseif ( 'admin' === $context ) {
|
45 |
-
return admin_url( $url );
|
46 |
-
} else {
|
47 |
-
return self_admin_url( $url );
|
48 |
-
}
|
49 |
}
|
50 |
|
51 |
/**
|
52 |
* Fetch the admin menu hook for a snippets menu
|
53 |
-
* @
|
54 |
-
* @
|
|
|
55 |
*/
|
56 |
function code_snippets_get_menu_hook( $menu = '' ) {
|
57 |
-
|
58 |
-
return get_plugin_page_hookname( $slug, 'snippets' );
|
59 |
}
|
60 |
|
61 |
/**
|
62 |
* Fetch the admin menu slug for a snippets menu
|
63 |
-
*
|
64 |
-
* @
|
65 |
-
*
|
|
|
|
|
|
|
|
|
66 |
*/
|
67 |
function get_snippet_edit_url( $snippet_id, $context = 'self' ) {
|
68 |
-
return
|
69 |
-
|
70 |
-
|
71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
<?php
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
/**
|
4 |
* Fetch the admin menu slug for a snippets menu
|
5 |
+
* @deprecated Use code_snippets()->get_menu_slug() instead
|
6 |
* @param string $menu The menu to retrieve the slug for
|
7 |
* @return string The menu's slug
|
8 |
*/
|
9 |
function code_snippets_get_menu_slug( $menu = '' ) {
|
10 |
+
return code_snippets()->get_menu_slug( $menu );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
}
|
12 |
|
13 |
/**
|
14 |
* Fetch the URL to a snippets admin menu
|
15 |
+
* @deprecated Use code_snippets()->get_menu_url() instead
|
16 |
+
*
|
17 |
* @param string $menu The menu to retrieve the URL to
|
18 |
* @param string $context The URL scheme to use
|
19 |
+
*
|
20 |
+
* @return string The menu's URL
|
21 |
*/
|
22 |
function code_snippets_get_menu_url( $menu = '', $context = 'self' ) {
|
23 |
+
return code_snippets()->get_menu_url( $menu, $context );
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
|
26 |
/**
|
27 |
* Fetch the admin menu hook for a snippets menu
|
28 |
+
* @deprecated Use code_snippets()->get_menu_hook() instead
|
29 |
+
* @param string $menu The menu to retrieve the hook for
|
30 |
+
* @return string The menu's hook
|
31 |
*/
|
32 |
function code_snippets_get_menu_hook( $menu = '' ) {
|
33 |
+
return code_snippets()->get_menu_hook( $menu );
|
|
|
34 |
}
|
35 |
|
36 |
/**
|
37 |
* Fetch the admin menu slug for a snippets menu
|
38 |
+
*
|
39 |
+
* @deprecated Use code_snippets()->get_snippet_edit_url() instead
|
40 |
+
*
|
41 |
+
* @param int $snippet_id The snippet
|
42 |
+
* @param string $context The URL scheme to use
|
43 |
+
*
|
44 |
+
* @return string The URL to the edit snippet page for that snippet
|
45 |
*/
|
46 |
function get_snippet_edit_url( $snippet_id, $context = 'self' ) {
|
47 |
+
return code_snippets()->get_snippet_edit_url( $snippet_id, $context );
|
48 |
+
}
|
49 |
+
|
50 |
+
/**
|
51 |
+
* Get the required capability to perform a certain action on snippets.
|
52 |
+
* Does not check if the user has this capability or not.
|
53 |
+
*
|
54 |
+
* If multisite, checks if *Enable Administration Menus: Snippets* is active
|
55 |
+
* under the *Settings > Network Settings* network admin menu
|
56 |
+
*
|
57 |
+
* @deprecated Use code_snippets()->get_cap() instead
|
58 |
+
* @since 2.0
|
59 |
+
* @return string The capability required to manage snippets
|
60 |
+
*/
|
61 |
+
function get_snippets_cap() {
|
62 |
+
return code_snippets()->get_cap();
|
63 |
}
|
64 |
+
|
65 |
+
/**
|
66 |
+
* Return the appropriate snippet table name
|
67 |
+
*
|
68 |
+
* @deprecated Use code_snippets()->db->get_table_name() instead
|
69 |
+
* @since 2.0
|
70 |
+
* @param string|bool|null $multisite Retrieve the multisite table name or the site table name?
|
71 |
+
* @return string The snippet table name
|
72 |
+
*/
|
73 |
+
function get_snippets_table_name( $multisite = null ) {
|
74 |
+
return code_snippets()->db->get_table_name( $multisite );
|
75 |
+
}
|
php/settings/editor-preview.php
CHANGED
@@ -15,7 +15,7 @@
|
|
15 |
function code_snippets_editor_settings_preview_assets( $hook ) {
|
16 |
|
17 |
/* Only load on the settings page */
|
18 |
-
if (
|
19 |
return;
|
20 |
}
|
21 |
|
15 |
function code_snippets_editor_settings_preview_assets( $hook ) {
|
16 |
|
17 |
/* Only load on the settings page */
|
18 |
+
if ( code_snippets()->get_menu_hook( 'settings' ) !== $hook ) {
|
19 |
return;
|
20 |
}
|
21 |
|
php/settings/settings-fields.php
CHANGED
@@ -65,6 +65,12 @@ function code_snippets_get_settings_fields() {
|
|
65 |
'label' => __( 'Show snippet descriptions on admin pages' ),
|
66 |
'default' => true,
|
67 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
);
|
69 |
|
70 |
/* Description Editor settings section */
|
65 |
'label' => __( 'Show snippet descriptions on admin pages' ),
|
66 |
'default' => true,
|
67 |
),
|
68 |
+
'disable_prism' => array(
|
69 |
+
'name' => __( 'Disable shortcode syntax highlighter', 'code-snippets' ),
|
70 |
+
'type' => 'checkbox',
|
71 |
+
'label' => __( 'Disable the syntax highlighting for the [code_snippet] shortcode on the front-end', 'code-snippets' ),
|
72 |
+
'default' => false,
|
73 |
+
),
|
74 |
);
|
75 |
|
76 |
/* Description Editor settings section */
|
php/snippet-ops.php
CHANGED
@@ -409,10 +409,6 @@ function execute_active_snippets() {
|
|
409 |
/** @var wpdb $wpdb */
|
410 |
global $wpdb;
|
411 |
|
412 |
-
if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
|
413 |
-
set_snippet_table_vars();
|
414 |
-
}
|
415 |
-
|
416 |
$current_scope = is_admin() ? 1 : 2;
|
417 |
|
418 |
/* Check if the snippets tables exist */
|
409 |
/** @var wpdb $wpdb */
|
410 |
global $wpdb;
|
411 |
|
|
|
|
|
|
|
|
|
412 |
$current_scope = is_admin() ? 1 : 2;
|
413 |
|
414 |
/* Check if the snippets tables exist */
|
php/upgrade.php
CHANGED
@@ -30,7 +30,7 @@ function code_snippets_upgrader() {
|
|
30 |
if ( version_compare( $prev_version, CODE_SNIPPETS_VERSION, '<' ) ) {
|
31 |
|
32 |
/* Upgrade the database tables */
|
33 |
-
|
34 |
|
35 |
/* Update the plugin version stored in the database */
|
36 |
update_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
|
30 |
if ( version_compare( $prev_version, CODE_SNIPPETS_VERSION, '<' ) ) {
|
31 |
|
32 |
/* Upgrade the database tables */
|
33 |
+
code_snippets()->db->create_tables( true );
|
34 |
|
35 |
/* Update the plugin version stored in the database */
|
36 |
update_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
|
php/views/edit.php
CHANGED
@@ -14,8 +14,8 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|
14 |
|
15 |
global $pagenow;
|
16 |
|
17 |
-
$table =
|
18 |
-
$edit_id =
|
19 |
$snippet = get_snippet( $edit_id );
|
20 |
|
21 |
?>
|
@@ -46,7 +46,7 @@ $snippet = get_snippet( $edit_id );
|
|
46 |
<div id="titlediv">
|
47 |
<div id="titlewrap">
|
48 |
<label for="title" style="display: none;"><?php _e( 'Name (short title)', 'code-snippets' ); ?></label>
|
49 |
-
<input id="title" type="text" autocomplete="off" name="snippet_name" value="<?php echo $snippet->name; ?>" placeholder="<?php _e( 'Name (short title)', 'code-snippets' ); ?>" />
|
50 |
</div>
|
51 |
</div>
|
52 |
|
14 |
|
15 |
global $pagenow;
|
16 |
|
17 |
+
$table = code_snippets()->db->get_table_name();
|
18 |
+
$edit_id = code_snippets()->get_menu_slug( 'edit' ) === $_REQUEST['page'] ? absint( $_REQUEST['id'] ) : 0;
|
19 |
$snippet = get_snippet( $edit_id );
|
20 |
|
21 |
?>
|
46 |
<div id="titlediv">
|
47 |
<div id="titlewrap">
|
48 |
<label for="title" style="display: none;"><?php _e( 'Name (short title)', 'code-snippets' ); ?></label>
|
49 |
+
<input id="title" type="text" autocomplete="off" name="snippet_name" value="<?php echo esc_attr( $snippet->name ); ?>" placeholder="<?php _e( 'Name (short title)', 'code-snippets' ); ?>" />
|
50 |
</div>
|
51 |
</div>
|
52 |
|
readme.txt
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
=== Code Snippets ===
|
2 |
Contributors: bungeshea
|
3 |
-
Donate link:
|
4 |
Tags: code-snippets, snippets, code, php, network, multisite
|
5 |
Requires at least: 3.6
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 2.
|
8 |
License: MIT
|
9 |
License URI: license.txt
|
10 |
|
@@ -116,6 +116,22 @@ That's fantastic! Fork the [repository on GitHub](http://github.com/sheabunge/co
|
|
116 |
|
117 |
== Changelog ==
|
118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
= 2.4.2 =
|
120 |
* Added query variable to activate safe mode
|
121 |
* Fixed settings not saving
|
@@ -375,6 +391,12 @@ __Fixed__
|
|
375 |
|
376 |
== Upgrade Notice ==
|
377 |
|
|
|
|
|
|
|
|
|
|
|
|
|
378 |
= 2.4.1 =
|
379 |
Fixed CodeMirror themes not being detected on settings page
|
380 |
|
1 |
=== Code Snippets ===
|
2 |
Contributors: bungeshea
|
3 |
+
Donate link: https://bungeshea.com/donate/
|
4 |
Tags: code-snippets, snippets, code, php, network, multisite
|
5 |
Requires at least: 3.6
|
6 |
+
Tested up to: 4.4
|
7 |
+
Stable tag: 2.6.0
|
8 |
License: MIT
|
9 |
License URI: license.txt
|
10 |
|
116 |
|
117 |
== Changelog ==
|
118 |
|
119 |
+
= 2.6.0 =
|
120 |
+
* Reconfigured plugin to use classloader and converted a lot of functional code into OOP code
|
121 |
+
* Updated CodeMirror to version 5.10.0
|
122 |
+
* Added `[code_snippets]` shortcode for embedding snippet code in a post
|
123 |
+
* Fixed broken snippet search feature [[#](https://wordpress.org/support/topic/search-is-not-working-6)]
|
124 |
+
* Added front-end syntax highlighting for shortcode using [PrismJS](http://prismjs.com)
|
125 |
+
|
126 |
+
= 2.5.1 =
|
127 |
+
* Fixed: Ensure errors are fatal before catching them during error checking
|
128 |
+
* Fixed: Escape the snippet name on the edit page to ensure it displays correctly
|
129 |
+
* Fixed: Exclude snippets with named functions from error checking so they do not run twice
|
130 |
+
|
131 |
+
= 2.5.0 =
|
132 |
+
* Added: Detect parse and fatal errors in code when saving a snippet, and display a user-friendly message
|
133 |
+
* Fixed: Updated access of some methods in Code_Snippets_List_Table class to match updated WP_List_Table class
|
134 |
+
|
135 |
= 2.4.2 =
|
136 |
* Added query variable to activate safe mode
|
137 |
* Fixed settings not saving
|
391 |
|
392 |
== Upgrade Notice ==
|
393 |
|
394 |
+
= 2.5.1 =
|
395 |
+
Prevent Don't Panic message from being triggered accidentally
|
396 |
+
|
397 |
+
= 2.5.0 =
|
398 |
+
Now detects errors in snippet code when saving
|
399 |
+
|
400 |
= 2.4.1 =
|
401 |
Fixed CodeMirror themes not being detected on settings page
|
402 |
|