我找到了这个解决方案:
在我的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
}
}
}
在我的
helpers.phpfunction 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];
}