first commit
This commit is contained in:
120
sso-wordpress-plugin/sso-wordpress-plugin.php
Normal file
120
sso-wordpress-plugin/sso-wordpress-plugin.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: SSO Login Button
|
||||
* Description: Adds a shortcode to display an SSO login button.
|
||||
* Version: 1.0.0
|
||||
* Author: Gemini
|
||||
* License: GPL-2.0-or-later
|
||||
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* Text Domain: sso-login-button
|
||||
*/
|
||||
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit; // Exit if accessed directly.
|
||||
}
|
||||
|
||||
// Will add plugin code here.
|
||||
|
||||
/**
|
||||
* Shortcode function to display the SSO login button.
|
||||
*
|
||||
* @return string The HTML for the login button.
|
||||
*/
|
||||
function sso_login_button_shortcode() {
|
||||
// The button HTML. The actual script will be enqueued separately.
|
||||
return '<button id="sso-login-btn">Login with SSO</button>';
|
||||
}
|
||||
add_shortcode( 'sso_login_button', 'sso_login_button_shortcode' );
|
||||
|
||||
/**
|
||||
* Enqueue scripts and styles.
|
||||
*/
|
||||
function sso_enqueue_scripts() {
|
||||
// Only enqueue the script if the shortcode is present on the page.
|
||||
// Note: This is a simplified check. A more robust solution might be needed for complex cases.
|
||||
global $post;
|
||||
if ( is_a( $post, 'WP_Post' ) && has_shortcode( $post->post_content, 'sso_login_button' ) ) {
|
||||
wp_enqueue_script(
|
||||
'sso-login-script',
|
||||
plugin_dir_url( __FILE__ ) . 'js/sso-login.js',
|
||||
array(),
|
||||
'1.0.0',
|
||||
true
|
||||
);
|
||||
|
||||
// Pass the SSO URL to the script.
|
||||
// We'll make this dynamic with a settings page later.
|
||||
$sso_url = get_option('sso_plugin_url', 'http://localhost:5000/');
|
||||
wp_localize_script(
|
||||
'sso-login-script',
|
||||
'ssoSettings',
|
||||
array(
|
||||
'ssoUrl' => esc_url( $sso_url ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
add_action( 'wp_enqueue_scripts', 'sso_enqueue_scripts' );
|
||||
|
||||
/**
|
||||
* Admin Menu and Settings
|
||||
*/
|
||||
|
||||
// Add the settings page to the admin menu
|
||||
function sso_plugin_add_settings_page() {
|
||||
add_options_page(
|
||||
'SSO Settings',
|
||||
'SSO Login',
|
||||
'manage_options',
|
||||
'sso-plugin-settings',
|
||||
'sso_plugin_render_settings_page'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_menu', 'sso_plugin_add_settings_page' );
|
||||
|
||||
// Render the settings page HTML
|
||||
function sso_plugin_render_settings_page() {
|
||||
?>
|
||||
<div class="wrap">
|
||||
<h1>SSO Login Settings</h1>
|
||||
<form action="options.php" method="post">
|
||||
<?php
|
||||
settings_fields( 'sso_plugin_options' );
|
||||
do_settings_sections( 'sso_plugin_settings' );
|
||||
?>
|
||||
<input
|
||||
type="text"
|
||||
name="sso_plugin_url"
|
||||
value="<?php echo esc_attr( get_option( 'sso_plugin_url' ) ); ?>"
|
||||
size="50"
|
||||
placeholder="Enter the full SSO URL"
|
||||
/>
|
||||
<?php submit_button( 'Save Settings' ); ?>
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
// Register the setting
|
||||
function sso_plugin_register_settings() {
|
||||
register_setting(
|
||||
'sso_plugin_options',
|
||||
'sso_plugin_url',
|
||||
[
|
||||
'type' => 'string',
|
||||
'sanitize_callback' => 'esc_url_raw',
|
||||
'default' => '',
|
||||
]
|
||||
);
|
||||
|
||||
add_settings_section(
|
||||
'sso_plugin_main_section',
|
||||
'Main Settings',
|
||||
null,
|
||||
'sso_plugin_settings'
|
||||
);
|
||||
}
|
||||
add_action( 'admin_init', 'sso_plugin_register_settings' );
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user