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
- can not serialize and insert data from custom form
- I would like to use create a function in my custom plugin to tell WP to use a different header
- How to edit/delete single row items in a table on my own menu page
- Getting media library popup in custom plugin admin page
- Create or Update thousands of woocommerce products via PHP
- send_headers don’t work on wordpress multisite
- jQuery function didn’t work in my plugin
- Sanitizing, Validating and Escaping in WordPress (Plugin)
- Get total number of comment of the posts written by an author
- Escape when echoed
- Scope for PHP Variables Assigned in functions.php or a plugin
- Plugin exceeds memory limit
- How to write one comment and publish on every post using database or plugin?
- Default Plugin Settings Not Writing to Database
- Make id column as AUTO INCREMENT on plugin activation
- Write to / remove from default .htaccess file from plugin?
- Update Option Error: Notice: Undefined index
- Plugin Development sqlite or WordPress’ database
- How to cancel WordPress’ action/filter when using OOP with anonymous callback
- WordPress Plugin Page is Loading in Admin Content Container Instead of Separate Page
- How to trigger $_GET request within admin plugin page?
- Building an email signup form. Where should the information be saved in the DB?
- How to generate video out of images via WordPress plugin
- How can I get WordPress to save comments in markdown format?
- WooCommerce get_price returning wrong price when used via ajax
- How to ‘clone’ a wp plugin to make small changes
- Open Post Thumbnail in New Child Theme File in WordPress
- Where should I save an API key of my user when installing my plugin?
- Is Wrapping intval() Around esc_attr() Redundant for Escaping Input?
- Programatically download a plugin
- Redirecting to home page after login as custom role WordPress
- Add keywords meta to index.php page
- Custom form action to handle data inside a plugin
- Self deactivate plugins after an action occurs
- Pulling data from custom plugin settings using PHP shortcode and Javascript
- Plugin Options Not Saving to Database in WP 4.5
- How to periodically scrape and cache strings from remote txt files. – My First Plugin
- WP Post Template – Templates in own folder
- Doubt using $wpbd->get_col for a single column
- Avoid class name collision when using third party libraries in plugins?
- Access WordPress database outside of WordPress
- How to create custom tables in WordPress using my own plugin?
- wordpress plugin is not activating from widget
- How to access data in wordpress database externally using php
- Correct way to perform non-cacheable DB query
- Is it possible to create Custom Post plug-in?
- Edit Yoast SEO breadcrumbs output [closed]
- How would I go about creating a user ranked post popularity page?
- Creating mySQL procedure with $wpdb
- Redirection of users away from wp-admin (but not administrators)
- Using a custom plugin to capture input data via Ajax and PHP
- code is working properly in Core PHP but writing coding in WordPress
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- Prevent duplicate records in plugin table
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Image upload and download from front-end
- Change commission_status paid when withdraw_status vendor is completed
- wp_remote_get() returns 403 while file_get_contents() does not
- How to output CMB2 select options from repeated groups select elements?
- Creating a Callback URL for WordPress Woocommerce to update Order Status
- Update results, Before deleting the related category [closed]
- 306 MB of wp_options occupied by WordPress SEO Plugin, is that normal? [closed]
- What are the specifics of WordPress development I need to know? [closed]
- Ajax call returning 0
- How to deal with WordPress and Pocket API to automate content curation on my hosted wordpress blog? [closed]
- WP All Import – Execute Imports
- WordPress Backend HA (Automatic failover)
- How to replace WordPress Media Upload Window with user’s device window?
- Conditional attributes and logic per product category
- How can I change the meta_key for a particular piece of information?
- Create a table with wordpress plugin boilerplate
- How to create a custom post type that contains another custom post type?
- Perform internal redirect in WordPress?
- How to prevent plugins from loading jQuery
- How can I save the selected page in the dropdown after anyone clicks on Save Changes?
- How to check record is exist or not in WordPress CRUD Operation with $wpdb
- How to override plugin function in code snippets WordPress
- How to make a Template page to show the information of different things Shop and Product page?
- How to create a “Most Popular” & “Latest” TAB in WordPress
- How to trigger plugin migration code when plugin updates?
- How to Save Category and Delete Category in same Function
- WordPress Throwing Deprecated Errors on its own Files
- public custom posts not showing in my wordpress plugin
- Use inline callable for hooks and filters
- Error in using ‘admin_enqueue_scripts’ action through a class
- Accessing Correct Database to Create REST API Endpoint
- Mixed results with is_page() WordPress function, when using $this, or self
- add_action() not working for admin
- REST API – filters not working inside plugin class
- Read page- or post-content across different builder-plugins
- How to make WordPress Plugin run on single specific Admin Page
- WordPress site server getting blocked due to resource abuse