Call to undefined function add_options_page() - wordpress

I developed the plugin for my wordpress project. I successfully tested it on my local xampp server with 5.3 php. Then I uploaded my project to the web hosting with php 5.2. First trouble which with I faced off was unsupporting anonymous functions in php 5.2. No issue, I redeclared all functions with names. But then I got error Call to undefined function add_options_page(), which I counldn't explain. Plz help me guys with your advices
My part of code:
function mainPage(){
///some code
}
function mainPage2(){
add_options_page('Submissions of MAIN page contact form', 'Submissions of MAIN page contact form', 'manage_options','ea_submissions2', mainPage());
}
add_action('admin_menu',mainPage2());
I think something wrong with my funcitons, look through it please.
There is no issue with php 5.2 as I thought, this part of code also doesn't work with php 5.3! Something wrong with my code

I had a similar problem, turns out I was running a function too early:
Use admin_init hook instead of init
Hopefully that helps someone out :D

This doesn't work because you have normal function not wrapped in a class, and because add_options_page does not work yet by that time that is why you get the error.
A fix would be to use an anonymous function in the add action call, but hence that does not work on php 5.2.
So long story short, this is fixable though, but you shouldn't run php 5.2 anymore in the first place. PHP 5.5 is already in development and 5.3 is facto standard these days. A solution is to ask your hosting company to upgrade php to at least 5.3 so that you can use anonymous functions and you can hook it to the add action call.
Or, wrap it all in a class and on the admin init function create the new class.

You have to call your code inside admin_menu like this
add_action( 'admin_menu', array(&$this, 'addWidgetSettingsMenu' ));

Aware that this is an old question, this is your problem:
add_action('admin_menu',mainPage2());
Here you are invoking the mainPage2() function and adding the return value of that function as an argument to the add_action method.
You should do
add_action('admin_menu', 'mainPage2');
This way, the mainPage2 function will be called when admin_menu happens.

Try it without giving space in title :-
SubmissionsOfMainPageContactForm

Related

Console Error for woocommerce_shared_settings deprecation

I am working with WooCommerce for the first time and I am currently implementing WC filters on the shop page. The filters show up but are not functional, and the console is throwing the following errors:
ERROR 1: woocommerce_shared_settings filter in Blocks is deprecated. See https://github.com/woocommerce/woocommerce-gutenberg-products-block/blob/trunk/docs/contributors/block-assets.md
ERROR 2: deprecated.min.js?ver=932d8bb37da8bbb396a7a3f754345e08:2 select control in #wordpress/data-controls is deprecated since version 5.7. Please use built-in resolveSelect control in #wordpress/data instead.
The errors disappear when I remove the filters.
I have located the file where the deprecated code exists. I also read the WC docs about how to fix the issue and it presented this code:
use Automattic\WooCommerce\Blocks\Package;
use Automattic\WooCommerce\Blocks\Assets\AssetDataRegistry;
Package::container()->get( AssetDataRegistry::class )->add( $key, $value )
It doesn't say where to put this code, though. Where should I put it to solve this issue?
I have the same problem.
Which is the file you located?
Here also says you have to add, on the "client side", this code:
wc.wcSettings.getSetting( 'key' );

what is the real use of __return_empty_array in wordpress and when should we use it?

As I have started learning wordpress plugin developement recently but i can't understand the function __return_empty_array. It returns an array but when should we really use it.
__return_empty_array returns an empty array. It is ued to return empty array to filters. For example consider the case of turning off the link of the authors page. You can add the following code to functions.php to get it done.
add_filter ('author_rewrite_rules', '__return_empty_array');
In this case an empty array is returned and __return_empty_array is used for it. Hope you get me.

Missing includes in Wordpress plugin (wp_insert_post function)

I created a code which generates content and I want to populate Wordpress's database with it. I am using wp_insert_post and add_post_meta functions but every time I load which triggers the script I get this error:
Fatal error: Call to undefined function add_action() in \www\scriptmafia\wp-includes\post.php on line 153
To my mind it due to some missing includes. I have included post.php which it mentioned as required include for wp_insert_post function.
I know this is pretty common among newbies in WordPress. However, any solution I have tried have not worked for me.
require_once( ABSPATH . '/wp-load.php'); should solve it :)

how the output of the drupal hooks

the drupal is 6.
1, in drupal.everything's output is by a theme function or a template file.is this right. if right,then question 2.
2,in a module there is a hook_link and hook_menu, how they output? i can't find a theme function or a template file effect it. thank you.
eg:in book's module there is a book_link() defined. but i can't find there is a heme_book_link(),and in hook_theme there is no return of the book_link.
3 things that make understanding Drupal hooks:
They are just regular php functions.
Many times they don't return anything.
They are "called" by module_invoke_all() or module_invoke()
For Example: If module foo has a hook_dosomething() there is a function in foo.module that implements module_invoke_all('foo', 'dosomething')
The other way to think about it is that the hook "exteneds" a function someplace else, and anything that happens in the hook happens in the function that calls module_invoke_all() in it.
Not all hooks generate output. hook_menu() and hook_link(), for example, just return arrays with data that will be used by Drupal in some way (e.g. to register new paths in the system).

Wordpress widget creation

%wordpress I've created to tool to turn php functions into Wordpress widgets. I use the register_sidebar_widget function but it seems like wp_register_sidebar_widget would give me more options. Is that legal?
P.S. I also generate widgets in the new 2.8 format.
register_sidebar_widget is deprecated--though it can still be used, but you could use wp_register_sidebar_widget. If you do use register_sidebar_widget might want to bracket it in an if ( function_exists('register_sidebar_widget') ) in case that function gets removed in subsequent versions.
Also, there is a plugin, Otto's PHP Code Widget, that allows PHP code in a widget.
http://codex.wordpress.org/WordPress_Widgets_Api/register_sidebar_widget
http://codex.wordpress.org/WordPress_Widgets_Api/wp_register_sidebar_widget
http://wordpress.org/extend/plugins/php-code-widget
Legal? Sure. WordPress is GPL, you can do anything you like as long as you follow the requirements of the license.

Resources