• Resolved webbere

    (@webbere)


    First, I absolutely LOVE this product, though i don’t use it as a plugin. Regardless, I have a “Brands” custom post type that asks for a URL for that specific company. The link in questions (https://patrickind.com/brands/sigma-wire-international/) does not connect correctly to their website because it automatically adds an “s” to the “http:” and this particular site does not need it. Here is my code for that field:

    // Brand Link
    
    	$cmb = new_cmb2_box( array(
    		'id'         => 'brand_metabox',
    
    		'title'      => __( 'Brand Link', 'cmb2' ),
    		'object_types'      => array( 'brands', ), // Post type
    
    		'context'    => 'normal',
    		'priority'   => 'high',
    
    		'show_names' => true, // Show field names on the left
    		// 'cmb_styles' => true, // Enqueue the CMB stylesheet on the frontend
    
    	) );
    		$cmb->add_field ( array(
    
    				'name' => __( 'Website URL', 'cmb2' ),
    'desc' => __( 'Enter the web address for this brand',
    
    'cmb2' ),
    				'id'   => $prefix . 'brand_link',
    
    				'type' => 'text_url',
    'protocols' => array( 'http', 'https'), // Array of
    allowed protocols
    		) );
    
    }

    I checked my functions file to make sure i didn’t add anything that WOULD force that “s” to appear but found nothing there.

    Is there a way to adjust this? Almost all other Brands do in-fact require the “s” to be there, but in this particular case it can’t be there. Whenever I manually remove the “s” from the text_url field and then update the page, the “s” reappears.

    I’m not sure how to correct that. Can you offer any suggestions?

    Please and thank you!

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter webbere

    (@webbere)

    this is how i’m calling it on the front end:

    <?php
    $texturl = get_post_meta( $post->ID, ‘_cmb_brand_link’, true );
    echo ‘<a class=”brand-link” target=”_blank” href=”‘;
    echo $texturl;
    echo ‘” alt=”‘;
    echo the_title();
    echo ‘”>’;
    echo ‘Visit ‘;
    echo the_title();
    echo ‘‘;
    ?>

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Not sure where exactly, but I’m curious if the HTTPS is being forced on somewhere in the sanitization process or escape process.

    Just as a temporary thing, not permanent, perhaps trying passing both of these in your add_field arguments, to see if the issue goes away.

    $cmb->add_field ( array(
    	'name' => __( 'Website URL', 'cmb2' ),
    	'desc' => __( 'Enter the web address for this brand', 'cmb2' ),
    	'id'   => $prefix . 'brand_link',
    	'type' => 'text_url',
    	'protocols' => array( 'http', 'https'), // Array of allowed protocols
    	'escape_cb' => false,
    	'sanitization_cb' => false,
    ) );
    

    If the issue goes away, remove one of them, and then re-check again as needed to get this URL without SSL. That should identify which is the culprit.

    Thread Starter webbere

    (@webbere)

    Hello there! Thank you for your response ??
    I added the two add_field parameters you suggested, cleared my browsing data and flushed the site cache, but i’m still seeing that darned “s” in the url.
    Do you perhaps have any other suggestions?

    I appreciate your time and help!

    THanks,
    Elise

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    I would need to dig in and try to recreate to really get to the bottom of this, admittedly, as I can’t recall any other details regarding this type of thing.

    Plugin Author Justin Sternberg

    (@jtsternberg)

    The text_url field has its value passed through esc_url_raw, which is likely the culprit (some plugin or your theme is probably filtering the results of that function to enforce https links).

    If you can’t debug the offending plugin, you can just switch that field to a regular text field, and it should work fine.

    
    $cmb->add_field ( array(
    	'name' => __( 'Website URL', 'cmb2' ),
    	'desc' => __( 'Enter the web address for this brand', 'cmb2' ),
    	'id'   => $prefix . 'brand_link',
    	'type' => 'text',
    ) );
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘text_url automatically adding “s” to “http:” when it shouldn’t’ is closed to new replies.