samedi 21 mai 2016

WordPress - Changing Checkbox Text Based On A Post Or Page

I'm working on a WordPress plugin that limits the access of certain pages to users not currently logged in. On both the Posts and Pages page, once the plugin is activated, a checkbox appears that says Restrict This ___ (where ___ is either Post or Page). Below this is a small description that says This setting will apply to this ___ only (where ___ is either post or page). But for some reason the description always says This setting will apply to this page only regardless if you're editing a post or a page. Why is the first message displaying correctly, but the second one isn't? Thanks.

// ...
<?php
 function RestrictionBoxStatus ($post) {
  $PostID = $post -> ID;
  if ($post -> post_type == "page") {
   $TheIDs = get_opt ("pages");
  }
  else {
   $TheIDs = get_opt ("posts");
  }
  if (!is_array ($page_ids)) $page_ids = array ();
?>
<input name="pr" type="hidden" value="update">
<input type="checkbox" name="restriction-status"<?php if (in_array ($PostID, $TheIDs)) echo ' checked="checked"'; ?>>
Restrict This <?php echo $post -> post_type == "post" ? "Post" : "Page"; ?>
<p>This setting apply only to this <b><u>
<?php
  $post -> post_type == 'post' ? 'post' : 'page' . '</u></b> only.';
  _e($post);
?></p>
<?php
 }
 //..
?>




Aucun commentaire:

Enregistrer un commentaire