我正在尝试从自定义字段中动态获取收件人电子邮件,并使用字符串替换来修改联系表单7收件人电子邮件。联系人表单正在发送,但似乎没有更改收件人电子邮件,因为我没有收到电子邮件。
<?php
function wpcf7_dynamic_email_field( $args ) {
$dynamic_email = '';
$submission = WPCF7_Submission::get_instance();
$unit_tag = $submission->get_meta( 'wpcf7-f3936-p3933-o1' );
// get the post ID from the unit tag
if ( $unit_tag && preg_match( '/^wpcf7-f(\d+)-p(\d+)-o(\d+)$/', $unit_tag, $matches ) ) {
$post_id = absint( $matches[2] );
$dynamic_email = get_post_meta( $post_id, 'email', true );
}
if ( $dynamic_email ) {
$args['recipient'] = str_replace('emailtoreplace@email.com', $dynamic_email, $args['recipient']);
}
return $args;
}
add_filter( 'wpcf7_mail_components', 'wpcf7_dynamic_email_field' );
?>
Run Code Online (Sandbox Code Playgroud)
我正在运行CF7 4.5.1和PHP 5.3,我在这里缺少什么吗?
我已经设置了 Devise,我已经在 user.rb 文件中设置了以下代码
def self.create_auto_password
generated_password = Devise.friendly_token.first(8)
self.create(password: generated_password, password_confirmation: generated_password)
end
Run Code Online (Sandbox Code Playgroud)
然后我尝试通过运行来生成注册控制器
rails generate devise:controllers -c registrations
以及其他一些变体,但它不会生成...在 Devise 中创建注册控制器的正确命令是什么?
有没有人用过 random_slug ( https://github.com/josei/random_slug ) 作为friendly_id?它上次更新是在 5 年前,所以我不确定尝试它是否浪费时间,或者即使有更好的解决方案?
基本上,我使用friendly_id 来获取我帖子的标题,并且我有一个范围,因此这些帖子对用户来说是唯一的,但我非常希望这些帖子是随机生成的 URL,类似于 YouTube URL 的 I假设 - 这是否可以通过友好的 ID 进行,或者我是否以错误的方式处理这个问题,还有其他什么可以让我的生活更轻松 100 倍吗?