Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It is not working for network setting page? #97

Open
faiyazalam opened this issue Feb 5, 2018 · 4 comments
Open

It is not working for network setting page? #97

faiyazalam opened this issue Feb 5, 2018 · 4 comments

Comments

@faiyazalam
Copy link

I created a network setting page but it is not working.
When I submit it is showing 404 page.
To fix this I just remove the action name "options.php" from the form.
Now it is not saving data.

@dmhendricks
Copy link

Yes, I encountered the same issue. The class is hard-coding options.php.

I tried changing line 531 in class.settings-api.php to:

<form method="post" action="<?php echo $_SERVER[ 'REQUEST_URI' ]; ?>">

...which I believe to be correct, but the settings are still not saving. I have to look at it more closely.

@dmhendricks
Copy link

dmhendricks commented Mar 2, 2018

Well, including the above change, I got it to work with a total hack. Given this example...

I added something like this to manually update options when the page is submitted:

function __construct() {
  // ... other code ...

  // Update network options when form submit is detected
  if( isset( $_POST['option_page'] ) && $_POST['option_page'] == 'wedevs_basics' ) $this->save_network_options();
}

private function save_network_options() {
    if( $_POST[ 'wedevs_basics' ] ) {
      $options_array = [];
      foreach( $_POST[ 'wedevs_basics' ] as $option_name => $option_value ) {
        $options_array[ $option_name ] = $option_value;
      }
      update_option( 'wedevs_basics', $options_array );
    }
  }
}

NB! This is not ideal and the code above may contain errors. It is heavily modified from my own code, which has a bunch of extra logic and tabs. I included it in case you are desperate. Caveat emptor.

I'm not sure how to retrieve a value from wp_options from a sub-site since it always tries to get it from the site's own wp_options. Does anyone know? get_option() and the multisite variants didn't work for me. We can't save to wp_sitemeta for get_network_option() or whatever, else the settings page doesn't populate. So, you'll probably have to create another hack...

// Retrieve value from wp_options
private function get_wpsac_network_option( $section_id, $option_name ) {

  global $wpdb;
  $result = $wpdb->get_col( $wpdb->prepare( "SELECT option_value FROM {$wpdb->base_prefix}options WHERE option_name = '%s'", $section_id ) );

  if( !isset( $result[0] ) || !is_serialized( $result[0] ) ) return '';
  $result = unserialize( $result[0] );

  return isset( $result[ $option_name ] ) ? $result[ $option_name ] : '';

}

// Example usage:
echo $this->get_wpsac_network_option( 'wedevs_basics', 'my_field_name' );

Again, not tested for errors... There is a better way, I just don't feel like finding it right now.

Good luck! Haha

@faiyazalam
Copy link
Author

@dmhendricks
To save time, I have not used this plugin for network admin setting page. I am using this only for admin setting page.
Hope the author will fix this soon.

Thanks for your response.

@dmhendricks
Copy link

@faiyazalam - Carbon Fields is about the only custom fields framework I've observed that supports network settings pages. It is available as a plugin and also via Composer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants