• Resolved Stilian

    (@stilians)


    Hi,

    I get the following PHP error every time I update a plugin (not from WordPress repository) using your plugin:
    PHP Warning: php_uname() has been disabled for security reasons in /var/www/wptbox/wp-admin/includes/class-pclzip.php on line 5677

    Also, this error is reported hundreds of times on each update! I have to scroll all the way down to click the “Activate” button.

    Here’s the section of the file’s referenced line:

    // --------------------------------------------------------------------------------
    
      // --------------------------------------------------------------------------------
      // Function : PclZipUtilTranslateWinPath()
      // Description :
      //   Translate windows path by replacing '\' by '/' and optionally removing
      //   drive letter.
      // Parameters :
      //   $p_path : path to translate.
      //   $p_remove_disk_letter : true | false
      // Return Values :
      //   The path translated.
      // --------------------------------------------------------------------------------
      function PclZipUtilTranslateWinPath($p_path, $p_remove_disk_letter=true)
      {
        if (stristr(php_uname(), 'windows')) {
          // ----- Look for potential disk letter
          if (($p_remove_disk_letter) && (($v_position = strpos($p_path, ':')) != false)) {
              $p_path = substr($p_path, $v_position+1);
          }
          // ----- Change potential windows directory separator
          if ((strpos($p_path, '\\') > 0) || (substr($p_path, 0,1) == '\\')) {
              $p_path = strtr($p_path, '\\', '/');
          }
        }
        return $p_path;
      }
      // --------------------------------------------------------------------------------

    Do you know why this happens? It’s quite annoying, could you do something about it?

    Thanks.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Chris Jean

    (@chrisjean)

    The warning occurs because the site’s hosting config disabled the php_uname function. Some hosting companies do this for various reasons. (Typically because it’s thought to improve security. I disagree that disabling the function does anything to improve security, but I digress.)

    Unfortunately, there isn’t anything I can change in the plugin to fix the problem. You would get the same warnings if this plugin was deactivated and you installed a new plugin on the site. The problem would remain because all the unzipping is done using code in WordPress and not from this plugin.

    You have the following options:

    1. Disable WP_DEBUG mode on the site so that warnings do not render in the page output.
    2. Have your host install the PHP ZipArchive library. This is typically listed as the php-zip library in operating system package managers. WordPress only uses the PclZip library if ZipArchive isn’t present. So, having ZipArchive present would bypass the issue. I wouldn’t expect the host to do this, but it is an option. I should note that most quality hosts provide this library.
    3. Have your host enable use of the php_uname function. As with #2, I wouldn’t expect the host to do this and most quality hosts do not disable this function.
    4. Change hosts.
    • This reply was modified 5 years, 4 months ago by Chris Jean.
    • This reply was modified 5 years, 4 months ago by Chris Jean.
    Thread Starter Stilian

    (@stilians)

    Hi, thanks for your detailed answer!

    I contacted my host’s support and they confirmed that they have php-zip enabled. They suggested that maybe some specific setting should be turned on (in your plugin?) for using php-zip library instead of PclZip library.

    Is that an option?

    Plugin Author Chris Jean

    (@chrisjean)

    All the unzipping logic is from WordPress and not the plugin, so there isn’t anything that I can control from the plugin. The logic in WP is fairly simple:

    /**
     * Filters whether to use ZipArchive to unzip archives.
     *
     * @since 3.0.0
     *
     * @param bool $ziparchive Whether to use ZipArchive. Default true.
     */
    if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
        $result = _unzip_file_ziparchive( $file, $to, $needed_dirs );
        if ( true === $result ) {
            return $result;
        } elseif ( is_wp_error( $result ) ) {
            if ( 'incompatible_archive' != $result->get_error_code() ) {
                return $result;
            }
        }
    }
    // Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
    return _unzip_file_pclzip( $file, $to, $needed_dirs );

    Given the logic and how PclZip is being used, the possible explanations are:

    1. The ZipArchive class is not present which would indicate that the php-zip library is not installed or properly configured.
    2. Something is disabling ZipArchive using the unzip_file_use_ziparchive filter. This plugin does not touch that filter. If this filter is the cause, it would be from a different plugin, the theme, or some other config such as an mu-plugin.
    3. The ZipArchive class is having problems unzipping archives. In the event that ZipArchive is available and not disabled by the filter, PclZip will be tried if unzipping using ZipArchive failed with an error code other than incompatible_archive. The code doesn’t log or display the specific error, so if this is happening, someone with access to the system would have to debug the code to find out what the error is. Perhaps with those specific error details, the problem with ZipArchive could be found and corrected.
    • This reply was modified 5 years, 4 months ago by Chris Jean.
    Thread Starter Stilian

    (@stilians)

    I contacted my host again, and the issue is indeed on their end. They said that the function is disabled on the server for security reasons. So there’s nothing I can do.

    Thank you Chris for responding with such professionalism and knowledge. I hope you’re rewarded for your work as much as you deserve.

    Cheers!

    Plugin Author Chris Jean

    (@chrisjean)

    Glad to help. Sorry to hear that your host disables so much functionality. I find that a bad sign when looking at a host, but that’s just me editorializing.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘PHP Warnings on every update’ is closed to new replies.