get_shortcode_page_id( 'terms-conditions' ); // Determine whether the document should be regenerated from the wizard data or read from the saved post. $sync_status = COMPLIANZ_TC::$document->syncStatus( $page_id ); if ( 'sync' === $sync_status ) { // Document is in sync: generate fresh HTML from the wizard-configured document. $html = COMPLIANZ_TC::$document->get_document_html( 'terms-conditions' ); } else { // Document is not in sync: fall back to the saved WordPress post content. $tc_post = get_post( $page_id ); if ( $tc_post ) { // Run the post content through the_content filter to apply shortcodes and formatting. $html = apply_filters( 'the_content', $tc_post->post_content ); } else { // No post found; use a placeholder so the PDF is not empty. $html = '--'; } } // Translate the document title for use as the PDF filename and header. $tc_title = __( 'Terms and Conditions', 'complianz-terms-conditions' ); // Stream the PDF to the browser and terminate; no further output should follow. COMPLIANZ_TC::$document->generate_pdf( $html, $tc_title ); exit; /** * Locates the WordPress installation root directory by traversing the filesystem. * * Walks up the directory tree from the current file's location, looking for a * `wp-config.php` file that signals the WordPress root. Handles edge cases where * WordPress core files are installed in a subdirectory of the config directory * (e.g. a `/wordpress/` sub-folder install). Also short-circuits for Bitnami * server images where WordPress is always at a fixed path. * * The resolved path is used to bootstrap WordPress before ABSPATH is available, * so it must work without any WordPress functions. * * @since 1.0.0 * * @return string|false Absolute path to the WordPress root directory (no trailing * slash), or false if it could not be located. */ function find_wordpress_base_path() { // Bitnami server images keep WordPress at a fixed location; detect and short-circuit. if ( file_exists( '/opt/bitnami/wordpress/wp-load.php' ) && file_exists( '/bitnami/wordpress/wp-config.php' ) ) { return '/opt/bitnami/wordpress'; } $path = __DIR__; // Walk up the directory tree looking for wp-config.php. do { $prev_path = $path; if ( file_exists( $path . '/wp-config.php' ) ) { // wp-load.php at the same level means this is the standard WordPress root. if ( file_exists( $path . '/wp-load.php' ) ) { return $path; } elseif ( file_exists( $path ) ) { // wp-config.php found but wp-load.php is absent here: WordPress core may // live in a subdirectory. Scan each direct child directory for wp-load.php. $handle = opendir( $path ); if ( false !== $handle ) { while ( false !== ( $file = readdir( $handle ) ) ) { // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Standard directory-traversal idiom. // Skip the current (.) and parent (..) directory entries. if ( '.' !== $file && '..' !== $file ) { $file = $path . '/' . $file; // If this child directory contains wp-load.php it is the WP root. if ( is_dir( $file ) && file_exists( $file . '/wp-load.php' ) ) { $path = $file; break; } } } closedir( $handle ); } } return $path; } } while ( ( $path = realpath( "$path/.." ) ) && $path !== $prev_path ); // phpcs:ignore Generic.CodeAnalysis.AssignmentInCondition.FoundInWhileCondition -- Standard filesystem-traversal do-while idiom; $prev_path guards against infinite loop at filesystem root. // Exhausted all parent directories without finding wp-config.php. return false; }