我有一个wordpress插件,允许我将人们发送到新的网址。而不是在同一页面上访问该URL并让用户离开我的网站。我想要一个新的窗口,当他们去网址时打开
如何编辑此代码以便打开新窗口?
<?php
/**
Plugin Name: [WPJB] Application URL
Version: 1.1
Author: Greg Winiarski
Description: Allows to set application URL on per job basis.
*/
// Plugin activation
register_activation_hook( __FILE__, 'wpjb_aurl_register');
function wpjb_aurl_register() {
// registers new custom field in wp_wpjb_meta table
wpjb_meta_register("job", "application_url");
}
// Plugin deactivation
register_deactivation_hook( __FILE__, 'wpjb_aurl_unregister');
function wpjb_aurl_unregister() {
// do nothing ...
}
// Adding custom fields to the form
add_filter("wpjb_form_init_job", "wpjb_aurl_init_job");
add_filter("wpja_form_init_job", "wpjb_aurl_init_job");
function wpjb_aurl_init_job($form) {
// adding new fields to the form
$e = $form->create("application_url", "text");
$e->setBuiltin(false);
$e->setLabel("Application URL");
$e->addFilter(new Daq_Filter_WP_Url);
$e->addValidator(new Daq_Validate_Url);
$e->setValue($form->getObject()->meta->application_url->value());
$form->addElement($e, "company");
return $form;
}
add_action("wpjb_front_pre_render", "wpjb_aurl_pre_render", 10, 2);
function wpjb_aurl_pre_render($app, $file) {
global $post_type;
try {
$c1 = is_wpjb() && wpjb_is_routed_to("index.single");
} catch(Exception $e) {
$c1 = false;
}
$c2 = $post_type == "job";
if(!$c1 && !$c2) {
return;
}
$job = $app->controller->view->job;
if(!$job->meta->application_url->value()) {
return;
}
$app->controller->view->application_url = $job->meta->application_url- >value();
}
?>
答案 0 :(得分:0)
你不能仅仅使用PHP
来完成它,但是你可以改为重定向到新的url echo javascript,它将在加载将在新窗口或标签中打开url的页面时触发。
使用类似
的内容Echo "<script> var win = window.open(".$job->meta->application_url->value().", '_blank'); win.focus();</script>";
在您的PHP脚本中可能位于您现在的位置
$app->controller->view->application_url = $job->meta->application_url->value();