plugin_dir_url()
returns the URL directory path for your plugin, so this won’t work as expected (the function won’t be called):
register_activation_hook(plugin_dir_url(__FILE__) . 'frequentVisitorCoupons.php',
'Utilities::createTablesIfNotExists');
You should have used plugin_dir_path()
which returns the file-system directory path for your plugin (e.g. /var/www/public/<user>/wp-content/plugins/your-plugin/
).
But if the code is in the main plugin file, then you could simply use __FILE__
:
register_activation_hook(__FILE__, 'Utilities::createTablesIfNotExists');
Sample plugin main file:
<?php
/*
* Plugin Name: My Plugin
*/
require_once 'path/to/classes/utilities.php';
// Installs the tables on plugin activation.
register_activation_hook( __FILE__, 'Utilities::createTablesIfNotExists' );
Related Posts:
- Help With MySQL to WPDB Query Conversion
- WPDB: Update table
- How to create plugin/ page that reads from database
- Comment “like” problem – “users who like this” avatar linking to current user profile instead of “liker’s” profile
- How to display results from a data table with an encrypted user id?
- How to securely controlling data without keeping it in postmeta?
- Using id to show item
- plugin doesn’t retrieve data from database
- Problems with autoloading classes via sp_autoload_register / maybe interfering WP-specific autoloader
- How to remove duplicate sub-menu name for top level menu items in a plugin?
- category_name not working (not showing up in sql query debug)
- How can I make my custom shortcode work in a Custom HTML Widget?
- How to Loop Plugin Option Field Set?
- Update Multiple Post Meta for the Same Post In One call?
- How do I configure WordPress to talk to a Microsoft SQL Server database?
- Rename existing old uploaded images containing accented French characters (not during upload)
- How to Create a Directory in a Plugin Folder?
- Ajax call doesn’t work in frontend but it’s working in backend (when I’m logged in)
- Create plugin that works in background
- Checking for user role in a custom plugin
- WordPress register_activation_hook table creation not working
- HELP: Integrating WP with raw PHP code once published button is hit
- Loading class files via autoload method
- I would like to use create a function in my custom plugin to tell WP to use a different header
- Getting media library popup in custom plugin admin page
- jQuery function didn’t work in my plugin
- Get total number of comment of the posts written by an author
- Escape when echoed
- How to write one comment and publish on every post using database or plugin?
- Make id column as AUTO INCREMENT on plugin activation
- Write to / remove from default .htaccess file from plugin?
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- How to create custom tables in WordPress using my own plugin?
- Correct way to perform non-cacheable DB query
- How would I go about creating a user ranked post popularity page?
- WordPress Backend HA (Automatic failover)
- Redirect to another page using contact form 7? [closed]
- Create a plugin from within WordPress
- Class variables not correct on page
- Why is one phpunit test throwing an error on one class when all other classes are similar without error?
- Is it necessary to auto delete my WP plugin database tables when users deactivate/delete my plugin?
- Activate my plugins via FTP
- How to insert and call new data in wordpress website database through a plugin
- Why is my custom post type not being activated on plug-in activation?
- How to add apply_filter for a class property in plugin
- Separate database for a wordpress plugin
- How to make multiple admin pages for one plugin?
- A server-side hook failed when committing plugin code to SVN
- Content-Security-Policy Headers are there and showing the correct settings, but still getting a refused connection
- What is the WordPress approach to custom data?
- How to delete all categories programatically?
- How to use custom Javascript code inside a plugin?
- How to add/change (woocommerce) product tab icon
- I want to generate the pdf and save it in library?
- Using meta_query in a WP_Query not working for numbers properly
- How to write to a separate PHP file in plugin settings
- How to access the WordPress DB from a plugin file
- Create “new pages” within the admin section of plugin
- More gentle way to hook WordPress custom url
- add_action for publish_post doesn’t work
- How to Call Specific .PHP file on add_submenu_page selection in Plugin Development?
- How to Add text value in Automatically in this conditions?
- Checkbox show / hide output result
- admin_notices show after load completed
- How can we get this dynamically as this folder may not be by the same name always → wp-admin
- Cant create table on plugin activation
- Custom Plugin: How to Include Install Buttons of other 3rd Party Plugins?
- Hide content for specific users with id
- adding dynamic/multiple slug values in ‘option_none_value’
- Why is my shortcode not working?
- Getting Fatal error: Uncaught Error: Call to undefined function plugin_dir_path() when linking to another file within my wordpress plugin
- How can I see $post object in frontend from functions.php?
- Move plugin pages from dashboard to front-end
- Moving a few select DB tables to a new WP instance
- implement checkbox or toggle switch in plugin code
- 500 Internal server error wp_handle_upload_prefilter
- Create a form and have custom menu display based on user answers?
- Can’t access 3rd party API, code works on local server but not on wordpress
- Get post content inside plugin class method
- Problem with conditional woocommerce custom checkout field
- Where do the section input fields values are stored in database
- How to limit each front-end user to view just his own uploaded files on Amazon S3?
- How can I insert a record into a custom table from my custom form in my custom admin page?
- How to save information related to post in database?
- Saving plugin data returns “You do not have sufficient permissions to access this page.”
- How to add a handler for a button in plugin?
- Can anyone tell me why I can’t edit a plugin when it is installed without having to re-install?
- Creating fields in the database
- Load my plugin before cache
- How to fix ‘Call to undefined function do_settings()’ error?
- wordpress select multiple options and illegal string offset ‘timeslot’ [closed]
- how to search through plugin in wordpress cimy-user-extra-fields?
- Get all the related data from WordPress DB
- get_option returning a different value from what’s saved
- Function not being called on form submit, only blank admin-post.php page
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- WordPress Throwing Deprecated Errors on its own Files