I want to build a WordPress admin dashboard widget which should return some information from another plugin.
This dashboard widget should read the functions of this plugin here:
http://plugins.svn.wordpress.org/wp-document-revisions/trunk/wp-document-revisions.php
So my code is:
include (WP_PLUGIN_URL.'/wp-document-revisions/wp-document-revisions.php');
$file_type = get_file_type('3');
But this doesn't work. These are the errors:
Fatal error: Call to undefined function add_action() in
/.../wp-content/plugins/wp-document-revisions/wp-document-revisions.php
on line 26
Fatal error: Call to undefined function get_file_type() in
/.../wp-content/plugins/dashboard-widget/dashboard-widget.php
Can anyone tell me how I have to do this, that I can read the function get_file_type('3')?
I'm assuming you are navigating straight to your PHP file in the wp-content/plugins/ folder rather than using a stub to create a URL. If this is the case, then you probably forgot to include wp-load.php
You should not include the plugin file (since the plugin may not be installed or activated).
Instead of this you should check if the function exists:
if (function_exists('get_file_type')) {
$file_type = get_file_type('3');
// rest of the code of the widget
}
It sounds like you are trying to access the PHP file directly, rather than going through WordPress proper. You should create a plugin, and hook into the Dashboard Widgets API.
As for implementation with WP Document Revisions, you've got two options. As of version 1.2, get_documents() and get_document_revisions() are two global functions that will be accessible anytime after the plugins_loaded hook. The FAQ has a bit more info, but they basically function like the native get_posts() function.
Alternatively, the class should be available globally as $wpdr. So if you wanted, for example, to call get_latest_version( 1 ) it'd be $wpdb->get_latest_version( 1 ).
Both assume the plugin's already activated. If you simply include the file, you're going to get an error that you're trying to redeclare the WP_Document_Revisions class.
If you do create a dashboard, I'd love to include it in future releases of the plugin!
Related
I have been fighting with this problem for several days now & I would appreciate input from (PHP / Wordpress) developers that are more experienced than me.
I'm making a debugging plugin for Wordpress, but one of the errors that I need to change comes from this file:
/site/public/wp-includes/wp-db.php
I need to change the structure and add more information to the $error_str in lines 1363 and 1366 so the output better suits our log reader and contains more useful information.
To do that I think I need to change the print_error() in line 1344
The problems are:
That the file is a core file in Wordpress, so I can't edit it directly.
It also have a global $wpdb variable that is used to call: $wpdb->query() & $wpdb->get_row() (also core functions in same file & class) that both in turn calls the print_error() function.
Other plugins are using these functions & I can't mess up their functionality but I should change their output too.
I think the most likely solution is to inherit & override the print_error() (and maybe also query() & get_row() so I can re-direct them to my new print_error()), but other plugins are using the $wpdb & those functions, I can (should) change the error_log() output for those plugins too, but I can't edit those plugins either & I can't mess them up with a faulty solution.
Questions:
How can I replace the print_error()?
What is the best way to do this?
How do I deal with the global $wpdb variable?
Do any of you have a better solution? I would very much appreciate it.
Link to the print_error() documentation (with source code):
https://developer.wordpress.org/reference/classes/wpdb/print_error/
Link directly to the source code: https://core.trac.wordpress.org/browser/tags/4.9.8/src/wp-includes/wp-db.php#L1344
Not entirely sure this is an excellent idea, but you could extend the wpdb class and replace the global $wpdb object.
E.g.
global $wpdb;
$wpdb = new YourWpdbClass(); // you can override methods here to your heart's content
wp_set_wpdb_vars();
Officially, the way to replace the global $wpdb is by creating a db.php file inside wp-content. So if you plugin needs to alter db functionality it would need to include that file and possibly custom installation instructions
Ive been trying for hours to figure out why this magento install will not work. At first it may look like a normal error and im missing a file, but in reality thats not the case. The controller
FME_Manufacturers_Controller
doesn't exist anymore and i'm sure its from an old extension. I cant seem to find anything in the codebase that has to do with the FME controller and I was wondering if this controller can be called from the database. If so, what table? The error is from line 93 in /lib/Varien/Autoload.php
Magento loads controllers and its action like so:
// #see Mage_Core_Controller_Varien_Router_Standard::match
// instantiate controller class
$controllerInstance = Mage::getControllerInstance($controllerClassName, $request, $front->getResponse());
First to find the place where the controller is loaded from you could search your Magento installation for Mage::getControllerInstance('FME_Manufacturers for example.
Second is you could look for lines like <?php echo $this->getUrl('frontname/controllername/action') ?>. Often this is used in templates to call controllers and their actions.
Another thing is, if you follow the error backtrace you should be able to see there this call comes from, shouldn't you?
To call a controller from database is not possible. The only thing is that a static block or a CMS page is including a template and in this template the controller is called. But you would find this place by scanning through all template files in app/design looking for FME.
I'm wondering (I have full access to the serve in case it's a php.ini setting) if there's anyway to "disable parsing of functions if a function was already defined" instead of throwing an error/notice about it?
For example /www/main/deep/file/file.php has:
function homepage_filter_get_map () {
// example1
$generic_filter_array = td_generic_filter_array::get_array();
}
and in /www/main-child/custom.php has, which is called/included/parsed before the file above:
function homepage_filter_get_map () {
//do nothing
}
Essentially, I'm looking for a way to suppress any and all errors outputting about already defined functions while silently ignoring functions that might have the same exact name, but already parsed/defined.
My problem is that the theme I'm using doesn't have full support for Wordpress child themes, just loop files mainly. I know I can just tweak the original files but I want the ability to be able to keep the theme updated without erasing all of our custom tweaks every-time.
Note: Yes, I know you can conditionally call functions, but again I'm looking for a way to do this without editing any of the "main" files since any tweaks done to those get overwritten when updating the parent theme.
if(!(function_exists('homepage_filter_get_map'))){
function homepage_filter_get_map(){
//do code
}
}
This checks if the function 'homepage_filter_get_map' exists. If it doesn't, create the function.
I have a Joomla website where I have a custom module with mod_myModuleName.php and mod_myModuleName.xml files and a folder where there are several PHP scripts that add special functionality to my module. There is a config.php file in the folder that holds an associative array with variables and their values hard-coded. The module works just fine.
What I want though is to provide administrator area for the values of the variables in the array, so that I can put values in administrator panel and get their values in config.php. In my mod_myModuleName.php I use <?php echo $params->get('param')?> and it works like a charm.
But when I try to use the same technique in the config.php it breaks my code. I tried to get the values in mod_myModuleName.php and then include it in config.php and use the variables but it does not work either. I have not got so much experience in php and cannot understand what can be the reason.
It sometimes gives me an error of something non object and I guess it must be something connected with object oriented php, am I right? And if so is there a way to overcome this without object orientation or how can I solve my problem?
The problem will be with the way you're using your config.php.
When your modules entry point file mod_myModuleName.php is loaded by Joomla the $params object is already available in that context, you need to provide it to your scripts.
If you look at something like the mod_articles_latest module you will notice that the helper class is included with this line:
require_once __DIR__ . '/helper.php';
And then helper class is has it's getList() method called statically with the $params passed into it, so that $params is available to class context:
$list = ModArticlesLatestHelper::getList($params);
Inside the helper class ModArticlesLatestHelper you will notice that the getList() expects the $params to be passed in.
public static function getList(&$params)
{
...
}
I would strongly recommend reading the articles in the Modules section of Developers Portal on the Joomla Doc's.
Try the "Creating a simple module" article.
I've never had problems with CakePHP's theming system in the past, but now, errors galore. My main issue is that all theme resources (those in /app/views/themed/MyTheme/webroot/*) fail to load. I've set up a custom AppController in /app to set the theme.
var $view = "Theme";
var $theme = "MyTheme";
When I go to any page, I can see that it's utilizing my theme's default.ctp layout and the HTML is fine. Any and all page resources, CSS, JavaScript, images, anything in the theme webroot, fails to load and instead gives me an error like the following (let's say I tried to access http://example.com/theme/MyTheme/img/bg.png):
Error: ThemeController could not be found.
Error: Create the class ThemeController below in file: app/controllers/theme_controller.php
<?php
class ThemeController extends AppController {
var $name = 'Theme';
}
I've never received an error like this in my time with CakePHP. I'm running the latest stable version at 1.3.7.
I've finally found a solution. CakePHP didn't like my uppercase theme name. In fact, any theme name that I tried that included uppercase characters failed to work. I changed my folder name and internal theme name from "MyTheme" to "my_theme" and it worked perfectly. Could possibly be a bug, but it could be undocumented, yet expected functionality.