10, 'headers' => array( 'Content-Type' => 'application/json' ), 'body' => wp_json_encode( self::payload() ), ) ); $code = is_wp_error( $response ) ? 0 : (int) wp_remote_retrieve_response_code( $response ); if ( $code >= 200 && $code < 300 ) { update_option( self::SENT, $now, false ); return true; } return false; } /** * What is sent: counts and names of kinds only. * * @return array */ public static function payload() { $summary = Store::summary(); $rules = array(); foreach ( isset( $summary['rules'] ) ? (array) $summary['rules'] : array() as $rule ) { if ( isset( $rule['rule'] ) && preg_match( '/^[a-z0-9-]{2,60}$/', (string) $rule['rule'] ) ) { $rules[ $rule['rule'] ] = array( 'found' => (int) $rule['before'], 'left' => (int) $rule['after'], ); } } $fixes = array(); foreach ( Settings::fixes() as $id => $on ) { if ( $on ) { $fixes[] = $id; } } return array( 'id' => (string) get_option( self::ID ), 'version' => FIXLIGHT_VERSION, 'wp' => self::major_minor( get_bloginfo( 'version' ) ), 'php' => self::major_minor( PHP_VERSION ), 'theme' => strtolower( substr( (string) get_template(), 0, 60 ) ), 'builders' => self::builders(), 'woocommerce' => class_exists( 'WooCommerce' ), 'pages' => isset( $summary['pages'] ) ? (int) $summary['pages'] : 0, 'fixes_on' => $fixes, 'rules' => $rules, ); } /** * Page builders in use, by family. * * @return string[] */ public static function builders() { $template = strtolower( (string) get_template() ); $found = array(); if ( defined( 'ELEMENTOR_VERSION' ) ) { $found[] = 'elementor'; } if ( in_array( $template, array( 'divi', 'extra' ), true ) || defined( 'ET_BUILDER_PLUGIN_VERSION' ) ) { $found[] = 'divi'; } if ( class_exists( 'FLBuilder' ) ) { $found[] = 'beaver'; } if ( defined( 'WPB_VC_VERSION' ) ) { $found[] = 'wpbakery'; } if ( 'bricks' === $template ) { $found[] = 'bricks'; } if ( defined( 'CT_VERSION' ) ) { $found[] = 'oxygen'; } if ( defined( '__BREAKDANCE_VERSION' ) ) { $found[] = 'breakdance'; } if ( ! $found ) { $found[] = function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ? 'block-theme' : 'classic-theme'; } return $found; } /** * "7.1.3" → "7.1". * * @param string $version Version. * @return string */ private static function major_minor( $version ) { return preg_match( '/^(\d+)\.(\d+)/', (string) $version, $m ) ? $m[1] . '.' . $m[2] : ''; } }