Skip to content

Commit

Permalink
admin api updated
Browse files Browse the repository at this point in the history
  • Loading branch information
rafasashi committed Jul 27, 2023
1 parent e6001d7 commit faf1ba3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
2 changes: 1 addition & 1 deletion includes/class-wordpress-plugin-template-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) );
Expand Down
55 changes: 29 additions & 26 deletions includes/lib/class-wordpress-plugin-template-admin-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}

Expand Down

0 comments on commit faf1ba3

Please sign in to comment.