I have added custom payment method to woocommerce and its working fine . I just have one problem that it calls a callback url for saving transaction information to db. I have created new function for this in my plugin file but i cant excess it directly .
This is how i have done it:
//add_action('wp_ajax_nopriv_payment_callback_action', 'payment_callback_action');
//function
function payment_callback_action() {
echo "Its Working!";
}
I am trying to access it by :
url:"<?=site_url( '/' );?>wp-admin/admin-ajax.php?action=payment_callback_action
It seemd that it because of i dnt have privillage to use it directly but how can i do this ?.
Thanks
# for users not logged in
add_action('wp_ajax_nopriv_payment_callback_action', 'dixipay_callback_action');
# for users logged in
add_action('wp_ajax_payment_callback_action', 'dixipay_callback_action');
# Your callback
function dixipay_callback_action() {
echo "Its Working!";
}
read more: http://codex.wordpress.org/AJAX_in_Plugins
Related
I am using contact form 7 wordpress plugin for one of website and facing problem to adding action after sending mail.
I want to call some CRM Api when data submitted by the user and also sent mail to admin so i have tried following way.
I added action and function to function.php
1)
add_action('init', create_function('',
'add_action("wpcf7_admin_after_mail", "leads_integration_wp_cf7");'));
function leads_integration_wp_cf7($cf7 ) {
$title = $contact_form->title;
$submission = WPCF7_Submission::get_instance();
if($submission)
{
$posted_data = $submission->get_posted_data();
//using curl make request here
}
}
So using this way i got mail but i am thinking my function(leads_integration_wp_cf7) did not called and i did not get entry in CRM.
2)
add_action('wpcf7_before_send_mail', 'leads_integration_wp_cf7');
using this way i made successfully request to CRM but mail sending stop.on a form page ajax preloader loading,loading, and not redirect on url.
Anybody face this issue i am new in wordpress.
The action wpcf7_admin_after_mail is called in edit-contact-form.php file and it is used for form control ui purpose so it will not be helpful for this case.
The action wpcf7_before_send_mail is correct for doing some task when contact form is posted and email is sent, can you confirm that mail is working properly if this action hook is not applied?
Also try renaming the param $cf7 to $contact_form
function leads_integration_wp_cf7($cf7) {
To
function leads_integration_wp_cf7($contact_form) {
{code: 'invalid_json', message: 'The response is not a valid JSON response.'}
code: "invalid_json"
message: "The response is not a valid JSON response."
I have this panel that i'm developing at my company where i will show the user's information from Google Analytics but i don't want the user to authorize or log in with his account every time he comes to the panel.
What i would like to do is: on the first time using my panel he would connect his Google account and i would save some info and on the next time he connects at my panel i would use this saved info to log on his account so i can list the Analytics info without ask for his permission or list that info even if he's not connected on is Google account right now.
Basically i would log in his account automatically and permit the 'app' to show the information.
I already have some code that connects on the API if he is connected on is Google account, but when he's not i get the login screen where he has to provide his email e password.
What i have so far is this:
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Analytics PHP Starter Application");
$client->setClientId('KEY');
$client->setClientSecret('SECRET');
$client->setRedirectUri('RETURN URI');
$client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
$client->setAccessType('offline');
$service = new Google_Service_Analytics($client);
if(isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if(isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if(isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
if($client->getAccessToken())
{
$props = $service->management_webproperties->listManagementWebproperties("12008145");//~all
print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";
$accounts = $service->management_accounts->listManagementAccounts();
//print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
$segments = $service->management_segments->listManagementSegments();
//print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
$goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
//print "<h1>Goals</h1><pre>" . print_r($goals, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
header("Location: " . $authUrl);
}
?>
Is there any way to do that ? I have looked for it around everywhere and couldn't find something near it.
In google Api's, when user authenticate the first time, you receive a CODE (which you are already getting i suppose). Use this code to get refresh token (lifetime is (always), until and unless, user revokes the permissions). Save this refresh token in Database for further use. Refresh token is used to get access token(lifetime is a short time, returned in the expires in argument). Access token is to give you access to your user's data for some time. You can keep using refresh token to get access token whenever you need to access your user's data.
Whenever you want to access user's data, use refresh token to get access token and then use that access token to get user's data.
In your case, you are using google api php client, you can use Methods in Client.php like:
getAccessToken()---to get refresh token the first time. When you call this method, you get back a json in a form: let this json name be $accessToken
$accessToken = {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
"expires_in":3600,"id_token":"TOKEN", "created":1320790426}
parse json to take refresh_token($refreshToken = $accessToken.refresh_token) and save it for later use.
setAccessToken($accessToken)---call this to set the OAuth access token.
refreshToken($refreshToken)---Fetches a fresh OAuth access token with the given refresh token.
For further clearity, look at Client.php and also read:
https://developers.google.com/accounts/docs/OAuth2WebServer
I'm getting an error (INVALID_SESSION_ID) when trying to send an authenticated GET request to Salesforce.com.
Here is the plug-in in its entirety, which basically just outputs the body of the REST response to whatever page has the [MembershipTables] shortcode:
if (!class_exists('WP_Http')) {
include_once(ABSPATH . WPINC . '/class-http.php');
}
// This is obviously the real username
$username = 'xxxx#xxxx.xxx';
// And this is obviously the real password concatonated with the security token
$password = 'xxxxxxxxxxxxxx';
function getMembershipTables() {
$api_url = 'https://na15.salesforce.com/services/apexrest/directory';
$headers = array('Authorization' => 'Basic ' . base64_encode("$username:$password"));
$args = array('headers' => $headers);
$request = new WP_Http;
$result = $request->request($api_url, $args);
$body = $result['body'];
echo "$body";
}
add_shortcode( 'MembershipTables', 'getMembershipTables' );
I should note that I can successfully hit this endpoint with Curl, though I use a session token I get from Salesforce using the old SOAP API to keep it equivalent (i.e., no client id/secret).
Am I doing something wrong with WP_Http? Or cannot I not authenticate a salesforce.com request using basic auth?
Thanks.
The salesforce API does not support Basic authentication, you need to call it with a sessionId. You can obtain a sessionId by various methods include interactive & programatic OAuth2 flows, and via a Soap login call.
Basis Interactive had a similar problem to solve. When I worked on the project I opted to to call the SalesForce CRM via the preset form plugin and a custom JS Cookie PHP Wordpress Plugin. We had this problem easily resolved by developing custom calls to SalesForce CRM via a getRequest in PHP passing data to the SalesForce CRM.
Test Site in Use:
http://newtest.medullan.com/wp/?page_id=3089
Here is the code and recycle the logical queries
Download Link:
http://basisinteractive.net/webdesign.html#wordpress
I have a timeout module that logs a user out based on if they have been inactive. The problem is that the module calls module_invoke_all('user_logout', $user); and another module ends up logging the user out as that module actually displays the proper logout landing page.
How can I make my module display a message on the other logout page? Also drupal_set_message would not work as the user will be logged out and the way drupal_set_message works is that you have to have the proper session at hand.
Please let me know your thoughts
Thanks
In hook_user_logout, set a cookie with the message you want to display
<?php
setcookie('my_message', t("Goodbye, have a nice evening!"), time() + (86400 * 30), "/");
?>
... then in hook_init, display whatever is in the cookie and delete the cookie
<?php
function MYMODULE_init() {
if(!empty($_COOKIE['my_message'])) {
drupal_set_message($_COOKIE['my_message']);
setcookie('my_message', '', time() - 3600);
}
}
?>
We're doing a site with user generated RSS feeds which can be viewed by other users who we accounts and are verified by the source user. Is there an RSS package for php around that has password protection available that's easy to tie into a user database?
if the RSS file name is rss.php then you can check in the php before generating XML if the user is authenticated or not !
RSS feeds can be protected using HTTP authentication. where you can use the following URL to access rss:
http://username:password#example.com/rss.php
you can allow acccess to the file by one of these methods:
.htaccess
using http authentication with PHP
You, on the database, create a unique key for all users.
id username rss_key
1 user_a 49f0bad29968
2 user_b 1f2414c23a7d
3 user_c 9bc46e8e52ad
Your RSS Link:
http://example.com/rss.php?Key=1f2414c23a7d
You pair the key value with the user.
<?php
$GetKey = addslashes($_GET['Key']);
//Other Rules --- Example: if(empty($GetKey)) { echo "error"; exit(); }
include("connect.php"); //Your connection file
include("session.php"); //Your session file
$Username = $User['username']; //in session file
$Match = Mysqli_Fetch_Array(Mysqli_Query($con, "SELECT u.rss_key AS 'RSSKey' WHERE user_table_name AS u WHERE u.username='".$Username."'");
if($Match['RSSKey'] !== $GetKey)
{
//Stop page
exit();
}
else{
//Your RSS Code...
}
?>