is there a way to install the app to the page with restrictions to the visitors country or age?
I am programming an app which will be only available for Users of distinct coutries.
However, I am planning to install the app as a tab on a Facebook page that is international with no restrictions. And I don't want users from other countries seeing my app.
Is this possible?
Regards,
Flashbaer
It should be possible according to https://developers.facebook.com/docs/reference/fbml/restricted-to/
Whatever settings I use result in that the tab isn't available for non-signed in users and is always available for signed in users. I don't think I'm doing anything wrong.
This is the code I use:
self::$facebookClient = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
));
$restrictions = array(
'location' => 'AR,AT',
// 'type' => 'alcohol',
// 'age' => '50+',
);
var_dump($fb->api('/'.$appId.'?restrictions='.urlencode(json_encode($restrictions)), 'POST'));
var_dump($fb->api('/'.$appId.'?fields=restrictions'));
Related
I'm trying to setup a bbpress with extended user capabilities.
The problem
My goal is that users need to have different capabilities in each forum, i.e:
UserA can't access ForumW
UserA can only read topics and replies in ForumX
UserA can create topics and write replies in ForumY
UserA can moderate ForumZ
Plugins
These are the plugins I tried so far, but without success:
Ultimate Member, official 1.7 and the new 2.0 version
https://ultimatemember.com/
They claim that they're working on a groups extension for UltimateMember v2, which somehow looks promising, but as of now there's no release date and I still don't know if this extension is going to solve my problem.
itthinx Groups plugin
http://docs.itthinx.com/document/groups/
Allows me to assign multiple groups to users and forums, but there's still a catch.
First attempt
Since itthinx Groups plugin allows me to assign multiple groups to UserA, which is great, it's still not solving my issue.
So, I tried something like this:
ForumX has the following groups assigned: ForumX_readers, ForumX_writers, ForumX_moderators
UserA has the following groups assigned: ForumX_readers, ForumY_writers, ForumZ_moderators
But the problem is, since UserA belongs to groups that have publish_replies and moderate capabilities, he has full access to ForumX.
So what I need is an intersection of the forum-groups and the user-groups - which in this example is ForumX_readers.
The promising part, but...
I digged into the code of the plugin and found the line that handles the capabilities of the user based on his assigned groups and quickly tried to get the current forum groups, to implement the intersection.
Unfortunatelly I was not able to access the global $post, the $_GLOBALS['post'] nor the $_REQUEST[] variables in this part of code. Neither directly nor with an apply_filters() function, that I implemented into the part of the code myself.
UPDATE:
I was able to get the ID with get_posts() and the slug of the current forum/topic.
So, my question
Is there any solution to my first attempt, which I may have overseen?
If not, is there maybe any other plugin that can solve my problem that I'm not aware of?
Or is something like that even impossible in bbpress?
After some further research and trial & error, I finally figured it out.
First step to do is to set up the capabilities, which in my case look something like this.
In the plugins directory, there is the file core/class-groups-user.php. The init_cache() function retrieves the assigned groups to the user, and sets the according capabilities.
To not mess around to much with the core-plugin, I applied a filter to the $group_ids variable which can be found in line: 415.
foreach( $user_groups as $user_group ) {
$group_ids[] = Groups_Utility::id( $user_group->group_id );
}
// added this line
$group_ids = apply_filters('filter_user_group_ids', $group_ids);`
I then created a new plugin, which hooks into this filter.
add_filter('filter_user_group_ids', 'dnmc_filter_groups', 10, 1);
function dnmc_filter_groups($user_group_ids) {
$forum_id = dnmc_get_forum_id();
if(!$forum_id) return $user_group_ids;
$forum_group_ids = Groups_Post_Access::get_read_group_ids( $forum_id);
$user_restricted_forum_group_ids = array_intersect($user_group_ids, $forum_group_ids);
return $user_restricted_forum_group_ids;
}
function dnmc_get_forum_id() {
$args_topic = array(
'name' => basename( untrailingslashit( rtrim($_SERVER['REQUEST_URI'], '/') ) ),
'post_type' => 'topic',
'post_status' => 'publish',
'numberposts' => 1
);
if($topic = get_posts($args_topic)) {
return $topic[0]->post_parent;
}
$args_forum = array(
'name' => basename( untrailingslashit( rtrim($_SERVER['REQUEST_URI'], '/') ) ),
'post_type' => 'forum',
'post_status' => 'publish',
'numberposts' => 1
);
if($forum = get_posts($args_forum)) {
return $forum[0]->ID;
}
return false;
}
I want to push the products profit of a transaction to Google Analytics.
With this i want to generate a report where i can see the total Product revenue and it's profit for each product that has been ordered.
i'm using this api to push custom metrics to analytics (Measurement protocol api)
I have made several custom metrics in analytics, for example:
Productsprofit (Scope hit, decimal)
Productsprofit2 (Scope Product, decimal)
I've googled several times and i think i need to use the Scope Hit for this type of tracking, am i right?
I've used the api to push the metric with the right indexes to Analytics
$analytics->setTransactionId('test'.$orderId)
->setAffiliation('Testshop')
->setRevenue(number_format($orderTotalPrice,2,'.',''))
->setTax(number_format($taxTotal,2,'.',''))
->setShipping(number_format($shippingTotal,2,'.',''))
->setCouponCode('');
foreach($orderInfo['orderDetails'] as $orderDetail) {
// Include a product, only required fields are SKU and Name
$productData1 = [
'sku' => $orderDetail['model'],
'name' => $orderDetail['name'],
'brand' => '',
'category' => '',
'variant' => '',
'price' => number_format($orderDetail['price'], 2, '.', ''),
'quantity' => $orderDetail['aantal'],
'coupon_code' => '',
'position' => 0,
'custom_metric_3'=>50.45, //<-- test data (Hit)
'custom_metric_4'=>15.50 //<-- test data (Product)
];
$analytics->addProduct($productData1);
}
// Don't forget to set the product action, in this case to PURCHASE
$analytics->setProductActionToPurchase();
// Finally, you must send a hit, in this case we send an Event
$analytics->setEventCategory('Checkout')
->setEventAction('Purchase')
->sendEvent();
I've created a custom report and added these metric to my report. But both metrics stay empty in my report.
Does anyone know what i'm doing wrong ? or what might solve my problem?
Thanks in advance!
In the PHP library that you are using, custom metrics and dimensions are set in a different manner depending on the scope, for Product scope you use the product array like you did, for Hit scope you use the setCustomMetric method. In your code this would look like:
$analytics->setTransactionId('test'.$orderId)
->setAffiliation('Testshop')
->setRevenue(number_format($orderTotalPrice,2,'.',''))
->setTax(number_format($taxTotal,2,'.',''))
->setShipping(number_format($shippingTotal,2,'.',''));
foreach($orderInfo['orderDetails'] as $orderDetail) {
$productData1 = [
'sku' => $orderDetail['model'],
'name' => $orderDetail['name'],
'brand' => 'the brand',
'category' => 'test category',
'variant' => 'variant x',
'price' => number_format($orderDetail['price'], 2, '.', ''),
'quantity' => $orderDetail['qty'],
'coupon_code' => 'coupon used',
'custom_metric_4' => 15.50,
];
$analytics->addProduct($productData1);
}
$analytics->setProductActionToPurchase();
$analytics->setCustomMetric(50.45, 3);
$analytics->setEventCategory('Checkout')
->setEventAction('Purchase')
->sendEvent();
Notice the call to $analytics->setCustomMetric(50.45, 3); before sending the hit. This should send the right data, the rest is creating or looking at the right report in Google Analytics.
I'll try to describe what it is I want to achieve, please let me know if too much/not enough detail!
I'm making a site that needs to have documents uploaded to it. These documents will belong to one only of four categories and there will be one page per category. On this page, by default all documents will display. Users will also be able to view only the documents from each year by clicking a link.
It also needs to have pagination so a max of 10 documents are displayed per page.
So how I would ideally like to do this is to make a custom post type (documents) which would then display an ACF custom field set. The field set would have three fields (doc_type, doc_file and release_date). doc_type would be a select field of the four categories, doc_file a file upload and release_date a datepicker field.
When you click on a page, the controller would select by doc_type to only show the documents that belong to that category.
I want to order by release_date and use the year from this field as the display text of my links. For the actual href, I'm imagining something like /path/to/page.php?year=2017.
So there's a few problems here: first is that I am not sure if what I want to do is even possible - let alone a good way of doing things - with WordPress. I'm more used to pure PHP and mySQL, and so I might be trying to shoehorn more general solutions into WP. Can anyone confirm if it's possible to achieve what I want?
Second, I'm specifically running into some issues when I try to execute this plan.
I can successfully get each page to only display the documents that belong to it, like so (although I'm generating $last by grabbing info from the URI, which seems dodgy).
$docArgs = array(
'post_type' => 'documents',
'meta_key' => 'doc_type',
'meta_value' => $last,
);
$context['documents'] = Timber::get_posts($docArgs);
When I try to get my sorting on though, de nada:
$docArgs = array(
'post_type' => 'documents',
'meta_key' => 'doc_type',
'meta_value' => $last,
'meta_query' => array(
array(
'key' => 'release_date',
'orderby' => 'meta_value_num',
'order' => DESC,
),
),
);
I assume I've got the syntax wrong, but I'm basically really confused about the whole thing. Any suggestions?
I am facing an issue in wordpress serialized data. I am developing a custom plugin which is in relation with woocommerce. I have added a checkout section in woocommerce settings section. Also I am providing same settings update form in my plugin section which is new menu option in left menu.
when I am saving data through woocommerce setting section it stores data in in wp_options table as serialized data. Below is example :
a:18:{s:7:"enabled";s:3:"yes";s:9:"test_mode";s:2:"no";s:19:"is_application_name";s:0:"";s:10:"is_api_key";s:0:"";s:17:"order_customtable";s:0:"";s:16:"order_customflds";s:0:"";s:23:"order_product_customfld";s:0:"";s:14:"is_merchant_id";s:0:"";s:5:"title";s:12:"Infusionsoft";s:9:"tax_label";s:9:"Sales Tax";s:16:"is_free_shipping";s:2:"no";s:11:"description";s:20:"Pay via
Infusionsoft";s:5:"cards";s:16:"VISA
MASTERCARD";s:14:"wooorderstatus";s:0:"";s:14:"thanks_message";s:39:"Thank
you. Your order has been
received";s:5:"debug";s:2:"no";s:11:"debug_email";s:0:"";s:13:"http_post_key";s:0:"";}
From my plugin page, on form submit I am getting field values and creating an array as below :
Array (
[enabled] => yes
[test_mode] => no
[is_application_name] =>
[is_api_key] =>
[order_customtable] =>
[order_customflds] =>
[order_product_customfld] =>
[is_merchant_id] =>
[title] => Infusionsoft
[tax_label] => Sales Tax
[is_free_shipping] => no
[description] => Pay via Infusionsoft
[cards] => VISA MASTERCARD
[wooorderstatus] =>
[thanks_message] => Thank you. Your order has been received
[debug] => no
[debug_email] =>
[http_post_key] => )
Now serializing and updating option using function update_option it will save data in in data base as below string :
s:597:"a:18:{s:7:"enabled";s:3:"yes";s:9:"test_mode";s:2:"no";s:19:"is_application_name";s:0:"";s:10:"is_api_key";s:0:"";s:17:"order_customtable";s:0:"";s:16:"order_customflds";s:0:"";s:23:"order_product_customfld";s:0:"";s:14:"is_merchant_id";s:0:"";s:5:"title";s:12:"Infusionsoft";s:9:"tax_label";s:9:"Sales Tax";s:16:"is_free_shipping";s:2:"no";s:11:"description";s:20:"Pay via
Infusionsoft";s:5:"cards";s:15:"VISA
MASTERCARD";s:14:"wooorderstatus";s:0:"";s:14:"thanks_message";s:39:"Thank
you. Your order has been
received";s:5:"debug";s:2:"no";s:11:"debug_email";s:0:"";s:13:"http_post_key";s:0:"";}";
Please help me in this issue.
Don't serialize the array yourself, update_option will do it if needed.
https://developer.wordpress.org/reference/functions/update_option/
I use Prestashop 1.6.2 and I have a problem trying to add this function.
I am a little bit new trying to mod prestashop, the thing is that I have some products that can be bought only for professionals. Everytime a user registers it's assigned to a user group (professional and no-professional).
I know I can hide the categories for specific user groups, but this method is not perfect, due to if they know the name of the product or search it, they can still access the product page and buy it.
Is there any smarty variable to edit the product.tpl so it displays the button with the conditions above? Or a module or another way to do this?
I don't know exactly is there is a variable already set in smarty or not, but your can define your customer variable with object of customer:
Find controllers/front/ProductController.php file, find method assignPriceAndTax and in the end of it you will find something similar to this:
$this->context->smarty->assign(array(
'quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (float)$tax, $ecotax_tax_amount),
'ecotax_tax_inc' => $ecotax_tax_amount,
'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2),
'ecotaxTax_rate' => $ecotax_rate,
'productPriceWithoutEcoTax' => (float)$product_price_without_eco_tax,
'group_reduction' => $group_reduction,
'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address),
'ecotax' => (!count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((float)$this->product->ecotax) : 0),
'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'),
'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group),
));
Add to this array
'customer_object' => $this->context->customer,
This variable you can use on the product page.
You can use the same way to close those buttons for all 'buy-windows' on your site.