WordPress.org

Ready to get started?Download WordPress

Forums

WordPress HTTPS (SSL)
[Plugin: WordPress HTTPS] Disable temporarily for specific page (7 posts)

  1. ururk
    Member
    Posted 2 years ago #

    Is there a simple way - in functions.php - to say:

    if (condition met) {
    $forceSSL = false;
    }

    ?

    I've been trying to figure out a way to programmatically disable or enable the plugin without touching the plugin code, and am having some difficulty... but I don't want it disabled for the entire site, just specific pages based on specific criteria.

    $forceSSL = get_post_meta($post->ID, 'force_ssl', true);
    				if ( !$this->is_ssl() && $forceSSL ) {
    					$this->redirect('https');
    				} else if ( get_option('wordpress-https_exclusive_https') == 1 && !$forceSSL ) {
    					$this->redirect('http');
    				}

    There is no filter available for post meta content, therefore, I cannot change it based on specific parameters (which would be defined in functions.php).

  2. Mvied
    Member
    Plugin Author

    Posted 2 years ago #

    Hey ururk,

    Not that I can think of. However, I really like the idea of being able to override the plugin's functionality programmatically. Off the top of my head, I'm not sure how I'd go about doing that, but I'll definitely put some thought into it. If I can figure it out soon, I'll get it into the next version.

    Thanks,
    Mike

  3. Mvied
    Member
    Plugin Author

    Posted 2 years ago #

    Hey ururk,

    The next version will feature a filter called 'force_ssl' that you will be able to hook into to programmatically force a page to HTTP or HTTPS based on whatever criteria you want.

    Thanks,
    Mike

  4. Mvied
    Member
    Plugin Author

    Posted 2 years ago #

    Basically, beneath this line:
    $force_ssl = get_post_meta($post->ID, 'force_ssl', true);

    I've added:
    $force_ssl = apply_filters( 'force_ssl', $post->ID, $force_ssl );

    Here is a simple example on how you could use the filter.

    function custom_force_ssl( $post_id, $force_ssl ) {
    	if ( $post_id == 5 ) {
    		return true
    	}
    	return $force_ssl;
    }
    add_filter('force_ssl' , 'custom_force_ssl', 10, 2);

    Returning true in the filter forces the page to SSL, returning false will force it to HTTP.

    Thanks,
    Mike

  5. ururk
    Member
    Posted 2 years ago #

    Thanks!

    I ended up hacking the plugin, but this is great news, as I can move my 'customization' to the theme.

    (BTW - this is a great plugin overall!)

  6. Mvied
    Member
    Plugin Author

    Posted 2 years ago #

    Hey ururk,

    Yep, that's why I posted the change. I figured you could get your code in place and when you update to the next version, it'll keep working.

    Thanks!

    Mike

  7. Mvied
    Member
    Plugin Author

    Posted 2 years ago #

    Hey ururk,

    I had to change it up slightly since I created the filter incorrectly.
    $force_ssl = apply_filters( 'force_ssl', $force_ssl, $post->ID );

    function custom_force_ssl( $force_ssl, $post_id ) {
    	if ( $post_id == 5 ) {
    		return true
    	}
    	return $force_ssl;
    }
    add_filter('force_ssl' , 'custom_force_ssl', 10, 2);

    Thanks,
    Mike

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic