To get you started, I’ve included a quick revision of your code, simplified, standardized, and with recommendations for security. There are some commented notes in the code for you to consider as you move forward.
<?php
/*
Plugin Name: My Plugin
Description: My plugin
Author: gigasize777 + Little Package
Version: 1.0
*/
defined( 'ABSPATH' ) || exit;
if ( ! class_exists( 'MP_Test_Plugin' ) ) :
class MP_Test_Plugin {
public function __construct() {
add_action( 'admin_menu', array( $this, 'setup_menu' ) );
add_action( 'admin_init', array( $this, 'register_options' ) );
}
public function setup_menu() {
// add_menu_page( string $page_title, string $menu_title, string $capability, string $menu_slug, callable $function = '', string $icon_url = '', int $position = null )
add_menu_page( 'Test Plugin Page', 'Test Plugin', 'manage_options', 'test-plugin', array( $this, 'test_menu_page' ), 'dashicons-smiley' );
}
public function test_menu_page() {
// you'll definitely want to check user privs and nonces here
if ( isset( $_POST['option_page'] ) && $_POST['option_page'] == 'mp_settings_group' ) {
if ( isset( $_POST['test_init'] ) ) {
update_option( 'test_init', 'yes' );
} else {
update_option( 'test_init', 'no' );
}
}
$test_option = get_option( 'test_init', 'no' );
?>
<div class="wrap">
<h1>Plugin</h1>
<!-- should NONCE this form -->
<form method="post"> <!-- action="options.php" will redirect you to options page on submit -->
<?php settings_fields( 'mp_settings_group' ); ?>
<?php do_settings_sections( 'mp_settings_group' ); ?>
<input type="checkbox" name="test_init" value="<?php echo $test_option; ?>" <?php checked( $test_option, 'yes' ); ?> id="test_init" /><label for="test_init"> We're good?</label>
<?php submit_button(); ?>
</form>
</div>
<?php
if ( $test_option == 'yes' ) {
echo 'We\'re good.';
} else {
echo 'Don\'t leave me hanging';
}
}
public function register_options() {
register_setting( 'mp_settings_group', 'test_init' ); // settings group for if you want to register group styling with WP later
}
}
endif;
if ( is_admin() ) { // let's only run this plugin on the WP backend
new MP_Test_Plugin();
}
thank you very much Little Package for your help, now i trying to change the style of the login page of wordpress i have added this code but doesn’t work:
if ( $test_option == 'yes' ) {
echo 'We\'re good.';
wp_enqueue_style( 'custom-login', plugins_url("/css/style-login.css", __FILE__ ));
add_action( 'login_enqueue_scripts', 'my_login_stylesheet' );
} else {
echo 'Don\'t leave me hanging';
}
}
@gigasize777
Sorry, your last post proves to me you need to hire professional help at this point. Check out: https://jobs.wordpress.net/post-a-job/
This forum is not the place to get custom code built for you for free. Sorry to be blunt, but it seems like you have not at all read what myself and another poster (on your duplicate post) have already told you.
Good luck on your project!
thank you again Dear Little Package for you response, I’m really sorry for having done a double post but I did it because another user told me that I should pay a large amount of money to teach me how to make practically a “hello world” application in WordPress, I’m from Venezuela and the highest salary for a professional here is $10/month, here people fight every day to survive, I know that all this is not your problem, but I want you to know that if I had the money I would pay it to you, I thought at the beginning that as WordPress was free software and support was too, I didn’t know that the WordPress forum was paid for simple questions like a “hello world” and non complete applications, I just want to learn that is my motivation.
Keep studying @gigasize777 — and best of luck to you!
@gigasize777 – You wrote
I didn’t know that the WordPress forum was paid for simple questions…
The WordPress Forums most certainly are not for pay. Soliciting payment in these forums is against our guidelines. While we cannot control what happens outside these forums, we strongly urge members to never engage with anyone soliciting payment in exchange for assistance as a result of any topic in these forums. If you want to hire someone, only interact with those where you initiated contact.
These forums are operated entirely by volunteers. No one is paid to help here, everyone has their own reasons to volunteer without compensation. As such, each member decides for themselves how much assistance they’ll provide. Some will do much more coding than others to help out.
Keep on learning for yourself. If you get stuck on something by all means seek the free assistance here. Bear in mind though that targeted, specific issues are more likely to be answered here. Wide ranging, open ended topics and asking for significant, complete coding solutions are less likely to be answered.