'1' ) ); $settings = is_array( $settings ) ? $settings : array(); if ( (string) ( $settings['enabled'] ?? '1' ) !== '1' ) { return false; } /* * FRONTENDDISPLAYGATEFIX1 * The admin UI stores Homepage separately as include_homepage. * The frontend gate must honour that flag before blocking the render. * Free / expired states also fall back to a safe sitewide widget; the * renderer then limits the visible chips to the free fallback set. */ $mode = function_exists( 'matewa_get_mode' ) ? matewa_get_mode() : MATEWA_MODE_FREE; // FREE-SITEWIDE-GUARANTEE: // Once enabled, Free and Trial Expired always render sitewide. // Ignore any historical Pro page-targeting data that may still exist. if ( in_array( $mode, array( MATEWA_MODE_FREE, MATEWA_MODE_TRIAL_EXPIRED ), true ) ) { return true; } $display_mode = matewa_normalise_widget_display_mode( $settings['display_mode'] ?? 'all' ); $page_ids = matewa_normalise_widget_page_ids( $settings['page_ids'] ?? array() ); $include_homepage = ( (string) ( $settings['include_homepage'] ?? '0' ) === '1' ); $is_home_request = is_front_page() || is_home(); if ( 'homepage' === $display_mode ) { return $is_home_request; } if ( in_array( $display_mode, array( 'selected', 'excluded' ), true ) ) { $is_listed = false; if ( $is_home_request && $include_homepage ) { $is_listed = true; } $current_ids = array(); $current_id = absint( get_queried_object_id() ); if ( $current_id > 0 ) { $current_ids[] = $current_id; } if ( $is_home_request ) { $front_page_id = absint( get_option( 'page_on_front' ) ); $posts_page_id = absint( get_option( 'page_for_posts' ) ); if ( $front_page_id > 0 ) { $current_ids[] = $front_page_id; } if ( $posts_page_id > 0 ) { $current_ids[] = $posts_page_id; } } $current_ids = array_values( array_unique( array_filter( array_map( 'absint', $current_ids ) ) ) ); foreach ( $current_ids as $maybe_current_id ) { if ( in_array( $maybe_current_id, $page_ids, true ) ) { $is_listed = true; break; } } if ( ! $is_listed && ! empty( $page_ids ) && ! empty( $_SERVER['REQUEST_URI'] ) ) { $current_path = wp_parse_url( esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ), PHP_URL_PATH ); $current_path = '/' . ltrim( (string) $current_path, '/' ); $current_path = untrailingslashit( $current_path ); foreach ( $page_ids as $page_id ) { $page_url = get_permalink( $page_id ); $page_path = $page_url ? wp_parse_url( $page_url, PHP_URL_PATH ) : ''; $page_path = '/' . ltrim( (string) $page_path, '/' ); $page_path = untrailingslashit( $page_path ); if ( '' !== $page_path && $current_path === $page_path ) { $is_listed = true; break; } } } if ( 'selected' === $display_mode ) { return $is_listed; } return ! $is_listed; } return true; } } /* ====================================================================== FRONTEND LOAD ====================================================================== */ add_action( 'wp_enqueue_scripts', function () { if ( function_exists( 'matewa_should_render_widget' ) && ! matewa_should_render_widget() ) { return; } require_once MATEWA_PLUGIN_DIR . 'public/matewa-assets.php'; }, 20 );