通过邮件检查Wordpress用户是否存在

DEM*_*DEM 3 php wordpress

对于我的一生,我无法让它工作(WP Codex 的默认示例)。我用这段代码创建了一个 php 文件并将其放入我的主题文件夹中,当我在网上访问该文件时,我得到一个空白页面,nada - 我是否遗漏了一些东西,我是否必须将其放在其他地方?任何帮助是极大的赞赏。

  <?php
  $email = 'myemail@example.com';
  $exists = email_exists($email);
  if ( $exists )
  echo "That E-mail is registered to user number " . $exists;
  else
  echo "That E-mail doesn't belong to any registered users on this site";
  ?>
Run Code Online (Sandbox Code Playgroud)

Ujj*_*wal 5

简单的答案,如果那是模板页面,那么使用这个:

<?php
  $email = 'myemail@example.com';
  $exists = email_exists($email);
  if ( $exists )
  echo "That E-mail is registered to user number ";
  else
  echo "That E-mail doesn't belong to any registered users on this site";
  ?>
Run Code Online (Sandbox Code Playgroud)

并确保您有正确的 php 开始和结束标签。

但如果来自模板页面以外的其他页面,则使用以下内容:

<?php
  require_once("../../../../wp-load.php");  //ADD THIS

  $email = 'myemail@example.com';
  $exists = email_exists($email);
  if ( $exists )
  echo "That E-mail is registered to user number ";
  else
  echo "That E-mail doesn't belong to any registered users on this site";
  ?>
Run Code Online (Sandbox Code Playgroud)

根据页面位置在 require_once("../../../../wp-load.php") 中添加或删除 ../ 。这肯定会对你有帮助。