Code Monkey home page Code Monkey logo

code-snippets's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

code-snippets's Issues

PHP fatal error

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:

require_once(): Failed opening required '/home/XXXXX/public_html/wp-content/plugins/code-snippets/php/import-export.php'

(include_path='.:/opt/alt/php70/usr/share/pear')

Type: PHP Fatal error Line: 60

File: /home/XXXXX/public_html/wp-content/plugins/code-snippets/php/class-code-snippets.php

Add brazilian portuguese translation

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

There's a Needle in my Error Log

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
code-snippet-error-log-github
...............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?

Add $result parameter to after_execute_snippet

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.

Integration with GitHub Gists

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.

Use Plugin as Library?

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.

code_snippets/before_execute_snippet filter

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?

json_encode( $atts, JSON_UNESCAPED_SLASHES ); not compatible with PHP 5.3.0

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 );   
        }       
    };

[Feature request] Support for CSS snippets

Please consider support for CSS snippets.

Use case

  • Easily turn snippets on/off to check where a problem might be.
  • Support for both PHP and CSS snippets wil eliminate the use for a child theme.
  • No worries about losing custom CSS when updating theme’s.
  • Using Export/Import, a lot of time will be saved on new projects.

I know you must have considered CSS support in the past

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’.

If you do consider doing this, count me in as a zealous beta tester!

Ps. Thank you so much for creating this @sheabunge ! It’s in all my projects by default.

Save command

Save the snippet with control + S or command+S

Snippet import Error

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.

Hook after snippet execution

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?

How can i integrate it with theme

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

Javascript error

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>

Bug with Screen Options

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.

Indonesian translation

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.

Add option to replace existing snippets when importing

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

Add different snippet types

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.

Snippets List Page Features

Add authors column

  • with the ability to deactivate with screen options
  • this would be especially helpful when collaborating with multiple developers

Add copy/clone feature

  • placed under each snippet title in list view
  • Deactivate | Export | Clone | Delete

Shared Snippets on multisite

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.

Bulk Import Feature

Having a feature of being able to bulk import multiple code snippets would be very useful.

Bug in Delete Script

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.

Originally posted here

Grouping sugestion

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)

[FEAT]: require other snippets

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.

Saving/Editing Enhancements

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.

Connexion reset while saving with echo "<script>"

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).

Insert snippets through shortcodes

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]

Snippet Priority Enhancement

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.

Missing argument 2 for wpdb::prepare()

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.

Originally posted here

ID Missing in filter code_snippets/allow_execute_snippet

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;
}

Request/suggestion: Please create a paid pro version

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:

  1. A customer pays you 19 a year or 59 for a lifetime account (just an example) without support OR 49 a year and 129 for lifetime including non-content related support.
  2. They receive a code that unlocks extra functionality (no extra pro plugin please). If this extra functionality could be support for CSS snippets, that would save installing yet another plugin and make CSS manageable for all site from one dashboard if they also use MainWP.
  3. You receive a lot of income, enough to keep developing this plugin and make room for other projects by hiring someone to do support (and so you not get bored doing just one thing).

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 ;-)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.