Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 39
0.00% covered (danger)
0.00%
0 / 8
CRAP
n/a
0 / 0
wpcomsh_hotfix_cherry_core_base_url
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
wpcomsh_woocommerce_download_file_xsendfile_x_accel_redirect_file_path
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
wpcomsh_pre_transient_jetpack_akismet_key_is_valid
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
wpcomsh_disallow_fb_for_woo_full_batch_api_sync
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
wpcomsh_patch_auto_update_spinner_style
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
12
create_function
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
get_magic_quotes_gpc
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
wpcomsh_remove_elementor_dev_notice
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2/**
3 * Hotfix file.
4 *
5 * @package wpcomsh
6 */
7
8/**
9 * Cherry Framework makes incorrect assumptions about ABSPATH and wp-content location.
10 *
11 * @see https://github.com/CherryFramework/cherry-framework/issues/178
12 *
13 * @param string $url URL.
14 * @return string
15 */
16function wpcomsh_hotfix_cherry_core_base_url( $url ) {
17    return str_replace( WP_CONTENT_DIR, '/wp-content/', $url );
18}
19add_filter( 'cherry_core_base_url', 'wpcomsh_hotfix_cherry_core_base_url' );
20
21/**
22 * On Atomic v2 we require the path within the webroot to be the one passed to X-Accel-Redirect
23 *
24 * @param string $xsendfile_path File path.
25 * @return string
26 */
27function wpcomsh_woocommerce_download_file_xsendfile_x_accel_redirect_file_path( $xsendfile_path ) {
28    if ( 0 === strpos( $xsendfile_path, 'srv/htdocs/' ) ) {
29        // 11 is the length of the string 'srv/htdocs/'.
30        $xsendfile_path = substr_replace( $xsendfile_path, '', 0, 11 );
31    }
32    return $xsendfile_path;
33}
34add_filter( 'woocommerce_download_file_xsendfile_x_accel_redirect_file_path', 'wpcomsh_woocommerce_download_file_xsendfile_x_accel_redirect_file_path' );
35
36/**
37 * We define a Akismet Key at the Platform Level which is always assumed to be valid so don't check it all the time.
38 *
39 * @see https://github.com/Automattic/jetpack/issues/12382
40 *
41 * @return string
42 */
43function wpcomsh_pre_transient_jetpack_akismet_key_is_valid() {
44    return 'valid';
45}
46add_filter( 'pre_transient_jetpack_akismet_key_is_valid', 'wpcomsh_pre_transient_jetpack_akismet_key_is_valid' );
47
48/**
49 * We disallow facebook-for-woocommerce full batch API sync because of large option DB churn.
50 *
51 * @see pcTzPI-6r-p2
52 * @see pcTzPI-64-p2
53 *
54 * @param bool $allow_full_sync Whether to allow full sync.
55 * @param int  $product_count   Amount of products.
56 *
57 * @return bool
58 */
59function wpcomsh_disallow_fb_for_woo_full_batch_api_sync( $allow_full_sync, $product_count ) {
60    // Disable only for sites with a large number of products.
61    $max_products_for_safe_full_sync = 5000;
62    if ( $product_count > $max_products_for_safe_full_sync ) {
63        return false;
64    }
65
66    return $allow_full_sync;
67}
68add_filter( 'facebook_for_woocommerce_allow_full_batch_api_sync', 'wpcomsh_disallow_fb_for_woo_full_batch_api_sync', 10, 2 );
69
70/**
71 * TODO: Remove this once Page Optimize stops breaking CSS load order (has any version after v0.5.1)
72 * This is a temporary fix for a page-optimize bug that causes spinner icons to show
73 * all the time in the plugins list auto-update column
74 *
75 * @see https://github.com/Automattic/wpcomsh/pull/699
76 */
77function wpcomsh_patch_auto_update_spinner_style() {
78    $current_screen = get_current_screen();
79    if ( isset( $current_screen->id ) && 'plugins' === $current_screen->id ) {
80        wp_add_inline_style(
81            'dashicons',
82            '.toggle-auto-update .dashicons.hidden { display: none; }'
83        );
84    }
85}
86add_action( 'admin_enqueue_scripts', 'wpcomsh_patch_auto_update_spinner_style', 999 );
87
88/**
89 * Polyfill the create_function function for PHP versions >= 8.0
90 * Code taken from https://github.com/php5friends/polyfill-create_function/blob/master/create_function.php
91 *
92 * Copying and distribution of this file, with or without modification,
93 * are permitted in any medium without royalty provided the copyright
94 * notice and this notice are preserved. This file is offered as-is,
95 * without any warranty.
96 */
97if ( ! function_exists( 'create_function' ) ) {
98    /**
99     * The create_function function.
100     *
101     * @param string $args The args.
102     * @param string $code The code.
103     *
104     * @return string The name of the function.
105     */
106    function create_function( $args, $code ) {
107        static $i = 0;
108
109        _deprecated_function( __FUNCTION__, 'trunk', 'anonymous functions' );
110
111        $namespace = 'wpcom_create_function';
112
113        do {
114            ++$i;
115            $name = "__{$namespace}_lambda_{$i}";
116        } while ( \function_exists( $name ) );
117
118        // phpcs:ignore Squiz.PHP.Eval.Discouraged, MediaWiki.Usage.ForbiddenFunctions.eval
119        eval( "function {$name}({$args}) { {$code} }" );
120
121        return $name;
122    }
123}
124
125/**
126 * Polyfill the get_magic_quotes_gpc() function for PHP versions >= 8.0.
127 */
128if ( ! function_exists( 'get_magic_quotes_gpc' ) ) {
129    /**
130     * The get_magic_quotes_gpc function.
131     *
132     * @suppress PhanRedefineFunctionInternal
133     * @return bool
134     */
135    function get_magic_quotes_gpc() {
136        _deprecated_function( __FUNCTION__, 'trunk' );
137
138        return false;
139    }
140}
141
142/**
143 * Use filter to remove the Elementor Developer Notice.
144 *
145 * Gutenberg is a default plugin installed on all WordPress.com sites,
146 * however, its presence triggers the beta install notice to appear even
147 * on production sites.
148 *
149 * @param array $notices The array of admin notices from Elementor.
150 * @return array Modified array without the Elementor Developer Notice.
151 */
152function wpcomsh_remove_elementor_dev_notice( $notices ) {
153    if ( is_array( $notices ) ) {
154        if ( class_exists( 'Elementor\Core\Admin\Notices\Elementor_Dev_Notice', false ) ) {
155            foreach ( $notices as $key => $notice ) {
156                if ( $notice instanceof Elementor\Core\Admin\Notices\Elementor_Dev_Notice ) { // @phan-suppress-current-line PhanUndeclaredClassInstanceof -- We've checked the class exists earlier.
157                    unset( $notices[ $key ] );
158                }
159            }
160        }
161    }
162
163    return $notices;
164}
165
166add_filter( 'elementor/core/admin/notices', 'wpcomsh_remove_elementor_dev_notice' );