Carl Brubaker
Forum Replies Created
-
Forum: Developing with WordPress
In reply to: ‘separate_items_with_commas’ not showing in UII tried both hierarchical true and false and it didn’t show up. I can accept it isn’t possible.
@bcworkz Thanks, I understand what you meant now, and it is working. Here are my new files:
// main.php if (is_admin()) { require_once plugin_dir_path(__FILE__) . 'activate-deactivate.php'; }
// activate-deactivate.php function my_plugin_on_activation() { if (!current_user_can('activate_plugins')) { return; } $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; check_admin_referer("activate-plugin_{$plugin}"); // other stuff that should happen... } register_activation_hook(WP_PLUGIN_DIR . '/my-plugin/main.php', 'my_plugin_on_activation'); function my_plugin_on_deactivation() { if (!current_user_can('activate_plugins')) { return; } $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; check_admin_referer("deactivate-plugin_{$plugin}"); // other stuff that should happen... } register_deactivation_hook(WP_PLUGIN_DIR . '/my-plugin/main.php', 'my_plugin_on_deactivation');
@bcworkz I think I tried what you said, but that didn’t work either. Here’s the setup:
my-plugin |-main.php |-activate-deactivate.php
// main.php if (is_admin()) { // I tried both of these with the same result require_once plugin_dir_path(__FILE__) . 'activate-deactivate.php'; // or require_once WP_PLUGIN_DIR . '/my-plugin/activate-deactivate.php'; }
// activate-deactivate.php function my_plugin_on_activation() { if (!current_user_can('activate_plugins')) { return; } $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; check_admin_referer("activate-plugin_{$plugin}"); // other stuff that should happen... } register_activation_hook(__FILE__, 'my_plugin_on_activation'); function my_plugin_on_deactivation() { if (!current_user_can('activate_plugins')) { return; } $plugin = isset($_REQUEST['plugin']) ? $_REQUEST['plugin'] : ''; check_admin_referer("deactivate-plugin_{$plugin}"); // other stuff that should happen... } register_deactivation_hook(__FILE__, 'my_plugin_on_deactivation');
Again, these functions work from within main.php, but not when placed in their own file.
- This reply was modified 4 years ago by Carl Brubaker.
Feeling a little dumb, just checked my hidden input and had
name="acion"
instead ofaction
. I tried to delete this thread but couldn’t figure it out.Forum: Developing with WordPress
In reply to: Plugin Location/Structure for wp_enque_style() Admin Page@bcworkz Got it! Thanks!
Forum: Developing with WordPress
In reply to: Plugin Location/Structure for wp_enque_style() Admin Page@joyously yes
my-plugin.php
has the headers.Forum: Developing with WordPress
In reply to: Plugin Location/Structure for wp_enque_style() Admin Page@howdy_mcgee @bcworkz This is what I ended up with in
my-plugin.php
. I tried the@param String $hook
but I couldn’t get it to work after multiple attempts of different iterations I found across the web. I would like to learn it, if possible, as it seems it would be easier and make the code more readable. If you have anymore suggestions towards that I would appreciate it.if (!defined("ABSPATH")) { exit; } if (is_admin()) { require_once plugin_dir_path(__FILE__) . "admin/admin-menu.php"; require_once plugin_dir_path(__FILE__) . "admin/settings-page.php"; } function my_plugin_styles() { if (get_current_screen()->id !== "toplevel_page_my-plugin") { return; } wp_enqueue_style( "custom_wp_admin_css", plugins_url("admin/css/style.css", __FILE__) ); } add_action("admin_enqueue_scripts", "my_plugin_styles");
- This reply was modified 4 years ago by Carl Brubaker.
- This reply was modified 4 years ago by Carl Brubaker.
Forum: Developing with WordPress
In reply to: Plugin Location/Structure for wp_enque_style() Admin PageThanks @joyously, that was the info I was looking for. I guess the index.php was a little redundant.
Thanks @howdy_mcgee as well. That was the information I was finding, but uncertain as to where it was supposed to go.