From faf1ba3e33675bb79326423908049b9891850574 Mon Sep 17 00:00:00 2001 From: "Rafasashi\\Raphael" Date: Thu, 27 Jul 2023 11:12:13 +0545 Subject: [PATCH] admin api updated --- ...ass-wordpress-plugin-template-settings.php | 2 +- ...ss-wordpress-plugin-template-admin-api.php | 55 ++++++++++--------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/includes/class-wordpress-plugin-template-settings.php b/includes/class-wordpress-plugin-template-settings.php index 2e058e8..2c2a575 100644 --- a/includes/class-wordpress-plugin-template-settings.php +++ b/includes/class-wordpress-plugin-template-settings.php @@ -71,7 +71,7 @@ public function __construct( $parent ) { add_action( 'admin_menu', array( $this, 'add_menu_item' ) ); // Add settings link to plugins page. - add_filter( 'plugin_action_links',array($this,'add_settings_link'),10,2); + //add_filter( 'plugin_action_links',array($this,'add_settings_link'),10,2); // Configure placement of plugin settings page. See readme for implementation. add_filter( $this->base . 'menu_settings', array( $this, 'configure_settings' ) ); diff --git a/includes/lib/class-wordpress-plugin-template-admin-api.php b/includes/lib/class-wordpress-plugin-template-admin-api.php index d8ea7b0..99992e7 100644 --- a/includes/lib/class-wordpress-plugin-template-admin-api.php +++ b/includes/lib/class-wordpress-plugin-template-admin-api.php @@ -39,39 +39,42 @@ public function display_field( $data = array(), $post = null, $echo = true ) { } // Check for prefix on option name. - $option_name = ''; - if ( isset( $data['prefix'] ) ) { - $option_name = $data['prefix']; - } - - // Get saved data. + + $option_name = ( isset( $data['prefix'] ) ? $data['prefix'] : '' ) . ( !empty($field['name']) ? $field['name'] : $field['id']); + + // Get default + + $default = isset($field['default']) ? $field['default'] : null; + + // Get saved data + $data = ''; - if ( $post ) { + + if ( !empty( $field['data'] ) ) { + + $data = $field['data']; + } + elseif ( $post ) { // Get saved field data. - $option_name .= $field['id']; - $option = get_post_meta( $post->ID, $field['id'], true ); - - // Get data to display in field. - if ( isset( $option ) ) { - $data = $option; - } - } else { + + $data = get_post_meta( $post->ID, $field['id'], true ); + } + else { // Get saved option. - $option_name .= $field['id']; - $option = get_option( $option_name ); - - // Get data to display in field. - if ( isset( $option ) ) { - $data = $option; - } + + $data = get_option( $option_name,$default ); } - // Show default data if no option saved and default is supplied. - if ( false === $data && isset( $field['default'] ) ) { - $data = $field['default']; - } elseif ( false === $data ) { + // Show default data if no option saved and default is supplied + + if( $data === '' && !is_null($default) ) { + + $data = $default; + } + elseif( $data === false ) { + $data = ''; }