Contact Form 7
CF7 / Really Simple Captha and HTTPS/SSL (2 posts)

  1. theZedt
    Posted 1 year ago #

    I noticed that using Contact Form 7 with a Really Simple Captcha on the form placed on a SSL page attempts to load the image from a http:// only URL, triggering unsafe content notices in some browsers.

    This can be easily improved by editing the wpcf7_upload_dir() function in cf7/includes/functions.php to take SSL into account:

    function wpcf7_upload_dir( $type = false ) {
    	$uploads = wp_upload_dir();
    	$uploads = apply_filters( 'wpcf7_upload_dir', array(
    		'dir' => $uploads['basedir'],
    		'url' => $uploads['baseurl'] ) );
         // SSL mod
         if (is_ssl()):
             $uploads['url'] = str_replace("http://","https://",$uploads['url']);
         // end SSL mod
    	if ( 'dir' == $type )
    		return $uploads['dir'];
    	if ( 'url' == $type )
    		return $uploads['url'];
    	return $uploads;

    I'm sure this can be done better or safer, but this worked for me.


  2. jblakely
    Posted 1 year ago #

    Here is a different method that worked for me. See the following post for the source of this solution.


    Essentially, I edited wp-includes/default-constants.php and changed the wp_plugin_directory_constants function as follows:

    function wp_plugin_directory_constants( ) {
            if ( !defined('WP_CONTENT_URL') )
                    define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content'); // full url - WP_CONTENT_DIR is defined further up
            if ( !defined('WP_CONTENT_URL') )
                    define( 'WP_CONTENT_URL', site_url( 'wp-content') ); // full url - WP_CONTENT_DIR is define with https or http per connection

    Hopefully this will be helpful to others.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Contact Form 7
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic