-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: settings section for openedx plugin configuration (#23)
* feat: submenu in settings section for openedx config * fix: added visibility to functions * fix: jwt token input disabled * feat: custom sanitize function for url * docs: add documentation for custom sanitize url * refactor: deleted temporary value in jwt token input * refactor: deleted spanish comment in css file * refactor: sanitazing fields with native wordpress function * refactor: direct call to sanitize function
- Loading branch information
1 parent
a54a653
commit 10a31c3
Showing
3 changed files
with
274 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
<?php | ||
|
||
namespace App\admin\views; | ||
|
||
class Openedx_Woocommerce_Plugin_Settings | ||
{ | ||
|
||
/** | ||
* Add the plugin settings submenu page. | ||
* | ||
* Registers a new administration submenu page under the Settings menu | ||
* for the Open edX plugin settings. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_settings_submenu() | ||
{ | ||
add_submenu_page( | ||
'options-general.php', | ||
'Open edX Settings', | ||
'Open edX Sync', | ||
'manage_options', | ||
'openedx-settings', | ||
array($this, 'openedx_settings_page') | ||
); | ||
} | ||
|
||
/** | ||
* Output the plugin settings page. | ||
* | ||
* Renders the form and fields for the Open edX plugin settings page. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_settings_page() | ||
{ | ||
?> | ||
<div class="wrap"> | ||
<h2>Open edX Settings</h2> | ||
<form method="post" action="options.php"> | ||
<?php settings_fields('openedx-settings-group'); ?> | ||
<?php do_settings_sections('openedx-settings'); ?> | ||
<?php submit_button(); ?> | ||
</form> | ||
</div> | ||
<?php | ||
} | ||
|
||
/** | ||
* Register settings and fields. | ||
* | ||
* Uses the Settings API to register the settings section, fields, and options | ||
* for the Open edX plugin configuration. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_settings_init() | ||
{ | ||
add_settings_section( | ||
'openedx-settings-section', | ||
'', | ||
array($this, 'openedx_settings_section_callback'), | ||
'openedx-settings' | ||
); | ||
|
||
add_settings_field( | ||
'openedx-domain', | ||
'Open edX Domain', | ||
array($this, 'openedx_domain_callback'), | ||
'openedx-settings', | ||
'openedx-settings-section' | ||
); | ||
|
||
add_settings_field( | ||
'openedx-client-id', | ||
'Client id', | ||
array($this, 'openedx_client_id_callback'), | ||
'openedx-settings', | ||
'openedx-settings-section' | ||
); | ||
|
||
add_settings_field( | ||
'openedx-client-secret', | ||
'Client secret', | ||
array($this, 'openedx_client_secret_callback'), | ||
'openedx-settings', | ||
'openedx-settings-section' | ||
); | ||
|
||
add_settings_field( | ||
'openedx-jwt-token', | ||
'JWT Token', | ||
array($this, 'openedx_jwt_token_callback'), | ||
'openedx-settings', | ||
'openedx-settings-section' | ||
); | ||
|
||
register_setting( | ||
'openedx-settings-group', | ||
'openedx-domain', | ||
'sanitize_url' | ||
); | ||
|
||
register_setting( | ||
'openedx-settings-group', | ||
'openedx-client-id', | ||
'sanitize_text_field' | ||
); | ||
|
||
register_setting( | ||
'openedx-settings-group', | ||
'openedx-client-secret', | ||
'sanitize_text_field' | ||
); | ||
|
||
register_setting( | ||
'openedx-settings-group', | ||
'openedx-jwt-token', | ||
'sanitize_text_field' | ||
); | ||
} | ||
|
||
/** | ||
* Output the domain settings field. | ||
* | ||
* Retrieves the saved domain value and outputs an input field and description text. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_domain_callback() | ||
{ | ||
$value = get_option( 'openedx-domain' ); ?> | ||
|
||
<input type="text" name="openedx-domain" id="openedx-domain" | ||
value="<?php echo esc_attr( $value ); ?>" required /> | ||
|
||
<p class='description'>Your Open edX platform's web address.</p> | ||
|
||
<?php | ||
} | ||
|
||
/** | ||
* Output the client ID settings field. | ||
* | ||
* Retrieves the saved client ID value and outputs an input field and description text. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_client_id_callback() | ||
{ | ||
$value = get_option( 'openedx-client-id' ); ?> | ||
|
||
<input type="text" name="openedx-client-id" id="openedx-client-id" | ||
value="<?php echo esc_attr( $value ); ?>" required /> | ||
|
||
<p class="description">Identifier for OAuth application in your Open edX | ||
platform.</p> | ||
|
||
<?php | ||
} | ||
|
||
/** | ||
* Output the client secret settings field. | ||
* | ||
* Retrieves the saved client secret value and outputs a password input field and description text. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_client_secret_callback() | ||
{ | ||
|
||
$value = get_option( 'openedx-client-secret' ); ?> | ||
|
||
<input type="text" name="openedx-client-secret" id="openedx-client-secret" | ||
value="<?php echo esc_attr( $value ); ?>" required /> | ||
|
||
<p class="description"> | ||
Confidential key for OAuth application in your Open edX platform. | ||
</p> | ||
|
||
<?php | ||
} | ||
|
||
/** | ||
* Output the JWT token settings field. | ||
* | ||
* Retrieves the saved JWT token value and outputs a text input field, generate token button, | ||
* and description text. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_jwt_token_callback() | ||
{ | ||
?> | ||
|
||
<div class="openedx-jwt-token-wrapper"> | ||
|
||
<input class="openedx-jwt-token-input" type="text" name="openedx-jwt-token" id="openedx-jwt-token" | ||
value="" disabled/> | ||
|
||
<button class="button" type="button" id="generate-jwt-token">Generate JWT Token</button> | ||
|
||
</div> | ||
|
||
<p class="description"> Select the Generate Token button to obtain a JWT Token. </p> | ||
|
||
<?php | ||
} | ||
|
||
/** | ||
* Output introductory text for the settings section. | ||
* | ||
* Echoes text prompting the user to fill in and save the settings. | ||
* | ||
* @return void | ||
*/ | ||
public function openedx_settings_section_callback() | ||
{ | ||
printf( 'Configuring the necessary parameters here to establish | ||
the connection between this plugin and your Open edX platform.'); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters