<tr class="secret_key_v2_invisible" style="display: none;"><th scope="row"><label for="loginpress_setting[secret_key_v2_invisible]">Secret Key</label></th><td><input type="text" class="regular-text" id="loginpress_setting[secret_key_v2_invisible]" name="loginpress_setting[secret_key_v2_invisible]" value=""><p class="description">Get <a href="https://www.google.com/recaptcha/admin" target="_blank"> reCaptcha</a> secret key. <br> <span class="alert-note">Make sure you are adding right secret key for this domain. If it's incorrect may be you'r not able to access your website.</span></p></td></tr>
毕竟现在右侧有文章分类、随机文章、热门文章三个模块。系统化整理文章、提高可发现性性上已经足够了。
在 SEO 优化上文章归档页固然归可以帮助搜索引擎更好地抓取和索引博客内容,不过在已经有 xml 站点地图的时候,文章归档页对于提供博客的 SEO 优化上作用不大,相较这种 html 格式站点地图,xml 格式的站点地图对搜索引擎会更加友好一些。
对象属性现在可以其 get 和 set 操作中关联相关的附加逻辑。根据用法,这可能会也可能不会使属性变为虚拟属性,即该属性根本没有实际的存储值。
<?php
class Person
{
// “虚拟”属性,可能无法明确设置。
public string $fullName {
get => $this->firstName . ' ' . $this->lastName;
}
// 所有的写入操作都会经过这个挂钩,结果就是写入的内容。
// 读取访问正常。
public string $firstName {
set => ucfirst(strtolower($value));
}
// 所有的写入操作都会经过这个挂钩,它必须写入支持值本身。
// 读取访问正常。
public string $lastName {
set {
if (strlen($value) < 2) {
throw new \InvalidArgumentException('Too short');
}
$this->lastName = $value;
}
}
}
$p = new Person();
$p->firstName = 'peter';
print $p->firstName; // 打印“Peter”
$p->lastName = 'Peterson';
print $p->fullName; // 打印“Peter Peterson”
不对称属性可见性
现在可以将对象属性的 set 可见性和 get 可见性分开控制。
<?php
class Example
{
// 第一个可见性修饰符控制 get 可见性,第二个修饰符控制 set 可见性。
// The get-visibility must not be narrower than set-visibility.
public protected(set) string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
class PhpVersion
{
#[\Deprecated(
message: "use PhpVersion::getVersion() instead",
since: "8.4",
)]
public function getPhpVersion(): string
{
return $this->getVersion();
}
public function getVersion(): string
{
return '8.4';
}
}
$phpVersion = new PhpVersion();
// Deprecated: Method PhpVersion::getPhpVersion() is deprecated since 8.4, use PhpVersion::getVersion() instead
echo $phpVersion->getPhpVersion();
新的 ext-dom 功能和 HTML5 支持
新的 DOM API 包括符合标准的支持,用于解析 HTML5 文档,修复了 DOM 功能行为中的几个长期存在的规范性错误,并添加了几个函数,使处理文档更加方便。
新的 DOM API 可以在 Dom 命名空间中使用。使用新的 DOM API 可以使用 Dom\HTMLDocument 和 Dom\XMLDocument 类创建文档。
$dom = Dom\HTMLDocument::createFromString(
<<<HTML
<main>
<article>PHP 8.4 is a feature-rich release!</article>
<article class="featured">PHP 8.4 adds new DOM classes that are spec-compliant, keeping the old ones for compatibility.</article>
</main>
HTML,
LIBXML_NOERROR,
);
$node = $dom->querySelector('main > article:last-child');
var_dump($node->classList->contains("featured")); // bool(true)
function email_friends( $post_ID )
{
$friends = 'bob@example.org, susie@example.org';
wp_mail( $friends, "sally's blog updated", 'I just put something on my blog: http://blog.example.com' );
return $post_ID;
}
add_action( 'publish_post', 'email_friends' );
function echo_comment_id( $comment_id )
{
echo 'Comment ID ' . $comment_id . ' could not be found';
}
add_action( 'comment_id_not_found', 'echo_comment_id', 10, 1 );
class MyPluginClass
{
public function __construct()
{
//add your actions to the constructor!
add_action( 'save_post', array( $this, 'myplugin_save_posts' ) );
}
public function myplugin_save_posts()
{
//do stuff here...
}