codesnippetspro / code-snippets Goto Github PK
View Code? Open in Web Editor NEWCode Snippets WordPress Plugin
Home Page: https://codesnippets.pro
License: Other
Code Snippets WordPress Plugin
Home Page: https://codesnippets.pro
License: Other
I prefer to enter a piece of code as is and build php code as a plugin.
your plugin should assume it's a plain snippet.
There could be a flag to mark it as runnable code.
The latest Code Snippet plugin cannot be activated in WordPress v4.9.4. My entire WordPress site was down after the plugin update with HTTP error 500. I had to deactivate all my plugins and reactivate one by one to trace which plugin was giving the problem.
Error as follow:
Hi, I've decided to help your project writing the translation for pt_BR (Brazilian Portuguese) my main language, I really hope that can help
Any problem, please let me know #60
I found this in my error_log, but..............
PHP Warning: strpos(): Empty needle in /home/pressily/public_html/wp-content/plugins/code-snippets/php/snippet-ops.php(383) : eval()'d code on line 8
...............I'm not seeing what the problem might be. Don't get me wrong, it could totally be something "else" in my stack here, but after a bit of php Googling, I'm still not able to diagnose if this is really a 'bug' worthy of Git, or something that ought to go over on .org/
Any ideas what could be throwing this error?
Hi, congrats on releasing the new version. I think is necessary to add the $result
parameter to the after_execute_snippet
hook, if you add the $result
parameter the developer will know if the snippet failed execution. if you check PHP documentation for eval it says that it return false when the evaluation fails.
Very cool, I just found this and I started to hack up an idea where it can get a list of Gists (by user or starred) and then fetch the Gist snippet.
I was wondering if this would be a good idea to integrate into this plugin or if you're interested.
I really love this plugin - thank you very much for your excellent work!!!
As I have lots of code snippets flying around, and would also like to publish some of them, is it possible to use a shortcode for rendering code as text in a blog entry?
And additionally it would be great to store snippets from multiple languages - these shouldn't be executed of course, but this way I can save all of my snippets in one convenient place. I know this may be out of scope of the plugin, but it would be awesome!! Maybe just adding a language dropdown menu just before the code editor is enough - and if the language is not PHP, then it's not possible to activate the snippet at all.
https://wordpress.org/support/topic/suggestion-scope?replies=2
Allow user to change the height of the description and code editors.
Move Settings (Scope) under title
Also, you could abbreviate:
Everywhere | Back-end Only | Front-end Only
https://wordpress.org/support/topic/suggestion-scope?replies=2
Implement a drop-down menu with options for snippet scope on edit snippet page.
is_admin()
! is_admin()
I implemented a must use plugin that allows me to recover from coding errors or disable plugins or the current theme for testing purposes, to do this i defined various options that are controlled by a parameter in the $_GET variable, one of them is an option to disable code snippets by defining CODE_SNIPPETS_SAFE_MODE as true, i was thinking to maybe extend this to disable a single snippet this way.
I suggest you add a filter that could allow to change the code before it is executed, this implementation requires that you also read the snippet id from the db, this filter would open the door to write code where i could check the snippet id and maybe return and empty string to not allow the snippet to execute depending of the situation.
foreach ( $active_snippets as $snippet_id => $snippet_code ) {
/* Execute the PHP code */
execute_snippet( apply_filters( 'code_snippets/before_execute_snippet', '', $snippet_code, $snippet_id ) );
}
Now that i write down this idea, i don´t now if this filter could be a security problem, another approach would be to make the filter a switch, instead of changing the snippet code, the filter could return true/false to allow the snippet to execute.
foreach ( $active_snippets as $snippet_id => $snippet_code ) {
/* Execute the PHP code */
if ( apply_filters( 'code_snippets/allow_execute_snippet', '', true, $snippet_id ) === true )
execute_snippet( $snippet_code );
}
What do you think?
The snippets currently sort by date/time of entry in the Manage Snippets screen.
It would be great if they sorted alphabetically as an option.
As seen in this support thread:
http://wordpress.org/support/topic/icon-disappears-with-mp6?replies=6
The icon has disappeared from the admin menu due to pointing to the wrong directory for the image file:
https://github.com/bungeshea/code-snippets/blob/develop/includes/class-admin.php#L176
Code Snippets Version 2.0-dev
GitHub >> code-snippets/blob/2.0/includes/editor.php
in line 27 >> ERROR with PHP 5.3.0
$atts = json_encode( $atts, JSON_UNESCAPED_SLASHES )
this not compatible with PHP version < 5.4.0
temporary I have adopted this solution
if ( $json_encode ) {
if (version_compare(phpversion(), '5.4.0', '<')) {
$atts = json_encode( $atts );
}else{
$atts = json_encode( $atts, JSON_UNESCAPED_SLASHES );
}
};
After saving the code, the editor cursor will continue on the same line.
I just copied a snippet from this page http://www.laplacef.com/how-to-defer-parsing-javascript-in-wordpress/ and i got a 501 server error every time i try to save the snippet, after testing i found that the bellow line causes the problem, it appears that the ! besides the parenthesis is the culprit. I know that line can be simplified but i thought you would like to know about this issue.
if (!(is_admin() )) {
Please consider support for CSS snippets.
I see more people asking for this. I hope the time has come to reconsider. I’ll gladly pay a reasonable yearly fee for a pro version that has this built in. Especially when the CSS is also checked for error and/or has a ‘clean-up-function’.
Ps. Thank you so much for creating this @sheabunge ! It’s in all my projects by default.
"Enter a list of tags; separated by commas" to add to localizeables.
Thank you Shea!
It would be great if we can save a snippet and insert it execute it in any post by using a shortcode.
Save the snippet with control + S or command+S
I just created an export file from the site i have my snippets to import them to a new site, when i click the "Upload file and import button" all i get is a new browser page with the url http://array/, both sites have wp 4.2.2 and the latest code-snippets version installed. I deactivated all the plugins but code-snippet before the import to discard any conflict. I tried importing a snippet file that i exported with the previous version and still the same problem.
There are certain snippets that should only run once like transients clean up, permalink structure reset or database handling, i suggest to add an action named code_snippets/after_execute_snippet allowing the developer to do any stuff he/she likes after the snippet executes, this way for example i could just write my own code to disable the snippet, bellow is a suggestion for the hook implementation, btw i noticed that you return the snippet eval result in execute_snippet() so i added it to the hook too.
foreach ( $active_snippets as $snippet_id => $snippet ) {
if ( apply_filters( 'code_snippets/allow_execute_snippet', true, $snippet_id ) ) {
/* Execute the PHP code */
$result = execute_snippet( $snippet->code );
do_action( 'code_snippets/after_execute_snippet', $result, $snippet_id );
}
}
One last note: semantically i think it sounds better 'allow_snippet_execute' and 'after_snippet_execute', i am not completely sure since English is not my primary language.
What do you think?
i am a wp theme writer in china and i like your plugin very much .how can i integrate in my own theme . in a theme some functions may be must and some may be recommend how i can use it looking for your reply thanks
I use a multisite. and it happen each time i try to save a code snippet in any of the sub sites.
cc @sheabunge
Since your last update i am receiving the following javascript error:
Uncaught TypeError: jQuery(...).resizable is not a function
This is the link that reports the error:
http://site.dev/wp-admin/admin.php?page=edit-snippet&id=<script id>
There a bug here.
It should be:
function set_screen_option( $status, $option, $value ) {
if ( 'snippets_per_page' === $option ) {
return $value;
}
return $status;
}
By not returning $status
other plugins that hook into set-screen-option will have its $value
set to null.
Sorry for previous translator but everything is wrong with that translation.
So I redo them all and upload them on Code Snippets's WordPress.org localization page (development trunk). I'm not familiar with git, maybe @sheabunge can help merge them.
Thanks for the plugin btw, it's super usefull.
See: https://wordpress.org/support/topic/display-snippet-on-front-end
Implement a short code to display a snippet on the front end.
[code_snippet id="44"]
Possibly also a TinyMCE button to browse the available snippets and insert the shortcode.
When I edit code I cannot see ~4-6 characters on the left hand side.
The line numbering column seems to hide it.
Wordpress 4.7 Multisite Subdomain
No strings in the mentioned file are localizeable by .po.
Probably, some bug is there.
Add a radio option when importing snippets to "replace existing snippets, where the names of snippets are compared and the saved version is updated/deleted if there is match, or ignore existing snippets, which functions as it does now.
See #32
In order to make this plugin more useful in different situations, I would like to implement support for CSS code snippets, and HTML snippets that can be inserted into posts through a visual editor button.
I suggest having three tabs on the edit snippet page: Functions, Styles, and Content. Functions are the executable PHP code snippets, styles are CSS snippets that will be concatenated into a stylesheet and linked either on the admin area or the front-end, and Content will be HTML (PHP?) snippets that are designed for inserting into posts. On each tab should be a short description of what the type does.
Each tab could also include type-specific settings. For example, the scope selector for function snippets, a similar one for CSS snippets, perhaps a shortcode identifier for content snippets.
Add authors column
Add copy/clone feature
It says preform instead of perform in this sentence: https://github.com/sheabunge/code-snippets/blob/develop/languages/code-snippets.pot#L291
Instead of needing to individually edit a snippet to mark it as shared across a multisite network, there should be a bulk option for this on the manage snippets page.
An enhancement for this plugin would be to add a shared flag field to the edit snippet screen when editing a snippet in the network admin area, then a single site would see it's own snippets plus the shared snippets, this way a network admin could write snippets to be used by all sites in a multisite setup, only network admins would be allowed to edit shared snippets.
Having a feature of being able to bulk import multiple code snippets would be very useful.
I wanted to send a quick note on a bug i discovered in the Delete Files script when uninstalling the plugin.
Line 1333
$wpdb->query( "DROP TABLE IF EXISTS $code_snippets->table" );
this causes private class access failure.
Should be:
$wpdb->query( "DROP TABLE IF EXISTS $code_snippets_table" );
this new code tested out correctly. although i am not running Multi-site, the same change may need to be added to line 1329.
Thanks for the awesome plugin.
Kudos for the snippet scope enhancement. May i suggest to add an "Admin" and "Front End" grouping to the Manage Snippets screen to easily detect witch snippets are admin only or front end only? The grouping should be: All (n) Active (n) Inactive (n) Admin (n) Front End (n)
A nice feature addition would be the ability to categorize snippets.
Originally posted here: http://bit.ly/U3acCF
Assume I'm adding a class as a snippet, or a function in a snippet and I'd like to use it again - it could be handy to have it available in other snippets.
I would love an option in settings to disable the full-height editor. And disable the description and tags fields (I don't use them).
I'd also love it if you used Ajax to save and put a SAVE button above the editor. That way the page doesn't reload each time I save.
Hi,
I'm facing an issue really annoying. I have to put some code line like this :
echo '<script type="text/javascript" src="'.site_url().'/edissyum/script.js"></script>';
But everytime there is a line like this, I have this error (on Firefox). Without those type of code, mixing echo and <script>, the snippet is saved.
Any idea ?
We have already check the firewall, we have the whole rights, Apache doesn't throw an error (under Debian 8).
I think it would be very useful if we could insert snippets at specific places through shortcodes.
One way to do the UI would be to add a fourth option to the "Reach" section when editing a snippet, after "Execute on all sites", "Execute on admin section" and "Execute on frontend". The fourth option would read "Execute through a shortcode" and when selected, would generate a shortcode like so:
[code-snippet id=123]
An enhancement for this plugin would be to add a priority field to the edit snippet screen and the db , then when the activation function runs it would get the plugins from the db adding a 'order by priority' to the query, this would implement a nice and easy way to control snippet execution order.
PHP warning on Manage Snippets page:
Warning: Missing argument 2 for wpdb::prepare(), called in /htdocs/wp-content/plugins/code-snippets/includes/class-list-table.php on line 286 and defined in /htdocs/wp-includes/wp-db.php on line 990
Andrew Nacin writes about the issue here.
Since the maximum length for the name/title is 36 characters, would it be possible to also display that column at 36 character width in the Manage Snippets screen?
This would prevent wrap on the title, making it easier to view many snippets http://screencast.com/t/pXWDvoEOt
It's a picky one I know… :)
There is a bug in the new filter code_snippets/allow_execute_snippet, i suggest the code bellow to correct the error. The safe mode code is working perfect with this filter, now whenever i make a mistake i append &safe_mode=2&sid=<snippet id>
to the url and it disables the snippet, as a suggestion later you could add an option to show a snippet id column.
Edit: I updated the code to add the enhancement suggested in issue # 37
function execute_active_snippets() {
/* Bail early if safe mode is active */
if ( defined( 'CODE_SNIPPETS_SAFE_MODE' ) && CODE_SNIPPETS_SAFE_MODE ) {
return false;
}
global $wpdb;
if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
set_snippet_table_vars();
}
/* Check if the snippets table exists */
if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
$sql = "SELECT id, code FROM {$wpdb->snippets} WHERE active=1";
}
/* Check if the multisite snippets table exists */
if ( is_multisite() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets ) {
$sql = ( isset( $sql ) ? $sql . "\nUNION ALL\n" : '' );
$sql .= "SELECT code FROM {$wpdb->ms_snippets} WHERE active=1";
}
if ( ! empty( $sql ) ) {
$sql .= sprintf( ' AND (scope=0 OR scope=%d)', is_admin() ? 1 : 2 );
/* Grab the active snippets from the database */
$active_snippets = $wpdb->get_results( $sql, OBJECT_K );
foreach ( $active_snippets as $snippet_id => $snippet ) {
if ( apply_filters( 'code_snippets/allow_snippet_execute', true, $snippet_id ) ) {
/* Execute the PHP code */
$result = execute_snippet( $snippet->code );
do_action( 'code_snippets/after_snippet_execute', $result, $snippet_id );
}
}
return true;
}
/* If we're made it this far without returning true, assume failure */
return false;
}
Hi @sheabunge ,
Even since we started using the Code Snippets Extension from MainWP, all our sites have become dependent on your plugin to function properly. We love it, but we also worry that one day you may lose interest and stop supporting it.
So allow me to paint a (probably unrealistic) ideal picture:
Indeed, this is around the time I woke up fro the dream above. Do not take it all literally, but please consider a paid version to ensure continuity.
Cheers and thanks again for making my dev-life easier ;-)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.