Once a user submits the form, I am trying to grab the data in field 1, assign it to a variable and then in a different function I am trying to use that data.
The data is successfully going into the variable defined in the after_submission function as I was able to simply tell the site to break if a certain word was in the variable. It's now a matter of getting that same data from a different function.
add_action("gform_after_submission", "after_submission", 10, 1);
function after_submission($entry, $form){
$shopname = $entry["1"];
global $response;
$response = 'https://openapi.etsy.com/v2/shops/'. $shopname .'/listings/active?api_key=xxxxxxxxxxxxx )';
}
function dynamic_url(){
$apiurl = $response;
return $apiurl;
}
Redeclare the global variable in your second function:
add_action("gform_after_submission", "after_submission", 10, 1);
function after_submission($entry, $form){
$shopname = $entry["1"];
global $response;
$response = 'https://openapi.etsy.com/v2/shops/'. $shopname .'/listings/active?api_key=xxxxxxxxxxxxx )';
}
function dynamic_url(){
global $response;
$apiurl = $response;
return $apiurl;
}
Related
There are a bunch of example of using this woocommerce hook woocommerce_email_recipient_customer_completed_order. So I added it to functions.php, and concatenated a couple example recipients as a test, but only the purchaser receives an email. It doesn't seem like this filter is getting invoked since if I turn on debugging and error_log(...) there's nothing in the log file.
Is there a reason this isn't working? I tried bumping the priority up to 99, but that doesn't work either. The site uses all the defaults and doesn't override any of the templates.
add_filter( 'woocommerce_email_recipient_customer_completed_order', 'custom_woocommerce_add_email_recipient', 10, 2);
function custom_woocommerce_add_email_recipient($recipient, $order) {
$recipient = $recipient . ', foo#example.com, bar#example.com';
return $recipient;
}
As I learn more about Woocommerce it looks like this site only goes as far as processing so I had to use the customer_processing_order mail ID instead to get this to work (thanks to #LoicTheAztec for verifying the customer_completed_order hook works), and instead of using the woocommerce_email_recipient_customer_processing_order hook I used woocommerce_email_headers and checked the mail ID.
add_filter( 'woocommerce_email_headers', 'woocommerce_email_headers_add_recipient', 10, 3);
function woocommerce_email_headers_add_recipient($headers, $mail_id, $order) {
if($mail_id == 'customer_processing_order') {
$member = null;
$memberMail = null;
foreach($order->get_meta_data() as $item) {
if ($item->key === 'member_name') {
$member = $item->value;
$memberMail = $this->getMemberMail($member);
$headers .= "BCC: {$member} <{$member_mail}>\r\n";
break;
}
}
}
return $headers;
}
I'm trying to create some filters for a datalist. I'd like the user to be able to select one or multiple filters from a list of tags and then spit out a list of objects based on those filters. All is good using this code to grab data based on the URL params being sent...
public function index(SS_HTTPRequest $request)
{
// ...
if($tagsParam = $request->getVar('tags')) {
$articles = new ArrayList();
$tagids = explode(",", $tagsParam);
foreach($tagids AS $tagid) {
$tag = Category::get()->byID($tagid);
$articleitems = $tag->getManyManyComponents('Articles')->sort('Date DESC');
foreach($articleitems AS $articleitem) {
$articles->push($articleitem);
}
}
}
$data = array (
'Articles' => $articles
);
if($request->isAjax()) {
return $this->customise($data)->renderWith('ListItems');
}
return $data;
}
That code works fine with a URL like mysite.com/?tags=1,2,3
My issue comes with trying to generate that URL based on the filters built with a CheckboxSetField. Here is my code for that...
public function ArticlesSearchForm()
{
$tagsmap = $this->getTags()->map('ID', 'Title')->toArray();
$form = Form::create(
$this,
'ArticlesSearchForm',
FieldList::create(
CheckboxSetField::create('tags')
->setSource($tagsmap)
),
FieldList::create(
FormAction::create('doArticlesSearch','Search')
)
);
$form->setFormMethod('GET')
->setFormAction($this->Link())
->disableSecurityToken()
->loadDataFrom($this->request->getVars());
return $form;
}
When the user submits that form, the URL generated is something along the lines of mysite.com?tags%5B1%5D=1&tags%5B2%5D=2&action_doArticlesSearch=Search Obviously, it's passing the values as an array. How can I pass a simple comma separated list?
Rather than trying to change the return of CheckboxSetField, I'd recommend changing your code. Given you are converting the comma-separated list list into an array already here:
$tagids = explode(",", $tagsParam);
Something like this, will skip this step:
public function index(SS_HTTPRequest $request)
{
// ...
if($tagsParam = $request->getVar('tags')) {
$articles = new ArrayList();
//This has a minor risk of going bad if $tagsParam is neither an
//array of a comma-separated list
$tagids = is_array($tags) ? $tagsParam : explode(",", $tagsParam);
i would change the page title from a wordpress plugin site. the name comes from a function:
function subPage() {
$content = 'blabla';
$subPageTitle = 'Plugin Sub Page Dynamic';
return $content;
}
and the simple function for replace wp_title:
function wp_plugin_page_title($subPageTitle) {
$siteTitle = $subPageTitle;
return $siteTitle;
}
add_filter('wp_title', wp_plugin_page_title);
my problem is now: how i get the variable $subPageTitle in the function wp_plugin_page_title()?
Thanks a lot for ANY help!
EDIT: the code was not correct.
function subPage() {
$subPage = new stdClass();
$subPage->content = 'blabla';
$subPage->subPageTitle = 'Plugin Sub Page Dynamic';
return $subPage;
}
function wp_plugin_page_title($subPageTitle) {
$siteTitle = $subPageTitle . " " . subPage()->subPageTitle;
return $siteTitle;
}
add_filter('wp_title', wp_plugin_page_title);
Then you get the value by calling subPage()
echo subPage()->subPageTitle;
If you print_r the subpage you will see:
stdClass Object ( [content] => blabla [subPageTitle] => Plugin Sub Page Dynamic )
Any values that are inside a function, they are encapsulated values if you need to reach them outside that function or you return them in an array or in an object.
I'm trying to integrate with zoom.us, they have their guides here - https://support.zoom.us/hc/en-us/articles/201363053-Meeting-API
When someone schedules a meeting, the scheduler creates a post, which I pick up and call this function:
function scheduler_zoom_integration($post_id) {
$postdata = get_post($post_id);
$appointment_id = get_post_meta( $post_id, '_birs_appointment_id', true );
if (!empty($appointment_id)) {
$conference_details = schedule_meeting();
add_post_meta($appointment_id,'appointment_zoom_details', $conference_details, true);
}
}
add_action('publish_post', 'scheduler_zoom_integration');
Inside that function I call the schedule_meeting function that is using the REST API from zoom to get the meeting details including the link people will click to join the meeting.
function schedule_meeting($coach_id, $appointment_id, $start_time) {
$api_key = 'xxxxxxxxxxxxxxxxxxxxxxx';
$api_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$coach_zoom_id = get_user_meta($coach_id, 'coachzoomid', true);
$url = 'https://api.zoom.us/v1/meeting/create?api_key='.$api_key.'&api_secret='.$api_secret.'&data_type=JSON&host_id='.$coach_zoom_id.'&topic=health&type=2&start_time='.$start_time.'&duration=30&timezone=GMT-7:00&option_jbh=true&option_start_type=video';
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$response = fopen($url, 'r', false, $context);
fpassthru($response);
$response = json_decode($response);
fclose($response);
return $response;
}
I'm looking to get feedback on how I'm performing this function as I've never done a REST API before. Should I use fopen / fclose? How do I make the call to begin with? Any help is appreciated.
You should try using WordPress' built in HTTP API. It has helper functions for doing HTTP calls. I see you're doing a GET so check out:
http://codex.wordpress.org/Function_Reference/wp_remote_get
Note that it returns WP_Error class on failure.
I have a Drupal variable, $view. I need to print out all of its values. I have tried:
dsm($view);
var_dump($view);
function hook_form_alter() {
$form['print'] = array('#value' => '<pre>'.print_r($view, 1).'</pre>');
}
All of these functions produce an output of Null, however. How can I get the value of the variable?
This is probably happening because the $view variable isn't within scope in the function hook_form_alter().
Use:
$view = views_get_current_view();
Then you can access, for example, the arguments of the view:
$arg0 = $view->args[0];
function MYMODULE_form_alter(&$form, &$form_state, &$form_id){
switch($form_id){
case 'MY_FORM':
$display_id = 'block_1';
$view = views_get_view('my_view_machine_name');
$view->set_display($display_id)
$view->set_items_per_page(0); // or other
$view->execute();
$result = $view->preview();
// Also you can use $view->result to get result as array
$form['print'] = $result;
break;
}
}