| @@ -1662,4 +1662,93 @@ | ||
| 1662 | 1662 | return $output; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | endif; |
| 1666 | + | |
| 1667 | +/** | |
| 1668 | + * Maybe reset opcache after Imagify update. | |
| 1669 | + * | |
| 1670 | + * @since 1.7.1.2 | |
| 1671 | + * @since 2.0 | |
| 1672 | + * @author Grégory Viguier | |
| 1673 | + * | |
| 1674 | + * @param object $wp_upgrader Plugin_Upgrader instance. | |
| 1675 | + * @param array $hook_extra { | |
| 1676 | + * Array of bulk item update data. | |
| 1677 | + * | |
| 1678 | + * @type string $action Type of action. Default 'update'. | |
| 1679 | + * @type string $type Type of update process. Accepts 'plugin', 'theme', 'translation', or 'core'. | |
| 1680 | + * @type bool $bulk Whether the update process is a bulk update. Default true. | |
| 1681 | + * @type array $plugins Array of the basename paths of the plugins' main files. | |
| 1682 | + * } | |
| 1683 | + */ | |
| 1684 | +function imagify_maybe_reset_opcache( $wp_upgrader, $hook_extra ) { | |
| 1685 | + _deprecated_function( __FUNCTION__ . '()', '2.0' ); | |
| 1686 | + | |
| 1687 | + static $imagify_path; | |
| 1688 | + | |
| 1689 | + if ( ! isset( $hook_extra['action'], $hook_extra['type'], $hook_extra['plugins'] ) ) { | |
| 1690 | + return; | |
| 1691 | + } | |
| 1692 | + | |
| 1693 | + if ( 'update' !== $hook_extra['action'] || 'plugin' !== $hook_extra['type'] || ! is_array( $hook_extra['plugins'] ) ) { | |
| 1694 | + return; | |
| 1695 | + } | |
| 1696 | + | |
| 1697 | + $plugins = array_flip( $hook_extra['plugins'] ); | |
| 1698 | + | |
| 1699 | + if ( ! isset( $imagify_path ) ) { | |
| 1700 | + $imagify_path = plugin_basename( IMAGIFY_FILE ); | |
| 1701 | + } | |
| 1702 | + | |
| 1703 | + if ( ! isset( $plugins[ $imagify_path ] ) ) { | |
| 1704 | + return; | |
| 1705 | + } | |
| 1706 | + | |
| 1707 | + imagify_reset_opcache(); | |
| 1708 | +} | |
| 1709 | + | |
| 1710 | +/** | |
| 1711 | + * Reset PHP opcache. | |
| 1712 | + * | |
| 1713 | + * @since 1.8.1 | |
| 1714 | + * @since 1.9.9 Added $reset_function_cache parameter and return boolean. | |
| 1715 | + * @since 2.0 deprecated | |
| 1716 | + * @author Grégory Viguier | |
| 1717 | + * | |
| 1718 | + * @param bool $reset_function_cache Set to true to bypass the cache. | |
| 1719 | + * @return bool Return true if the opcode cache was reset (or reset in a previous call), or false if the opcode cache is disabled. | |
| 1720 | + */ | |
| 1721 | +function imagify_reset_opcache( $reset_function_cache = false ) { | |
| 1722 | + _deprecated_function( __FUNCTION__ . '()', '2.0' ); | |
| 1723 | + | |
| 1724 | + static $can_reset; | |
| 1725 | + | |
| 1726 | + if ( $reset_function_cache || ! isset( $can_reset ) ) { | |
| 1727 | + if ( ! function_exists( 'opcache_reset' ) ) { | |
| 1728 | + $can_reset = false; | |
| 1729 | + return false; | |
| 1730 | + } | |
| 1731 | + | |
| 1732 | + $opcache_enabled = filter_var( ini_get( 'opcache.enable' ), FILTER_VALIDATE_BOOLEAN ); // phpcs:ignore PHPCompatibility.IniDirectives.NewIniDirectives.opcache_enableFound | |
| 1733 | + | |
| 1734 | + if ( ! $opcache_enabled ) { | |
| 1735 | + $can_reset = false; | |
| 1736 | + return false; | |
| 1737 | + } | |
| 1738 | + | |
| 1739 | + $restrict_api = ini_get( 'opcache.restrict_api' ); // phpcs:ignore PHPCompatibility.IniDirectives.NewIniDirectives.opcache_restrict_apiFound | |
| 1740 | + | |
| 1741 | + if ( $restrict_api && strpos( __FILE__, $restrict_api ) !== 0 ) { | |
| 1742 | + $can_reset = false; | |
| 1743 | + return false; | |
| 1744 | + } | |
| 1745 | + | |
| 1746 | + $can_reset = true; | |
| 1747 | + } | |
| 1748 | + | |
| 1749 | + if ( ! $can_reset ) { | |
| 1750 | + return false; | |
| 1751 | + } | |
| 1752 | + | |
| 1753 | + return opcache_reset(); // phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.opcache_resetFound | |
| 1754 | +} | |