There is an error here. You’ve not declared _register_hooks() method.
And I instantiated the class like below-
global $p;
if(empty($p)){
$p = plugin::getInstance();
$p->activate();
}
And it worked. For your case that has not worked cause WordPress uses a variable with name $plugin in its life cycle. And your code checks it’s empty or not. Obviously it’s not gonna be empty. So your $plugin = plugin::getInstance(); never executed. For using this singleton pattern your better declare the variable $plugin with a different name. Like I declared it as $p here. Better you prefix with something unique. Hope that suggestion helps you.
Related Posts:
- Include WP_Query in my own PHP file?
- When to use Exceptions vs Error Objects vs just plain false/null
- WordPress URL Rewrite not working
- How to use update and delete query in wordpress
- add_meta_boxes action with refresh on save
- simple wordpress ajax plugin not working when not logged in
- Resize Image without cropping
- how to create and show sessions in word press?
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- When is is_admin() available?
- New Plugin Review
- Create custom blocks for bootstrap
- Hiding WordPress Plugin Source Code
- wp_insert_post() is returning the correct post ID, no failure, but the post content does not get updated
- wp_loaded hook block script enquequing
- Custom filter in admin edit custom post type responding with invalid post type?
- WordPress Scheduled Event Request Blocking
- How to find error in my code when the error message is pointing to WP core file?
- How to access global variable $menu inside a class function
- How to set up VS Code for WP plugin/theme development in 2021? [closed]
- Custom user login page by creating a plugin
- Singelton class does not work, multiple initialization on page reload
- Saving an array of dynamic repeater data as post_meta
- WordPress wpform plugin submit and get multiple checked value from checkbox [closed]
- How to upload a file to a folder named after the user_id via plugin
- developing a wordpress plugin, have a few PHP Woocommerce related coding questions
- Whitelisting items from custom options page
- Add_menu_page not displaying the menu in class based plugin
- Script to browser problem PHP
- adjust section according to country?
- wp query foreach deleting record returning only first or last item
- PHP > Scheduled Tasks > Sending daily email with dynamic API variables
- how to update and display an option without reloading the page
- How to obtain the current website URL in my theme?
- Plugin Generate Unexpected output during activation
- Undefined method class::construct() when creating a plugin
- Hook called before text widget save
- plugin add action hook is not working :
- wpdb prepare insert table doesn’t work
- wordpress admin plugin menu custom css
- Using admin-post.php for admin form but it directs me to admin-post.php white screen
- Hooks for post saving make a post-new.php to load latest post’s data
- How can I display Custom Post type Custom Columns and its Content in a Dashboard Widget?
- custom plugin with upload files does not work
- Using flickr api in custom wordpress plugin
- Toolbar Hidden in a Virtual Page
- What is the difference between Null vs Empty (Zero Length) string?
- PHP: $_SESSION destroyed after page reload for my custom session
- send popup after wp_redirect()
- no_rest_route error on custom routes
- Payment field disappears on custom Paypal plugin
- Adding image upload in tag section – WordPress plugin development
- Create ACF Checkbox to get all ACF Values from Parent Page
- How to Send Pingbacks for all Posts in WordPress?
- I am having errors with checkout on wordpress
- File is executed twice if plugin is activating
- product_type_options get saved value [closed]
- Display a custom name when the user has no name settle in his account
- How can I update the price when someone enters postcode or zip code in woocommerce checkout page?
- Sum All the Post Meta of Published posts of Current Logged in user
- Update user meta when an external link in admin notice is clicked
- Is there an option to execute javascript file only on plugin activation
- How do I remove an action hook inside a class that is called by another class?
- Autoloading Classes in Plugins
- Ajax in a class instantiated via shortcode
- Parsing webhook from Shopify in WordPress
- Comparing Dates within plugin using PHP If statement
- Shortcode Works for Logged in Users but Not Working for Guest
- Submit to itself don’t work
- WordPress / PhpStorm / XDebug and plugin_dir_path issues
- Unable to pass variable to database
- Send data from plugin to external database
- Add custom filter to register data in array
- See output of a sql query while plugin installation in wordpress
- Why this plugin is not working?
- Permission error on plugin save
- Trouble using wordpress functions in a pop-up modal form
- How to execute add_action() function from custom plugin to Crontrol plugin or do_action()?
- MySQL update text field with ‘
- how can I make content from a plugin hidden when user is logged in? [duplicate]
- base64_encode conflict with convert_smilies in wordpress
- Properly process a custom WP REST API request (Authenticate, Authorize + Validate)?
- Implement OAuth2 in custom plugin
- login redirect based on user role not work as expected
- redirect user from login page if is logged
- How to pass and validate nonce in custom REST routes
- How to lock users account until approvation
- Variable ++ in query loop
- ajax problems on loading page [closed]
- WordPress REST API – Custom field not added to pages
- Compare user meta values before update them
- Capture the Selected Radio Button Value between two files in wordpress theme
- Cannot register a custom WP-CLI command
- How to change product SKU’s in bulk with a plugin
- JQuery UI Autocomplete showing as bullets
- Why does WordPress not make use of gettext directly?
- Trouble with WordPress Settings API: Form Submits When Fields Called Directly, Fails When Using Callbacks
- Add Imports to Existing WordPress Import Map
- How can I catch WordPress custom settings page slug has already changed?
- Custom plugin with dynamic child pages listing database records