I tried to call the jooomla triggerEvent function for rsform Pro's payment plugin from an external php file.
But I keep getting 500 errors and my server error log didn't cache the error code.
Below is my code and I also added my reference.
Please help me to find out the error source.
Thank you in advance.
define( '_JEXEC', 1 );
define('JPATH_BASE', '../');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
require_once (JPATH_BASE. '/plugins/system/rsfppayment/rsfppayment.php');
jimport('joomla.application.component.controller');
$updatedSubmissionId = 168;
$mainframe = JFactory::getApplication();
$mainframe->triggerEvent('rsfp_afterConfirmPayment', array($updatedSubmissionId));
Its better to make your own function for your plugin then to use a function from another plugin. But I will give a short note on method to call plugins inside your own plugin code(latest for Joomla 3+):
Step 1:
Call JPluginHelper::importPlugin( 'plugingroup' );
plugingroup can be system or plugin folder where rsfppayment plugins are located.
Step 2:
$dispatcher = JEventDispatcher::getInstance();
Step 3:
$results = $dispatcher->trigger( 'rsfp_afterConfirmPayment', array($updatedSubmissionId) );
The below code should do the trick - a 'little' more information can be found on the docs.joomla.org site https://docs.joomla.org/Triggering_content_plugins_in_your_extension.
// Note JDispatcher is deprecated in favour of JEventDispatcher in Joomla 3.x however still works.
JPluginHelper::importPlugin('system');
$dispatcher = JDispatcher::getInstance();
$dispatcher->trigger('rsfp_afterConfirmPayment', array($updatedSubmissionId));
Related
I am trying to obtain the username variable from an external PHP script that is not part of Drupal or a Drupal Module.
For Drupal 7 there was drupal_bootstrap to load the required Drupal dependencies. However, after a long search all I found for Drupal 8 was a note that drupal_bootstrap is deprecated for Drupal 8.
And indeed, I get a
Call to undefined function drupal_bootstrap()
when I try to call it after including as in
<?php
define('DRUPAL_ROOT', '/var/www/html/drupal7'); // Define the DRUPAL_ROOT constant which is used in many places.
$base_url = 'http://'.$_SERVER['HTTP_HOST'].'/drupal7'; // Again, this is used in many places.
require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; // Include the boostrap file.
drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION); // Start things up to whatever level you need.
global $user;
echo $user->name;
So how can I use the Drupal 8 API from an outside script?!
Posted this on another forum and I got this code, but it just doesn't work, so I would like to know what's going wrong. I know that something's missing, but I don't know how to echo the name of the current user who's logged on:
<?php
define('DRUPAL_DIR', __DIR__ .'/../../drupal');
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once DRUPAL_DIR . '/autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
require_once DRUPAL_DIR . '/core/includes/database.inc';
require_once DRUPAL_DIR . '/core/includes/schema.inc';
?>
Thanks in advance
I am integrating google spreadsheet in my project. I have to save form data into google spreadsheet.
For this i am using asimqt php-google-spreadsheet-client library.
I have single form on site that form is submitting using ajax. For this i have written function in function.php.
Getting error when initializing object of DefaultServiceRequest class.
Error: Fatal error: Class 'Google\Spreadsheet\DefaultServiceRequest' not found
require '/vendor/autoload.php';
use Google\Spreadsheet\DefaultServiceRequest;
use Google\Spreadsheet\ServiceRequestFactory;
function spreadsheet_feeds()
{
$access_tok = 'xyz-token';
$serviceRequest = new DefaultServiceRequest($access_tok); // Getting error
ServiceRequestFactory::setInstance($serviceRequest);
$spreadsheetService = new Google\Spreadsheet\SpreadsheetService();
$spreadsheetFeed = $spreadsheetService->getSpreadsheets();
}
add_action( 'wp_ajax_nopriv_spreadsheet_data', 'spreadsheet_feeds' );
add_action('wp_ajax_spreadsheet_data','spreadsheet_feeds');
Any help why this error is occurring because class is already include using "use" statement ?
This seems to be an issue with the location of your vendor folder.
Make sure that the vendor folder is accessible by the file
Considering your folder hierarchy to be
-wp-content
--themes
---your-theme
----functions.php
If you have your vendor folder in your-theme/vendor then in your functions.php
you should write
require 'vendor/autoload.php';
and if vendor is in the root directory of WP make sure you traverse back to the root folder using something like :
require __DIR__ .'/../../../../vendor/autoload.php';
Just replace require '/vendor/autoload.php'; to require_once('vendor/autoload.php');
Just now I tried this here for you myself and it works.
I need to create a very simple REST API (GET ONLY BY NOW)
but tables for query are not native of wordpress then I need to create a new php file,
this is not going to be a template
then how can I Access to wordpress functions and wordpress connection object for not create a new mysql connection object.
I tried but I got
Call to a member function get_results()
thanks
<?php
/**
* api
* #package accesspresslite
*/
define( 'SHORTINT',true);
require_once('./wp-load.php')
global $wpdb;
$results = $wpdb->get_results('select email from wp_wysija_user',OBJECT);
?>
This is the path where wp-load.php file is.
and i got
Parse error: syntax error, unexpected 'global' (T_GLOBAL) in C:\xampp\htdocs\IniYuc\wp-content\themes\accesspress-lite-child\api.php on line 11
You can load the wordpress functions/objects from outside the framework. Consider the following code:
define( 'SHORTINIT', true );
require_once(PATH_TO_YOUR_INSTALLATION . '/wp-load.php' );
Afterwards, alle the known objects (e.g. $wpdb) will be present.
Create a new php file in your THEME directory like:
wp-content/themes/accesspress-lite-child/NEW-FILE.php
And put the bellow lines at top of the file:
<?php
define( 'SHORTINIT', true );
//Add file from = C:\xampp\htdocs\IniYuc\
require_once('../../../wp-load.php' );
Note: set the proper path to wp-load.php so it loads the required file.
You can use WP functions now.
I'm trying to create a script that would download and install wordpress + plugins + themes automatically.
All the stages until installing are working out. The files are downloaded and the wp-config.php is working - but when I try to run the wp install I get the following error:
Fatal error: Call to undefined method stdClass::add_query_var() in C:\Apache24\htdocs\wp\wp\wp-includes\taxonomy.php on line 371
From doing some research - it seems that the problem is finding the right way to include wordpress functions in my script - this is my code
define( 'WP_INSTALLING', true );
global $wp;
require_once( $directory . 'wp-blog-header.php' );
/** Load WordPress Bootstrap */
require_once( $directory . 'wp-load.php' );
/** Load WordPress Administration Upgrade API */
require_once( $directory . 'wp-admin/includes/upgrade.php' );
/** Load wpdb */
require_once( $directory . 'wp-includes/wp-db.php' );
var_dump($wp);
// WordPress installation
wp_install( $data[ 'weblog_title' ], $data['user_login'], $data['admin_email'], (int) $data[ 'blog_public' ], '', $data['admin_password'] );
in taxonomy line 371 theres a function call :
$wp->add_query_var( $args['query_var'] );
I suspect that $wp never gets defined.
Does anyone know what I should change to do that?
I made sure that it crashes on the wp_install - never goes past that in my script.
I have a PHP script used for AJAX queries, but I want them to be able to operate under the umbrella of Joomla's (2.5) framework so I can have session id's, user id's etc available to me.
For example:
$(function () {
$.ajax({
url: 'ajax.php', //the script to call to get data
dataType: 'json' //data format
...
});
});
Where ajax.php has code such as:
$user =& JFactory::getUser();
From what I understand it's best to make your AJAX/JSON calls to a standard Joomla component. I don't know much about developing a MVC component but from what I can see it is way overkill for what I want to do.
Is there something else I could be using?
if you create a component you can create new view for raw queries for example compoments/com_yourcomponent/views/ajax/view.raw.php and put all logic and output in there
url will be index.php?option=com_yourcomponent&view=ajax&format=raw
or
you can to create new method in controller.php with exit() after print information and url will be index.php?option=com_yourcomponent&task=ajax
This is absolutely possible by way of the Joomla Platform. The example I'll give you below is actually for J1.5, but is easily adaptable to J2.5 with some adjustment to the included files.
Create a joomla platform file to include as shown below:
Include that file in your script
Use the now-available Joomla environment for your functions.
Another strong recommendation is to implement a ReSTful API instead of your custom scripts. It's outrageously simple using Luracast Restler. I had it up and running in about 10 minutes, then added the Joomla Framework as shown below, and had an extremely flexible Joomla based API using AJAX calls for my site in under an hour! Best spent development time in years, as far as I'm concerned.
yourscript.php
require_once('joomla_platform.php');
/* Get some of the available Joomla stuff */
$config = new JConfig();
$db = &JFactory::getDBO();
$user =& JFactory::getUser();
if($user->gid <25) {
die ("YOU CANT BE HERE");
}
echo "<pre>".print_r($config,true)."</pre>";
joomla_platform.php
<?php
/* Initialize Joomla framework */
if (!defined('_JEXEC')) {
define( '_JEXEC', 1 );
// define('JPATH_BASE', dirname(__FILE__) );
define ('JPATH_BASE', "c:\\wamp\\www");
define( 'DS', DIRECTORY_SEPARATOR );
/* Required Files */
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/* To use Joomla's Database Class */
require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
require_once ( JPATH_LIBRARIES.DS.'joomla'.DS.'import.php'); // Joomla library imports.
/* Create the Application */
global $mainframe;
$mainframe =& JFactory::getApplication('site');
}
?>
You don't need to create any custom files and add them into Joomla script. You just need a controller to serve ajax request. You don't even need a view (one way).
Your ajax call should be like these:
$(function () {
$.ajax({
url: 'index.php?option=com_<component_name>&no_html=1task=<controller_name>.<controller_action>', //not_html = 1 is important since joomla always renders it's default layout with menus and everything else, but we want the raw json output
dataType: 'json' //data format
...
});
});
And your controller:
/*
* #file admin/controller/<controller_name>.php
*/
class <component_name>Controller<controller_name> extends JController
{
public function <controller_action>()
{
//do something
$respnse['message'] = 'Your message for the view';
die(json_encode($reponse));
}
}
...
This is just one of the examples of how it's could be done.