content = $content; $this->has_domdocument = class_exists( 'DOMDocument' ); if ( ! $this->has_domdocument || empty( $this->content ) ) { return; } $this->remove_script(); $this->parse_dom(); } /** * Parse the DOM content into XML and HTML DOMDocuments. * * @since 2.5.6 * * @return void */ private function parse_dom() { libxml_use_internal_errors( true ); $this->dom_xml = $this->get_dom_xml(); $this->dom_html = $this->get_dom_html(); libxml_clear_errors(); } /** * Callback to fire when ob_flush() is called. Allows us to ensure that our Hooks JS has been output on the page, * even in heavily-cached or concatenated environments. * * @since 2.5.6 * * @return string */ public function get_injected_html() { require_once \GFCommon::get_base_path() . '/form_display.php'; $has_printed = \GFFormDisplay::$hooks_js_printed; /** * Allow plugins to force the hook vars to output no matter what. Useful for certain edge-cases. * * @since 2.5.3 * * @param bool $force_output Whether to force the script output. * * @return bool */ $force_output = apply_filters( 'gform_force_hooks_js_output', false ); if ( ! $force_output && ! $has_printed ) { return $this->content; } if ( ! $this->should_inject_hooks_js() ) { return $this->content; } return $this->inject_hooks_js(); } /** * Returns the scripts to be removed from the content or the script tag for output. * * @since 2.9.19 * * @param bool $for_output Indicates if only script tag for output should be returned. * * @return string[]|string */ private function get_scripts( $for_output = false ) { static $scripts = array(); if ( empty( $scripts ) ) { $script = \GFCommon::get_hooks_javascript_code( false ); $scripts = array( \GFCommon::get_inline_script_tag( $script, false ), \wp_get_inline_script_tag( $script, array( 'id' => 'gform_gravityforms-js-before' ) ), $script, ); } return $for_output ? $scripts[0] : $scripts; } /** * Removes the hooks script from the content. * * @since 2.9.19 * * @return void */ private function remove_script() { // Fast path: exact match (works when the tag has not been modified). $modified = str_replace( $this->get_scripts(), '', $this->content ); if ( $modified !== $this->content ) { $this->content_modified = $modified; return; } // If the