register_activation_hook with include file [closed]

You have two options either define you register methods as static and then you can avoid instantiating your classes or even calling the MyActivation function ex: File1.php: Class File1 { static function file1_register() { //register some short codes; } static function file1_unregister() { //unregister previous short codes; } } File2.php: Class File2 { static function … Read more

Plugin won’t activate – cannot declare class (already in use)

Because WordPress already have class named Request https://developer.wordpress.org/reference/classes/requests/ When creating a plugin or using boilerplate to generate, you should add prefix for your plugin name/class name, or avoid using very basic name. Example: class Wpse309780_Request { function __construct(argument) { # code… } }

How to properly setup an activation hook

You first example looks corrent. There is however a typo, hence class ‘MyPluginAdmin’ not found. You include myplugin-admin.php, but then your question seems to suggest the page holding the class is in fact my-plugin-admin.php (with a hypen). If I correct the typo and run the code there are no warnings. Edit (this works correctly): my-plugin.php: … Read more

Default Plugin Settings Not Writing to Database

I believe the issue is that your function that sets up the settings initially isn’t getting run upon activation. Add a call to your mouldings_register_settings_initial() in the activation hook, like this: function mouldings_activate() { global $wpdb, $mouldings_options; mouldings_register_settings_initial(); if ($mouldings_options === false){ $mouldings_options = array( ‘idea_item_columns’ => ‘4’ ); update_option( ‘mouldings_settings’, $mouldings_options ); } } … Read more

Comments deactivated

Comments might have been closed once. If you change this option later globally it doesn’t affect existing posts when comments were turned off per post. To test if comments really work create a new post and enable the discussion meta box on that screen: If you can comment while all plugins are disabled and the … Read more

How to automate wordpress plugin activate and deactivate by php logic?

Method 1 You can use activate_plugin() and deactivate_plugins() to activate/deactivate plugins programmatically. If you want to control the time at which those actions happen, then you can use wp_schedule_event() too. Method 2 I know you asked about PHP, but if you have WP-CLI installed on your server, you can also write a script that uses … Read more

File not found.