get(); $settings[ $key ] = $value; return update_option( self::CORE_OPTION, $settings, true ); } /** * Option name holding one module's settings. * * @param string $module_id Module id. * @return string */ public function module_option_name( $module_id ) { return 'pagecore_' . str_replace( '-', '_', $module_id ) . '_settings'; } /** * Read a module setting. * * @param string $module_id Module id. * @param string $key Setting key, or null for the whole array. * @param mixed $default Value returned when the key is absent. * @return mixed */ public function get_module( $module_id, $key = null, $default = null ) { $settings = get_option( $this->module_option_name( $module_id ), array() ); $settings = is_array( $settings ) ? $settings : array(); if ( null === $key ) { return $settings; } return array_key_exists( $key, $settings ) ? $settings[ $key ] : $default; } /** * Write a module setting. * * @param string $module_id Module id. * @param string $key Setting key. * @param mixed $value Value to store. * @return bool */ public function set_module( $module_id, $key, $value ) { $settings = $this->get_module( $module_id ); $settings[ $key ] = $value; return update_option( $this->module_option_name( $module_id ), $settings, true ); } /** * Whether the site owner has asked for all data to go on uninstall. * * Defaults to false, so an accidental delete never takes content with it. * * @return bool */ public function should_remove_all_data() { return (bool) $this->get( 'remove_all_data', false ); } }