Using a function from joomla plugin file - php

As stated in my question, how can i use the function which is inside joomla plugin folder from an external php file?
To be exact, it is under this patch "/plugins/system/rsfppayment/rsfppayment.php" and I want to use the function rsfp_afterConfirmPayment(). I pasted the code snippet below and this file is from rsForm Pro Paypal payment plugin.
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
/**
* RSForm! Pro Payment Plugin
*/
class plgSystemRSFPPayment extends JPlugin
{
function rsfp_afterConfirmPayment($SubmissionId) {
RSFormProHelper::sendSubmissionEmails($SubmissionId);
}
}

You can do the following:
require_once('/plugins/system/rsfppayment/rsfppayment.php');
$objplgSystemRSFPPayment = new plgSystemRSFPPayment();
$objplgSystemRSFPPayment->rsfp_afterConfirmPayment($submissionId);
Of course, you need to make sure that the path is correct and the value of $submissionId is valid.

Post the complete code then you use. The code of itoctopus is correct

Related

Fatal error: Cannot declare class MYCLASS Woocommerce Settings

I have a website, and when I go to the WordPress admin page and click on woocommerce-settings it shows this error:
Fatal error: Cannot declare class WC_Settings_General, because the
name is already in use in
/(hosting)/website/wp-content/plugins/woocommerce/includes/admin/settings/class-wc-settings-general.php
on line 0 The site is experiencing technical difficulties. Please
check your site admin email inbox for instructions.
The beginning of class-wc-settings-general.php looks like this:
<?php
/**
* WooCommerce General Settings
*
* #package WooCommerce/Admin
*/
defined( 'ABSPATH' ) || exit;
if ( class_exists( 'WC_Settings_General', false ) ) {
return new WC_Settings_General();
}
/**
* WC_Admin_Settings_General.
*/
class WC_Settings_General extends WC_Settings_Page {
/**
* Constructor.
*/
public function __construct() {
$this->id = 'general';
$this->label = __( 'General', 'woocommerce' );
parent::__construct();
}
/**
* Get settings array.
*
* #return array
*/
public function get_settings() {
etc. The webpage url that is generating this error is: https://www.(mywebsite).com/wp-admin/admin.php?page=wc-settings
I need to know how to resolve this issue and get to the woocommerce settings. I have other websites that have woocommerce and do not have this issue, and I do not know where the other place it is declared would be.
If you need to know the list of plugins, please, let me know.
Please do not flag as a duplicate post as this is a very specific issue regarding woocommerce and WordPress that the other posts I have looked at (around 8 others) do not fix. I have checked for require to change to require_once
Thank you in advance!
I had exactly the same error, except it was pointing to line 0. I switched theme to Storefront and deactivated all plugins except WooCommerce, which fixed the problem... then switched the theme back and gradually added plugins back in to find out which was the problem.
Hopefully this can work for you as well - it was just a conflict with me on an old plugin I thankfully wasn't using any more anyway.

Disabling the Codeigniter’s cache for logged in users

I'm using codeigniter cache on my personal CMS. The problem is, i don't want to show cached pages if the user it's logged on administration.
Saw this tutorial on google:
http://www.badpenguin.org/codeigniter-cache-disable
class MY_Output extends CI_Output {
function _display_cache(&$CFG, &$URI)
{
/* Simple Test for Ip Address */
if ($_SERVER['REMOTE_ADDR'] == NOCACHE_IP )
{
return FALSE;
}
/* Simple Test for a cookie value */
if ( (isset($_COOKIE['nocache'])) && ( $_COOKIE['nocache'] > 0 ) )
{
return FALSE;
}
/* Call the parent function */
return parent::_display_cache($CFG,$URI);
}
}
The problem it's that the session it's on database (ci_sessions), and i can't access it inside MY_Output.
using:
$CI =& get_instance();
$CI->session->userdata('userID')
give me:
Class 'CI_Controller' not found in
As output runs before controller, and session Needs CIcontroller, the only Thing i can think of its disable session storage on database and the encription, and i don't want do that rs.
Someone can give me some light on this? i still can't find the solution to this!
Thanks!
Try this:
#$SESS = & load_class('Session', 'libraries/Session');
The # is there to prevent it from whining about "session already started". Do note: this is for CI3. The code for the original Output class states (lines 407-409):
// Note: We use load_class() because we can't use $CI =& get_instance()
// since this function is sometimes called by the caching mechanism,
// which happens before the CI super object is available.

Joomla plugin event not firing

I'm working on a plugin to work with a custom component I am developing for Joomla 3.3
However, with basic code firing in the event "onBeforeCompileHead", I am trying to update the canonical information that Joomla 3.3 produces, by taking all of the data from the array and resending it after modifying the data to add my own information.
However when adding custom code according to the Joomla programming guide (for starters) I do not see the code running nor does it add the head information needed for this test.
My code is as follows:
<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.plugin.plugin');
class plgSystemCUSTOMPLUGIN extends JPlugin {
function onBeforeCompileHead() {
if ($this->params->get('site_url')) {
$document = JFactory::getDocument();
$headData = $document->getHeadData();
$headData['metaTags']['standard']['revised'] = $this->params->get('site_url');
$document->setHeadData($headData);
}
}
}
I've taken the if statement out, it was not even hitting this point. I've even added a basic PHP mailer call to send a test email if this function was hit at all.
The plugin was installed as a "System" plugin. It is loading however the class into the framework, as I am able to cause syntax errors. I've also checked and the dispatcher in Joomla's core is definitely loading the event.
Does anyone have insight as to what is going on here?
Thanks!
I've figured this out. My language file was not using the proper name for the plugin, and this will only work if the class name is like:
class plgSystem[plugin_name] {
}
I now have this working as expected.
Thanks!

PHP: Is this the correct way of using a function that is defined under a class?

I have a PHP class inside my Wordpress plugin that is activated in a website. I want to use a method (doc_export function) that is defined inside this class in another plugins (also activated in the same website). I add this one and it seems working:
<?php
// Export doc
if (defined('DOC_ADMIN_MODE')) {
$my_Documentation = new Class_Documentation;
$mydocexport = $my_Documentation->doc_export();
$mydocexport_file = ABSPATH . '_export/' . basename($site['site_url']) . '/doc.xml';
file_put_contents($mydocexport_file, $mydocexport);
}
?>
I want to know if this is the proper approach..Thanks.
Yes that's the proper approach. You can also read about the OOP basis in PHP at http://php.net/manual/en/language.oop5.basic.php

joomla component development with Ajax queries

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.

Categories