xarxaprod-wp-plugin/includes/plugin-settings-pannel.php

176 lines
5.7 KiB
PHP
Raw Normal View History

2024-01-09 16:22:35 +01:00
<?php
/**
* Custom settings page
*
* This class defines all code necessary to run during the plugin's activation.
*
* @link https://xarxaprod.cat
* @since 1.0.0
* @package xarxaprod-wp-plugin
* @subpackage xarxaprod-wp-plugin/includes
* @author Jorge - vitrubio.net <jorge@vitrubio.net>
*
* @internal never define functions inside callbacks.
* these functions could be run multiple times; this would result in a fatal error.
* https://developer.wordpress.org/plugins/settings/custom-settings-page/
*/
/**
2024-04-03 16:38:16 +02:00
* @internal never define functions inside callbacks.
* these functions could be run multiple times; this would result in a fatal error.
*/
2024-01-09 16:22:35 +01:00
/**
2024-04-03 16:38:16 +02:00
* custom option and settings
*/
function xarxaprod_plugin_settings_init() {
// Register a new setting for "xxpplugin" page.
register_setting( 'xxpplugin', 'xarxaprod_plugin_options' );
// Register a new section in the "xxpplugin" page.
add_settings_section(
'xarxaprod_plugin_section_options',
__( 'Control de les opcions de la web Xarxaprod', 'xxpplugin' ), 'xarxaprod_plugin_section_options_callback',
'xxpplugin'
);
// Register a new field in the "xarxaprod_plugin_section_options" section, inside the "xxpplugin" page.
add_settings_field(
'xarxaprod_plugin_field_reusableblocks', // As of WP 4.6 this value is used only internally.
// Use $args' label_for to populate the id inside the callback.
__( 'Reusable blocks', 'xxpplugin' ),
'xarxaprod_plugin_field_reusableblocks_cb',
'xxpplugin',
'xarxaprod_plugin_section_options',
array(
'label_for' => 'xarxaprod_plugin_field_reusableblocks',
'class' => 'xarxaprod_plugin_row',
'xarxaprod_plugin_custom_data' => 'custom',
)
);
}
2024-01-09 16:22:35 +01:00
/**
2024-04-03 16:38:16 +02:00
* Register our xarxaprod_plugin_settings_init to the admin_init action hook.
*/
add_action( 'admin_init', 'xarxaprod_plugin_settings_init' );
2024-01-09 16:22:35 +01:00
2024-04-03 16:38:16 +02:00
/**
* Custom option and settings:
* - callback functions
*/
2024-01-09 16:22:35 +01:00
2024-04-03 16:38:16 +02:00
/**
* Xarxaprod section callback function.
*
* @param array $args The settings array, defining title, id, callback.
*/
function xarxaprod_plugin_section_options_callback( $args ) {
?>
<p id="<?php echo esc_attr( $args['id'] ); ?>"><?php esc_html_e( 'Aquestes son las opcions de la pagina Xarxaprod 2023. Pots modificar i pots seguir els links dels botons.', 'xxpplugin' ); ?></p>
<?php
2024-01-09 16:22:35 +01:00
}
2024-04-03 16:38:16 +02:00
/**
* Reusable Blocks field callbakc function.
*
* WordPress has magic interaction with the following keys: label_for, class.
* - the "label_for" key value is used for the "for" attribute of the <label>.
* - the "class" key value is used for the "class" attribute of the <tr> containing the field.
* Note: you can add custom key value pairs to be used inside your callbacks.
*
* @param array $args
*/
function xarxaprod_plugin_field_reusableblocks_cb( $args ) {
// Get the value of the setting we've registered with register_setting()
$options = get_option( 'xarxaprod_plugin_options' );
?>
<p class="">
<a href="<?php echo admin_url(); ?>edit.php?post_type=wp_block" class="button">Reusable Blocks</a>
<?php esc_html_e( 'Si vols modificar els blocks reutilizables (els de color violeta) de las págines i entrades, fes click al botó.', 'xxpplugin' ); ?>
</p>
<?php
2024-01-09 16:22:35 +01:00
}
2024-04-03 16:38:16 +02:00
/**
* Lite Youtube Embed field callbakc function.
* https://wordpress.org/plugins/lite-embed-for-youtube
* https://github.com/paulirish/lite-youtube-embed
*
* WordPress has magic interaction with the following keys: label_for, class.
* - the "label_for" key value is used for the "for" attribute of the <label>.
* - the "class" key value is used for the "class" attribute of the <tr> containing the field.
* Note: you can add custom key value pairs to be used inside your callbacks.
*
* @param array $args
*/
2024-01-09 16:22:35 +01:00
/**
* top level menu
* https://developer.wordpress.org/reference/functions/add_menu_page/
*/
2024-04-03 16:38:16 +02:00
if( ! function_exists('xarxaprod_plugin_options_page') ){
function xarxaprod_plugin_options_page() {
2024-01-09 16:22:35 +01:00
// add top level menu page
add_menu_page(
$page_title = 'Xarxaprod plugin options', // $page_title
2024-04-03 16:38:16 +02:00
$menu_title = 'Xarxaprod', //$menu_title
2024-01-09 16:22:35 +01:00
$capability = 'manage_options', //'edit_others_posts', // $capability
2024-04-03 16:38:16 +02:00
$menu_slug = 'xxpplugin-options', // $menu_slug
$function = 'xarxaprod_plugin_options_page_html', //$function
$icon_url = 'dashicons-sos',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu
2024-01-09 16:22:35 +01:00
$position = '25'// $position
);
}
}
2024-04-03 16:38:16 +02:00
/**
* Register our xarxaprod_plugin_options_page to the admin_menu action hook.
*/
add_action( 'admin_menu', 'xarxaprod_plugin_options_page' );
/**
* Top level menu callback function
*/
function xarxaprod_plugin_options_page_html() {
// check user capabilities
if ( ! current_user_can( 'manage_options' ) ) {
return;
}
// add error/update messages
// check if the user have submitted the settings
// WordPress will add the "settings-updated" $_GET parameter to the url
if ( isset( $_GET['settings-updated'] ) ) {
// add settings saved message with the class of "updated"
add_settings_error( 'xarxaprod_plugin_messages', 'xarxaprod_plugin_message', __( 'Settings Saved', 'xxpplugin' ), 'updated' );
}
// show error/update messages
settings_errors( 'xarxaprod_plugin_messages' );
?>
<div class="wrap">
<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
<form action="options.php" method="post">
<?php
// output security fields for the registered setting "xxpplugin"
settings_fields( 'xxpplugin' );
// output setting sections and their fields
// (sections are registered for "xxpplugin", each field is registered to a specific section)
do_settings_sections( 'xxpplugin' );
// output save settings button
//submit_button( 'Save Settings' );
?>
</form>
</div>
<?php
2024-01-09 16:22:35 +01:00
}