From dc4ddbb3e6bb17640222b0e76a7dcfabab77cd60 Mon Sep 17 00:00:00 2001 From: "Jorge vitrubio.net" Date: Wed, 3 Apr 2024 16:38:16 +0200 Subject: [PATCH] added plugin page in admin --- includes/plugin-settings-pannel.php | 318 +++++++++++----------------- xarxaprod-wp-plugin.php | 2 +- 2 files changed, 125 insertions(+), 195 deletions(-) diff --git a/includes/plugin-settings-pannel.php b/includes/plugin-settings-pannel.php index 6b3698d..aba7df6 100644 --- a/includes/plugin-settings-pannel.php +++ b/includes/plugin-settings-pannel.php @@ -19,227 +19,157 @@ /** -* custom option and settings -*/ -if( ! function_exists('xarxaprod_wpplugin_settings_init') ){ - function xarxaprod_wpplugin_settings_init() { - // register a new setting for "xarxaprod_wpplugin" page - register_setting( 'xarxaprod_wpplugin_settings', 'xarxaprod_wpplugin_options' ); + * @internal never define functions inside callbacks. + * these functions could be run multiple times; this would result in a fatal error. + */ - // register a new section in the "xarxaprod_wpplugin" page - add_settings_section( - 'xarxaprod_wpplugin_section_control_home', - __( 'Home control.', 'xarxaprod-wpplugin-textdomain' ), - 'xarxaprod_wpplugin_section_control_home_cb', - 'xarxaprod_wpplugin_settings' - ); +/** + * 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_wpplugin_section_control_home" section, inside the "xarxaprod_wpplugin" page - // - // uncoment below to activate - // add_settings_field( - // 'xarxaprod_wpplugin_field_control_home', // as of WP 4.6 this value is used only internally - // // use $args' label_for to populate the id inside the callback - // __( 'This is the content being shown in home page:', 'xarxaprod-wpplugin-textdomain' ), - // 'xarxaprod_wpplugin_field_control_home_cb', - // 'xarxaprod_wpplugin_settings', - // 'xarxaprod_wpplugin_section_control_home' - // ); - - // register a new section in the "xarxaprod_wpplugin" page - add_settings_section( - 'xarxaprod_wpplugin_section_reusableblocks', - __( 'Reusable blocks.', 'xarxaprod-wpplugin-textdomain' ), - 'xarxaprod_wpplugin_section_reusableblocks_cb', - 'xarxaprod_wpplugin_reusableblocks' - ); - // register a new field in the "xarxaprod_wpplugin_section_reusableblocks" section, inside the "xarxaprod_wpplugin" page - // - // uncoment below to activate - add_settings_field( - 'xarxaprod_wpplugin_field_reusableblocks', // as of WP 4.6 this value is used only internally - // use $args' label_for to populate the id inside the callback - __( 'Follow this link to edit the reusable blocks Reusable blocks', 'xarxaprod-wpplugin-textdomain' ), - 'xarxaprod_wpplugin_field_reusableblocks_cb', - 'xarxaprod_wpplugin_settings', - 'xarxaprod_wpplugin_section_reusableblocks', - - // edit.php?post_type=wp_block - ); - - - // register a new section in the "xarxaprod_wpplugin" page - // - // uncoment below to activate - - // add_settings_section( - // 'xarxaprod_wpplugin_section_olderthandate', - // __( 'Older than options.', 'xarxaprod-wpplugin-textdomain' ), - // 'xarxaprod_wpplugin_section_olderthandate_cb', - // 'xarxaprod_wpplugin_settings' - // ); - - - // register a new field in the "xarxaprod_wpplugin_section_olderthandate" section, inside the "xarxaprod_wpplugin" page - // - // uncoment below to activate - - // add_settings_field( - // 'xarxaprod_wpplugin_field_olderthandate', // as of WP 4.6 this value is used only internally - // // use $args' label_for to populate the id inside the callback - // __( 'Hide content older than...', 'xarxaprod-wpplugin-textdomain' ), - // 'xarxaprod_wpplugin_field_olderthandate_cb', - // 'xarxaprod_wpplugin_settings', - // 'xarxaprod_wpplugin_section_olderthandate', - // [ - // 'label_for' => 'xarxaprod_wpplugin_field_olderthandate', - // 'class' => 'xarxaprod-wpplugin-row', - // 'xarxaprod_wpplugin_custom_data' => 'custom', - // ] - // ); - } + // 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', + ) + ); } +/** + * Register our xarxaprod_plugin_settings_init to the admin_init action hook. + */ +add_action( 'admin_init', 'xarxaprod_plugin_settings_init' ); + /** -* register our xarxaprod_wpplugin_settings_init to the admin_init action hook -*/ -add_action( 'admin_init', 'xarxaprod_wpplugin_settings_init' ); + * Custom option and settings: + * - callback functions + */ + /** -* custom option and settings: -* callback functions -*/ - - - - - -// olderthandate section cb - -// section callbacks can accept an $args parameter, which is an array. -// $args have the following keys defined: title, id, callback. -// the values are defined at the add_settings_section() function. -if( ! function_exists('xarxaprod_wpplugin_section_olderthandate_cb') ){ - function xarxaprod_wpplugin_section_olderthandate_cb( $args ) { - ?> -

- -

- +

+ . -// the "class" key value is used for the "class" attribute of the containing the field. -// you can add custom key value pairs to be used inside your callbacks. -if( ! function_exists('xarxaprod_wpplugin_field_olderthandate_cb') ){ - function xarxaprod_wpplugin_field_olderthandate_cb( $args ) { - // get the value of the setting we've registered with register_setting() - $options = get_option( 'xarxaprod_wpplugin_options' ); - // output the field - ?> - -

- number of days from today to the past or the date from wich will be considered old posts. Then the class oldpost will be added to the post and pages so you can apply a css style to your theme.', 'xarxaprod-wpplugin-textdomain' ); ?> -

-
- - -
-
- - -
- - - - - -. + * - the "class" key value is used for the "class" attribute of the 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' ); + ?> +

+ Reusable Blocks + +

+ . + * - the "class" key value is used for the "class" attribute of the containing the field. + * Note: you can add custom key value pairs to be used inside your callbacks. + * + * @param array $args + */ + /** * top level menu * https://developer.wordpress.org/reference/functions/add_menu_page/ */ -if( ! function_exists('xarxaprod_wpplugin_options_page') ){ - function xarxaprod_wpplugin_options_page() { +if( ! function_exists('xarxaprod_plugin_options_page') ){ + function xarxaprod_plugin_options_page() { // add top level menu page add_menu_page( $page_title = 'Xarxaprod plugin options', // $page_title - $menu_title = 'Xarxaprod options', //$menu_title + $menu_title = 'Xarxaprod', //$menu_title $capability = 'manage_options', //'edit_others_posts', // $capability - $menu_slug = 'xarxaprod-options', // $menu_slug - $function = 'xarxaprod_wpplugin_options_page_html', //$function - $icon_url = 'dashicons-rest-api',// $icon_url //https://developer.wordpress.org/resource/dashicons/#menu + $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 $position = '25'// $position ); } } -// register our xarxaprod_wpplugin_options_page to the admin_menu action hook -add_action( 'admin_menu', 'xarxaprod_wpplugin_options_page' ); -// top level menu: callback functions -if( ! function_exists('xarxaprod_wpplugin_options_page_html') ){ - function xarxaprod_wpplugin_options_page_html() { - // check user capabilities - if ( ! current_user_can( 'manage_options' ) ) { - ?> -

- -

- -
-

-
- -
-
- +
+

+
+ +
+
+