• Resolved ralbusta

    (@ralbusta)


    Use this file to fix the broken update:

    <?php
    /**
    * This file includes functions for importing and exporting snippets
    */
    /**
    *
    * @access private
    *
    * @param $snippets
    * @param null $multisite
    * @param string $dup_action
    *
    * @return array
    */
    function _code_snippets_save_imported_snippets( $snippets, $multisite = null, $dup_action = ‘ignore’ ) {
    /* Get a list of existing snippet names keyed to their IDs */
    $existing_snippets = array();
    if ( ‘replace’ == $dup_action || ‘skip’ === $dup_action ) {
    $all_snippets = get_snippets( array(), $multisite );
    foreach ( $all_snippets as $snippet ) {
    if ( $snippet->name ) {
    $existing_snippets[ $snippet->name ] = $snippet->id;
    }
    }
    }
    /* Save a record of the snippets which were imported */
    $imported = array();
    /* Loop through the provided snippets */
    foreach ( $snippets as $snippet ) {
    /* Check if the snippet already exists */
    if ( ‘ignore’ !== $dup_action && isset( $existing_snippets[ $snippet->name ] ) ) {
    /* If so, either overwrite the existing ID, or skip this import */
    if ( ‘replace’ === $dup_action ) {
    $snippet->id = $existing_snippets[ $snippet->name ];
    } elseif ( ‘skip’ === $dup_action ) {
    continue;
    }
    }
    /* Save the snippet and increase the counter if successful */
    if ( $snippet_id = save_snippet( $snippet ) ) {
    $imported[] = $snippet_id;
    }
    }
    return $imported;
    }
    /**
    * Imports snippets from a JSON file
    *
    * @since 2.9.7
    *
    * @uses save_snippet() to add the snippets to the database
    *
    * @param string $file The path to the file to import
    * @param bool|null $multisite Import into network-wide table or site-wide table?
    * @param string $dup_action Action to take if duplicate snippets are detected. Can be ‘skip’, ‘ignore’, or ‘replace’
    *
    * @return array|bool An array of imported snippet IDs on success, false on failure
    */
    function import_snippets_json( $file, $multisite = null, $dup_action = ‘ignore’ ) {
    if ( ! file_exists( $file ) || ! is_file( $file ) ) {
    return false;
    }
    $raw_data = file_get_contents( $file );
    $data = json_decode( $raw_data, true );
    $snippets = array();
    /* Reformat the data into snippet objects */
    foreach ( $data[‘snippets’] as $snippet ) {
    $snippet = new Code_Snippet( $snippet );
    $snippet->network = $multisite;
    $snippets[] = $snippet;
    }
    $imported = _code_snippets_save_imported_snippets( $snippets, $multisite, $dup_action );
    do_action( ‘code_snippets/import/json’, $file, $multisite );
    return $imported;
    }
    /**
    * Imports snippets from an XML file
    *
    * @since 2.0
    *
    * @uses save_snippet() to add the snippets to the database
    *
    * @param string $file The path to the file to import
    * @param bool|null $multisite Import into network-wide table or site-wide table?
    * @param string $dup_action Action to take if duplicate snippets are detected. Can be ‘skip’, ‘ignore’, or ‘replace’
    *
    * @return array|bool An array of imported snippet IDs on success, false on failure
    */
    function import_snippets_xml( $file, $multisite = null, $dup_action = ‘ignore’ ) {
    if ( ! file_exists( $file ) || ! is_file( $file ) ) {
    return false;
    }
    $dom = new DOMDocument( ‘1.0’, get_bloginfo( ‘charset’ ) );
    $dom->load( $file );
    $snippets_xml = $dom->getElementsByTagName( ‘snippet’ );
    $fields = array( ‘name’, ‘description’, ‘desc’, ‘code’, ‘tags’, ‘scope’ );
    $snippets = array();
    /* Loop through all snippets */
    /** @var DOMElement $snippet_xml */
    foreach ( $snippets_xml as $snippet_xml ) {
    $snippet = new Code_Snippet();
    $snippet->network = $multisite;
    /* Build a snippet object by looping through the field names */
    foreach ( $fields as $field_name ) {
    /* Fetch the field element from the document */
    $field = $snippet_xml->getElementsByTagName( $field_name )->item( 0 );
    /* If the field element exists, add it to the snippet object */
    if ( isset( $field->nodeValue ) ) {
    $snippet->set_field( $field_name, $field->nodeValue );
    }
    }
    /* Get scope from attribute */
    $scope = $snippet_xml->getAttribute( ‘scope’ );
    if ( ! empty( $scope ) ) {
    $snippet->scope = $scope;
    }
    $snippets[] = $snippet;
    }
    $imported = _code_snippets_save_imported_snippets( $snippets, $dup_action, $multisite );
    do_action( ‘code_snippets/import/xml’, $file, $multisite );
    return $imported;
    }
    /**
    * Set up the current page to act like a downloadable file instead of being shown in the browser
    *
    * @param string $format
    * @param array $ids
    * @param string $table_name
    * @param string $mime_type
    *
    * @return array
    */
    function code_snippets_prepare_export( $format, $ids, $table_name = ”, $mime_type = ” ) {
    global $wpdb;
    /* Fetch the snippets from the database */
    if ( ” === $table_name ) {
    $table_name = code_snippets()->db->get_table_name();
    }
    if ( count( $ids ) ) {
    $sql = sprintf(
    ‘SELECT * FROM %s WHERE id IN (%s)’, $table_name,
    implode( ‘,’, array_fill( 0, count( $ids ), ‘%d’ ) )
    );
    $snippets = $wpdb->get_results( $wpdb->prepare( $sql, $ids ), ARRAY_A );
    } else {
    $snippets = array();
    }
    /* Build the export filename */
    if ( 1 == count( $ids ) ) {
    /* If there is only snippet to export, use its name instead of the site name */
    $first_snippet = new Code_Snippet( $snippets[0] );
    $title = strtolower( $first_snippet->name );
    } else {
    /* Otherwise, use the site name as set in Settings > General */
    $title = strtolower( get_bloginfo( ‘name’ ) );
    }
    $filename = “{$title}.code-snippets.{$format}”;
    $filename = apply_filters( ‘code_snippets/export/filename’, $filename, $title );
    /* Set HTTP headers */
    header( ‘Content-Disposition: attachment; filename=’ . sanitize_file_name( $filename ) );
    if ( ” !== $mime_type ) {
    header( “Content-Type: $mime_type; charset=” . get_bloginfo( ‘charset’ ) );
    }
    /* Return the retrieved snippets to build the rest of the export file */
    return $snippets;
    }
    /**
    * Export snippets to a downloadable PHP file
    *
    * @param $ids
    * @param $table_name
    */
    function download_snippets( $ids, $table_name = ” ) {
    $snippets = code_snippets_prepare_export( ‘php’, $ids, $table_name );
    echo “<?php\n”;
    /* Loop through the snippets */
    foreach ( $snippets as $snippet ) {
    $snippet = new Code_Snippet( $snippet );
    echo “\n/**\n * {$snippet->name}\n”;
    if ( ! empty( $snippet->desc ) ) {
    /* Convert description to PhpDoc */
    $desc = strip_tags( str_replace( “\n”, “\n * “, $snippet->desc ) );
    echo ” *\n * $desc\n”;
    }
    echo ” */\n{$snippet->code}\n”;
    }
    exit;
    }
    /**
    * Export snippets in JSON format
    *
    * @param array $ids list of snippet IDs to export
    * @param string $table_name name of the database table to fetch snippets from
    */
    function export_snippets( $ids, $table_name = ” ) {
    $raw_snippets = code_snippets_prepare_export( ‘json’, $ids, $table_name, ‘application/json’ );
    $final_snippets = array();
    foreach ( $raw_snippets as $snippet ) {
    $snippet = new Code_Snippet( $snippet );
    $fields = array( ‘name’, ‘desc’, ‘tags’, ‘scope’, ‘code’ );
    $final_snippet = array();
    foreach ( $fields as $field ) {
    if ( ! empty( $snippet->$field ) ) {
    $final_snippet[ $field ] = $snippet->$field;
    }
    }
    if ( $final_snippet ) {
    $final_snippets[] = $final_snippet;
    }
    }
    $data = array(
    ‘generator’ => ‘Code Snippets v’ . CODE_SNIPPETS_VERSION,
    ‘date_created’ => date( ‘Y-m-d H:i’ ),
    ‘snippets’ => $final_snippets,
    );
    echo wp_json_encode( $data, apply_filters( ‘code_snippets/export/json_encode_options’, 0 ) );
    exit;
    }

    Save as import-export.php in the php folder of code-snippets plugin. They forgot to add the file to the update

    Don’t Copy/Paste as this is causing problems for some. Use download link in my other post.

    • This topic was modified 6 years, 9 months ago by ralbusta.
Viewing 15 replies - 16 through 30 (of 40 total)
  • I think the easiest solution for most people is to login to the hosting account, navigate to wp-content> plugins folder, and rename the plugin folder from code-snippets to something else, like code-snippets-old. The site will now be accessible. Then re-install the last stable version (2.10.0).

    You can get a copy of the older version here: https://www.ads-software.com/plugins/code-snippets/advanced/ (at the bottom of the page).

    I had to do this for a dozen websites this morning. I’ll wait for the developer to push an update that fixes this.

    anonymized-14293447

    (@anonymized-14293447)

    “the plugin cannot be activated because it generates a fatal error”.

    I cannot even disable other plugins… it’s just a series of warnings FUCK THAT IDIOT in AUSTRALIA !

    Similar to many others, this crashed my site after the latest (Feb 10, 2018) update. It’s about 710am in Tasmania right now, so I imagine they will see these issues shortly and hopefully issue a fix quickly. Thanks.

    (@arsenalemusica) – Just do what I and (@aumw-jay) have suggested – rename the code-snippets folder.

    Thread Starter ralbusta

    (@ralbusta)

    Renaming the folder is what I did initially, but you lose all your snippets functionality. So I went looking for a better solution. You can also add a empty file called import-export.php in the php folder as well.

    Okay, applied this fix and the plugin is working. ??

    I just updated a few sites by uploading the missing file (cPanel File Manager) and I can confirm it works perfectly.

    Commenting out the offending line worked for me ??

    Line 60 – original:

    require_once $includes_path . '/import-export.php';

    Line 60 – commented out:

    //require_once $includes_path . '/import-export.php';

    • This reply was modified 6 years, 9 months ago by snifflevalve.
    Plugin Author Shea Bunge

    (@bungeshea)

    Hello everyone,

    I am really sorry that this has happened and it’s been so long without a fix. I did test the new version thoroughly before releasing it, but unfortunately there was a hitch in the release process and not all of the plugin files were uploaded correctly.

    I have reuploaded the missing file and bumped the version number, so redownloading or updating the plugin should fix this issue. I am really sorry that this has happened, and many thanks to @ralbusta for providing a fix.

    Thank you, Shea.

    OK, that seems to be working now, thanks.

    • This reply was modified 6 years, 9 months ago by EdFoC.

    Thanks a lot, Shea.

    No need to feel panic.

    Here’s how I fixed it, without touching a single line code.

    1. I renamed plugin name by checking with SFTP to code-snippets-old
    2. Access Dashboard, plugin would be deactivated
    3. Rename back
    4. Use a plugin called WP Rollback to switch to previous version. (I am not affiliated with this plugin, I found it helpful, Big Thanks to its Developer)
    5. Using WP Rollback you can switch to previous version
    6. Click on Activate.

    Enjoy! As you receive update that broken issue has been fixed; you can update to the most latest version.

    I hope this helps.
    Thanks

    Sincerely,
    Gulshan

    As I understand it, WP Rollback only rolls back plugins that are on www.ads-software.com. Since I have a fair few that are not, it would be a very incomplete solution for me.

    I rolled back using Beyond Compare (not affiliated, but a paying customer for 13 years). I get it to mirror the web server file structure locally with sftp, before updating. And if something goes wrong, I get it to sync back that folder. And it just worked. No need even to activate.

    (@thegulshankumar) Good of you to suggest your solution, but it is all fixed now…

Viewing 15 replies - 16 through 30 (of 40 total)
  • The topic ‘Fix new update’ is closed to new replies.