0

I'm making a plugin which generate a form in a custom post. For security, I would like to avise the administrator with a notice if this specific post does not work with HTTPS/SSL yet.

I know the function is_ssl() but it is to check the current page, not a specific post by the ID.

Someone has got an idea ?

0

You could get all posts/pages, check if the shortcode for your plugin is used, and if so retrieve the permalink for that post/page.

Other than that, I don't know of any reliable method. And while I think your intentions are good, this does not really belong in your plugin, it isn't really your job to educate people.

0

I found this solution :

In my Admin object

add_action( 'admin_notices', array( $this, 'display_warning_no_ssl') );

function display_warning_no_ssl() {

    $forms = foo_get_form_pages();

    foreach ( $forms as $form ){
        $permalink = get_post_permalink( $form['ID'] );
        $protocol = foo_get_protocol( $permalink );
        if($protocol !== "https"){
            ?>
            <div class="notice error is-dismissible" >
                <p><?php _e( 'Enabling the HTTPS protocol for the page : "'.$permalink.'" is not mandatory but strongly advised for security issues for your users.!', PLUGIN_DOMAIN ); ?></p>
            </div>
            <?php
        }
    }

} 

In my helpers.php

function foo_get_form_pages(){
    global $wpdb;
    $forms_query_string       = "SELECT * FROM {$wpdb->prefix}posts WHERE post_type='foo'";
    $forms = $wpdb->get_results( $forms_query_string, ARRAY_A );
    $f_forms = array();
    foreach ( $forms as $key => $val ){
        $f_forms[$val['post_name']] = $val; 
    }
    return $f_forms; 
}

function foo_get_protocol( $url ){
    $a_url = explode("://", $url);
    return $a_url[0];
}  

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.