Action Run


目录

表单提交时执行操作的实际方法。这是操作触发的主要方法。它可以使用来自自定义控件的可选数据,但这不是必需的。

Run 方法

触发操作的方法称为 run()。该方法仅在表单提交时执行。在你的操作类中,按如下方式使用该方法:

class Elementor_Test_Action extends \ElementorPro\Modules\Forms\Classes\Action_Base {

	public function run( $record, $ajax_handler ): void {

		// ...

	}

}

执行操作

开发者可以在表单提交时执行任何代码,可能性是无限的。让我们看一些例子。

发送电子邮件

在下面的例子中,我们将在每次表单提交时发送一封电子邮件:

class Elementor_Test_Action extends \ElementorPro\Modules\Forms\Classes\Action_Base {

	public function run( $record, $ajax_handler ): void {

		wp_mail( /* ... */ );

	}

}

发送 HTTP 请求

在下面的例子中,我们将在每次表单提交时发送一个 HTTP 请求:

class Elementor_Test_Action extends \ElementorPro\Modules\Forms\Classes\Action_Base {

	public function run( $record, $ajax_handler ): void {

		wp_remote_post( /* ... */ )

	}

}

创建 WordPress 文章/页面/自定义文章类型

另一个用例是在每次表单提交后创建 WordPress 自定义文章类型:

class Elementor_Test_Action extends \ElementorPro\Modules\Forms\Classes\Action_Base {

	public function run( $record, $ajax_handler ): void {

		wp_insert_post( /* ... */ );

	}

}

版本号 #2
由 壳壳虫 创建于 2026-03-26 17:08:44 UTC
由 壳壳虫 更新于 2026-03-26 17:08:44 UTC